@itwin/imodel-components-react 4.0.0-dev.11 → 4.0.0-dev.13

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 (354) hide show
  1. package/lib/cjs/imodel-components-react/UiIModelComponents.d.ts +28 -28
  2. package/lib/cjs/imodel-components-react/UiIModelComponents.d.ts.map +1 -1
  3. package/lib/cjs/imodel-components-react/UiIModelComponents.js +75 -79
  4. package/lib/cjs/imodel-components-react/UiIModelComponents.js.map +1 -1
  5. package/lib/cjs/imodel-components-react/color/AlphaSlider.d.ts +36 -36
  6. package/lib/cjs/imodel-components-react/color/AlphaSlider.js +190 -186
  7. package/lib/cjs/imodel-components-react/color/AlphaSlider.js.map +1 -1
  8. package/lib/cjs/imodel-components-react/color/AlphaSlider.scss +63 -63
  9. package/lib/cjs/imodel-components-react/color/ColorPickerButton.d.ts +37 -37
  10. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js +112 -108
  11. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  12. package/lib/cjs/imodel-components-react/color/ColorPickerButton.scss +90 -90
  13. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts +23 -23
  14. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js +78 -74
  15. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  16. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.d.ts +21 -21
  17. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js +149 -145
  18. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  19. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.scss +93 -93
  20. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts +44 -44
  21. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js +143 -139
  22. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  23. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.scss +62 -62
  24. package/lib/cjs/imodel-components-react/color/HueSlider.d.ts +22 -22
  25. package/lib/cjs/imodel-components-react/color/HueSlider.js +203 -199
  26. package/lib/cjs/imodel-components-react/color/HueSlider.js.map +1 -1
  27. package/lib/cjs/imodel-components-react/color/HueSlider.scss +61 -61
  28. package/lib/cjs/imodel-components-react/color/SaturationPicker.d.ts +20 -20
  29. package/lib/cjs/imodel-components-react/color/SaturationPicker.js +217 -213
  30. package/lib/cjs/imodel-components-react/color/SaturationPicker.js.map +1 -1
  31. package/lib/cjs/imodel-components-react/color/SaturationPicker.scss +35 -35
  32. package/lib/cjs/imodel-components-react/color/Swatch.d.ts +22 -22
  33. package/lib/cjs/imodel-components-react/color/Swatch.js +64 -60
  34. package/lib/cjs/imodel-components-react/color/Swatch.js.map +1 -1
  35. package/lib/cjs/imodel-components-react/color/Swatch.scss +22 -22
  36. package/lib/cjs/imodel-components-react/color/getCSSColorFromDef.d.ts +6 -6
  37. package/lib/cjs/imodel-components-react/color/getCSSColorFromDef.js +23 -23
  38. package/lib/cjs/imodel-components-react/color/getCSSColorFromDef.js.map +1 -1
  39. package/lib/cjs/imodel-components-react/editors/ColorEditor.d.ts +44 -44
  40. package/lib/cjs/imodel-components-react/editors/ColorEditor.js +155 -151
  41. package/lib/cjs/imodel-components-react/editors/ColorEditor.js.map +1 -1
  42. package/lib/cjs/imodel-components-react/editors/ColorEditor.scss +18 -18
  43. package/lib/cjs/imodel-components-react/editors/WeightEditor.d.ts +47 -47
  44. package/lib/cjs/imodel-components-react/editors/WeightEditor.js +164 -160
  45. package/lib/cjs/imodel-components-react/editors/WeightEditor.js.map +1 -1
  46. package/lib/cjs/imodel-components-react/editors/WeightEditor.scss +16 -16
  47. package/lib/cjs/imodel-components-react/inputs/QuantityInput.d.ts +25 -25
  48. package/lib/cjs/imodel-components-react/inputs/QuantityInput.js +100 -96
  49. package/lib/cjs/imodel-components-react/inputs/QuantityInput.js.map +1 -1
  50. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts +44 -44
  51. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  52. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +272 -268
  53. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  54. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.scss +106 -106
  55. package/lib/cjs/imodel-components-react/lineweight/Swatch.d.ts +33 -33
  56. package/lib/cjs/imodel-components-react/lineweight/Swatch.js +89 -85
  57. package/lib/cjs/imodel-components-react/lineweight/Swatch.js.map +1 -1
  58. package/lib/cjs/imodel-components-react/lineweight/Swatch.scss +48 -48
  59. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.d.ts +60 -60
  60. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.js +163 -159
  61. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  62. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.scss +51 -52
  63. package/lib/cjs/imodel-components-react/navigationaids/Cube.d.ts +45 -45
  64. package/lib/cjs/imodel-components-react/navigationaids/Cube.js +131 -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 +175 -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 +650 -638
  70. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  71. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.scss +178 -178
  72. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.d.ts +145 -145
  73. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.js +657 -653
  74. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  75. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.scss +135 -135
  76. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.d.ts +26 -26
  77. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js +103 -99
  78. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
  79. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.scss +59 -63
  80. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.d.ts +17 -17
  81. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js +56 -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 +88 -84
  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 +89 -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 +112 -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 +187 -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.js +149 -145
  100. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  101. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.d.ts +17 -17
  102. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js +63 -59
  103. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  104. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.d.ts +17 -17
  105. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js +51 -47
  106. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  107. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.d.ts +16 -16
  108. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js +58 -54
  109. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  110. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.d.ts +18 -18
  111. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js +52 -48
  112. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  113. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.d.ts +17 -17
  114. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js +54 -50
  115. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  116. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.d.ts +17 -17
  117. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +62 -58
  118. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  119. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.d.ts +17 -17
  120. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js +51 -47
  121. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  122. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts +17 -17
  123. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js +60 -56
  124. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  125. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts +17 -17
  126. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +98 -95
  127. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  128. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.d.ts +23 -23
  129. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js +123 -119
  130. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  131. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.d.ts +52 -52
  132. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.js +143 -143
  133. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  134. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.d.ts +31 -31
  135. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.js +69 -69
  136. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  137. package/lib/cjs/imodel-components-react/timeline/InlineEdit.d.ts +27 -27
  138. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js +85 -81
  139. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  140. package/lib/cjs/imodel-components-react/timeline/InlineEdit.scss +26 -26
  141. package/lib/cjs/imodel-components-react/timeline/PlayerButton.d.ts +33 -33
  142. package/lib/cjs/imodel-components-react/timeline/PlayerButton.js +99 -95
  143. package/lib/cjs/imodel-components-react/timeline/PlayerButton.js.map +1 -1
  144. package/lib/cjs/imodel-components-react/timeline/PlayerButton.scss +28 -28
  145. package/lib/cjs/imodel-components-react/timeline/Scrubber.d.ts +54 -54
  146. package/lib/cjs/imodel-components-react/timeline/Scrubber.js +195 -191
  147. package/lib/cjs/imodel-components-react/timeline/Scrubber.js.map +1 -1
  148. package/lib/cjs/imodel-components-react/timeline/Scrubber.scss +105 -105
  149. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.d.ts +77 -77
  150. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.js +432 -428
  151. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.js.map +1 -1
  152. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.scss +359 -359
  153. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.d.ts +15 -15
  154. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.js +58 -54
  155. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.js.map +1 -1
  156. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.scss +39 -39
  157. package/lib/cjs/imodel-components-react/timeline/Timeline.scss +164 -164
  158. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.d.ts +130 -133
  159. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.d.ts.map +1 -1
  160. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.js +398 -365
  161. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.js.map +1 -1
  162. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.scss +178 -161
  163. package/lib/cjs/imodel-components-react/timeline/interfaces.d.ts +174 -174
  164. package/lib/cjs/imodel-components-react/timeline/interfaces.d.ts.map +1 -1
  165. package/lib/cjs/imodel-components-react/timeline/interfaces.js +45 -45
  166. package/lib/cjs/imodel-components-react/timeline/interfaces.js.map +1 -1
  167. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts +42 -42
  168. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  169. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +276 -274
  170. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  171. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts +106 -106
  172. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js +105 -105
  173. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  174. package/lib/cjs/imodel-components-react.d.ts +82 -82
  175. package/lib/cjs/imodel-components-react.js +105 -101
  176. package/lib/cjs/imodel-components-react.js.map +1 -1
  177. package/lib/esm/imodel-components-react/UiIModelComponents.d.ts +28 -28
  178. package/lib/esm/imodel-components-react/UiIModelComponents.d.ts.map +1 -1
  179. package/lib/esm/imodel-components-react/UiIModelComponents.js +72 -75
  180. package/lib/esm/imodel-components-react/UiIModelComponents.js.map +1 -1
  181. package/lib/esm/imodel-components-react/color/AlphaSlider.d.ts +36 -36
  182. package/lib/esm/imodel-components-react/color/AlphaSlider.js +160 -160
  183. package/lib/esm/imodel-components-react/color/AlphaSlider.js.map +1 -1
  184. package/lib/esm/imodel-components-react/color/AlphaSlider.scss +63 -63
  185. package/lib/esm/imodel-components-react/color/ColorPickerButton.d.ts +37 -37
  186. package/lib/esm/imodel-components-react/color/ColorPickerButton.js +83 -83
  187. package/lib/esm/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  188. package/lib/esm/imodel-components-react/color/ColorPickerButton.scss +90 -90
  189. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts +23 -23
  190. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js +51 -51
  191. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  192. package/lib/esm/imodel-components-react/color/ColorPickerPanel.d.ts +21 -21
  193. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js +122 -122
  194. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  195. package/lib/esm/imodel-components-react/color/ColorPickerPanel.scss +93 -93
  196. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts +44 -44
  197. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js +114 -114
  198. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  199. package/lib/esm/imodel-components-react/color/ColorPickerPopup.scss +62 -62
  200. package/lib/esm/imodel-components-react/color/HueSlider.d.ts +22 -22
  201. package/lib/esm/imodel-components-react/color/HueSlider.js +173 -173
  202. package/lib/esm/imodel-components-react/color/HueSlider.js.map +1 -1
  203. package/lib/esm/imodel-components-react/color/HueSlider.scss +61 -61
  204. package/lib/esm/imodel-components-react/color/SaturationPicker.d.ts +20 -20
  205. package/lib/esm/imodel-components-react/color/SaturationPicker.js +187 -187
  206. package/lib/esm/imodel-components-react/color/SaturationPicker.js.map +1 -1
  207. package/lib/esm/imodel-components-react/color/SaturationPicker.scss +35 -35
  208. package/lib/esm/imodel-components-react/color/Swatch.d.ts +22 -22
  209. package/lib/esm/imodel-components-react/color/Swatch.js +34 -34
  210. package/lib/esm/imodel-components-react/color/Swatch.js.map +1 -1
  211. package/lib/esm/imodel-components-react/color/Swatch.scss +22 -22
  212. package/lib/esm/imodel-components-react/color/getCSSColorFromDef.d.ts +6 -6
  213. package/lib/esm/imodel-components-react/color/getCSSColorFromDef.js +19 -19
  214. package/lib/esm/imodel-components-react/color/getCSSColorFromDef.js.map +1 -1
  215. package/lib/esm/imodel-components-react/editors/ColorEditor.d.ts +44 -44
  216. package/lib/esm/imodel-components-react/editors/ColorEditor.js +124 -124
  217. package/lib/esm/imodel-components-react/editors/ColorEditor.js.map +1 -1
  218. package/lib/esm/imodel-components-react/editors/ColorEditor.scss +18 -18
  219. package/lib/esm/imodel-components-react/editors/WeightEditor.d.ts +47 -47
  220. package/lib/esm/imodel-components-react/editors/WeightEditor.js +133 -133
  221. package/lib/esm/imodel-components-react/editors/WeightEditor.js.map +1 -1
  222. package/lib/esm/imodel-components-react/editors/WeightEditor.scss +16 -16
  223. package/lib/esm/imodel-components-react/inputs/QuantityInput.d.ts +25 -25
  224. package/lib/esm/imodel-components-react/inputs/QuantityInput.js +70 -70
  225. package/lib/esm/imodel-components-react/inputs/QuantityInput.js.map +1 -1
  226. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts +44 -44
  227. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  228. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +243 -243
  229. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  230. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.scss +106 -106
  231. package/lib/esm/imodel-components-react/lineweight/Swatch.d.ts +33 -33
  232. package/lib/esm/imodel-components-react/lineweight/Swatch.js +59 -59
  233. package/lib/esm/imodel-components-react/lineweight/Swatch.js.map +1 -1
  234. package/lib/esm/imodel-components-react/lineweight/Swatch.scss +48 -48
  235. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.d.ts +60 -60
  236. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.js +134 -133
  237. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  238. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.scss +51 -52
  239. package/lib/esm/imodel-components-react/navigationaids/Cube.d.ts +45 -45
  240. package/lib/esm/imodel-components-react/navigationaids/Cube.js +100 -100
  241. package/lib/esm/imodel-components-react/navigationaids/Cube.js.map +1 -1
  242. package/lib/esm/imodel-components-react/navigationaids/Cube.scss +19 -19
  243. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.d.ts +175 -174
  244. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.d.ts.map +1 -1
  245. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js +620 -610
  246. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  247. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.scss +178 -178
  248. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.d.ts +145 -145
  249. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.js +627 -626
  250. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  251. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.scss +135 -135
  252. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.d.ts +26 -26
  253. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js +76 -76
  254. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
  255. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.scss +59 -63
  256. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.d.ts +17 -17
  257. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js +29 -30
  258. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
  259. package/lib/esm/imodel-components-react/quantityformat/FormatSample.d.ts +18 -18
  260. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +61 -61
  261. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  262. package/lib/esm/imodel-components-react/quantityformat/FormatType.d.ts +17 -17
  263. package/lib/esm/imodel-components-react/quantityformat/FormatType.js +62 -63
  264. package/lib/esm/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  265. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.d.ts +17 -17
  266. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +82 -83
  267. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  268. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.d.ts +19 -19
  269. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +106 -110
  270. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  271. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.d.ts +21 -21
  272. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js +157 -158
  273. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  274. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts +22 -22
  275. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js +122 -122
  276. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  277. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.d.ts +17 -17
  278. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js +36 -36
  279. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  280. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.d.ts +17 -17
  281. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js +24 -24
  282. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  283. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.d.ts +16 -16
  284. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js +31 -31
  285. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  286. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.d.ts +18 -18
  287. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js +25 -25
  288. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  289. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.d.ts +17 -17
  290. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js +27 -27
  291. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  292. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.d.ts +17 -17
  293. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +35 -35
  294. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  295. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.d.ts +17 -17
  296. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js +24 -24
  297. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  298. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts +17 -17
  299. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js +33 -33
  300. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  301. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts +17 -17
  302. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +68 -69
  303. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  304. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.d.ts +23 -23
  305. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js +96 -96
  306. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  307. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.d.ts +52 -52
  308. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.js +139 -139
  309. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  310. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.d.ts +31 -31
  311. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.js +65 -65
  312. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  313. package/lib/esm/imodel-components-react/timeline/InlineEdit.d.ts +27 -27
  314. package/lib/esm/imodel-components-react/timeline/InlineEdit.js +55 -55
  315. package/lib/esm/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  316. package/lib/esm/imodel-components-react/timeline/InlineEdit.scss +26 -26
  317. package/lib/esm/imodel-components-react/timeline/PlayerButton.d.ts +33 -33
  318. package/lib/esm/imodel-components-react/timeline/PlayerButton.js +68 -68
  319. package/lib/esm/imodel-components-react/timeline/PlayerButton.js.map +1 -1
  320. package/lib/esm/imodel-components-react/timeline/PlayerButton.scss +28 -28
  321. package/lib/esm/imodel-components-react/timeline/Scrubber.d.ts +54 -54
  322. package/lib/esm/imodel-components-react/timeline/Scrubber.js +164 -164
  323. package/lib/esm/imodel-components-react/timeline/Scrubber.js.map +1 -1
  324. package/lib/esm/imodel-components-react/timeline/Scrubber.scss +105 -105
  325. package/lib/esm/imodel-components-react/timeline/SolarTimeline.d.ts +77 -77
  326. package/lib/esm/imodel-components-react/timeline/SolarTimeline.js +402 -402
  327. package/lib/esm/imodel-components-react/timeline/SolarTimeline.js.map +1 -1
  328. package/lib/esm/imodel-components-react/timeline/SolarTimeline.scss +359 -359
  329. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.d.ts +15 -15
  330. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.js +28 -28
  331. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.js.map +1 -1
  332. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.scss +39 -39
  333. package/lib/esm/imodel-components-react/timeline/Timeline.scss +164 -164
  334. package/lib/esm/imodel-components-react/timeline/TimelineComponent.d.ts +130 -133
  335. package/lib/esm/imodel-components-react/timeline/TimelineComponent.d.ts.map +1 -1
  336. package/lib/esm/imodel-components-react/timeline/TimelineComponent.js +368 -339
  337. package/lib/esm/imodel-components-react/timeline/TimelineComponent.js.map +1 -1
  338. package/lib/esm/imodel-components-react/timeline/TimelineComponent.scss +178 -161
  339. package/lib/esm/imodel-components-react/timeline/interfaces.d.ts +174 -174
  340. package/lib/esm/imodel-components-react/timeline/interfaces.d.ts.map +1 -1
  341. package/lib/esm/imodel-components-react/timeline/interfaces.js +42 -42
  342. package/lib/esm/imodel-components-react/timeline/interfaces.js.map +1 -1
  343. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts +42 -42
  344. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  345. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +249 -251
  346. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  347. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts +106 -106
  348. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js +96 -95
  349. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  350. package/lib/esm/imodel-components-react.d.ts +82 -82
  351. package/lib/esm/imodel-components-react.js +87 -87
  352. package/lib/esm/imodel-components-react.js.map +1 -1
  353. package/lib/public/locales/en/UiIModelComponents.json +139 -139
  354. package/package.json +24 -28
@@ -1,244 +1,244 @@
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 { Icon } 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
- import { SvgCaretDown, SvgCaretDownSmall, SvgCaretUp, SvgCaretUpSmall } from "@itwin/itwinui-icons-react";
17
- /** adjust formatter spec to show only primary unit without a label. */
18
- function adjustFormatterSpec(formatterSpec) {
19
- if (undefined === formatterSpec)
20
- return formatterSpec;
21
- const singleUnitConversion = [];
22
- singleUnitConversion.push(formatterSpec.unitConversions[0]);
23
- const newFormat = formatterSpec.format.clone({
24
- showOnlyPrimaryUnit: true,
25
- traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,
26
- type: FormatType.Decimal,
27
- precision: FormatType.Decimal !== formatterSpec.format.type ? DecimalPrecision.Four : formatterSpec.format.precision,
28
- });
29
- return new FormatterSpec("single-value", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);
30
- }
31
- function convertValueFromDisplayToPersistence(value, unitConversions, unit) {
32
- // istanbul ignore next
33
- if (!unitConversions || 0 === unitConversions.length)
34
- return value;
35
- const unitConversion = unitConversions.find((spec) => spec.name === unit.name);
36
- // istanbul ignore next
37
- if (!unitConversion)
38
- return value;
39
- const convertedValue = (value * unitConversion.conversion.factor) + unitConversion.conversion.offset;
40
- return convertedValue;
41
- }
42
- function getUnitLabel(parserSpec) {
43
- if (undefined === parserSpec)
44
- return "";
45
- const format = parserSpec.format;
46
- // istanbul ignore else
47
- if (!format.units || !format.units[0])
48
- return parserSpec.outUnit.label;
49
- const [unit, label] = format.units[0];
50
- // istanbul ignore next
51
- return label !== null && label !== void 0 ? label : unit.label;
52
- }
53
- const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuantityNumberInput(props, ref) {
54
- const { containerClassName, persistenceValue, min, max, onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;
55
- const rawValueRef = React.useRef(persistenceValue);
56
- const [formatterSpec, setFormatterSpec] = React.useState(() => adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
57
- const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
58
- const formatValue = React.useCallback((value) => {
59
- if (undefined === value)
60
- return "";
61
- // istanbul ignore else
62
- if (formatterSpec) {
63
- return formatterSpec.applyFormatting(value);
64
- }
65
- // istanbul ignore next
66
- return value.toFixed(2);
67
- }, [formatterSpec]);
68
- const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));
69
- const [formattedValue, setFormattedValue] = React.useState(() => lastFormattedValueRef.current);
70
- React.useEffect(() => {
71
- const handleUnitSystemChanged = (() => {
72
- setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
73
- setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
74
- });
75
- IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(handleUnitSystemChanged);
76
- return () => {
77
- IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(handleUnitSystemChanged);
78
- };
79
- }, [quantityType]);
80
- React.useEffect(() => {
81
- const handleUnitSystemChanged = ((args) => {
82
- const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);
83
- // istanbul ignore else
84
- if (args.quantityType === quantityKey) {
85
- setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
86
- setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
87
- }
88
- });
89
- IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(handleUnitSystemChanged);
90
- return () => {
91
- IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(handleUnitSystemChanged);
92
- };
93
- }, [quantityType]);
94
- const unitLabel = getUnitLabel(parserSpec);
95
- // See if new initialValue props have changed since component mounted
96
- React.useEffect(() => {
97
- rawValueRef.current = persistenceValue;
98
- const currentFormattedValue = formatValue(rawValueRef.current);
99
- setFormattedValue(currentFormattedValue);
100
- }, [formatValue, persistenceValue]);
101
- // this is the unprocessed input from user, it is not processed until blur or enter key press
102
- const handleDisplayValueChange = React.useCallback((event) => {
103
- setFormattedValue(event.currentTarget.value);
104
- }, []);
105
- const updateValue = React.useCallback((newValue) => {
106
- let persistedValue = newValue;
107
- // istanbul ignore else
108
- if (parserSpec) {
109
- // convert value from display unit to persistence unit
110
- const [unit] = parserSpec.format.units ? parserSpec.format.units[0] : /* istanbul ignore next */ [parserSpec.outUnit];
111
- persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);
112
- rawValueRef.current = persistedValue;
113
- }
114
- const newFormattedVal = formatValue(persistedValue);
115
- onChange && onChange(persistedValue);
116
- setFormattedValue(newFormattedVal);
117
- }, [formatValue, onChange, parserSpec]);
118
- /**
119
- * Used internally to parse the argument x to it's numeric representation.
120
- * If the argument cannot be converted to finite number returns 0; If a
121
- * "precision" prop is specified uses it round the number with that
122
- * precision (no fixed precision here because the return value is float, not
123
- * string).
124
- */
125
- const parseInternal = React.useCallback((x) => {
126
- if (!x)
127
- return 0;
128
- let n = parseFloat(x);
129
- // istanbul ignore next
130
- if (isNaN(n) || !isFinite(n)) {
131
- n = 0;
132
- }
133
- const localPrecision = 6; // TODO get a reasonable value from format
134
- const q = Math.pow(10, localPrecision);
135
- const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
136
- const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
137
- n = Math.min(Math.max(n, localMin), localMax);
138
- n = Math.round(n * q) / q;
139
- return n;
140
- }, [min, max]);
141
- const updateValueFromString = React.useCallback((strValue) => {
142
- // istanbul ignore else
143
- if (parserSpec) {
144
- const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);
145
- // at this point we should have a string value in persistence units without a label
146
- if (Parser.isParsedQuantity(parseResult)) {
147
- const persistedValue = parseResult.value; // in persistence units
148
- // set strValue and let it go through parseInternal which will ensure min/max limits are observed
149
- strValue = formatValue(persistedValue);
150
- }
151
- else {
152
- // istanbul ignore else
153
- if (rawValueRef.current) { // restore last known good value
154
- const lastKnownFormattedVal = formatValue(rawValueRef.current);
155
- setFormattedValue(lastKnownFormattedVal);
156
- return;
157
- }
158
- }
159
- }
160
- const newValue = parseInternal(strValue);
161
- // istanbul ignore else
162
- if (undefined !== newValue)
163
- updateValue(newValue);
164
- }, [formatValue, parseInternal, parserSpec, updateValue]);
165
- const handleBlur = React.useCallback((event) => {
166
- const newVal = parseInternal(event.target.value);
167
- onBlur && onBlur(event);
168
- updateValue(newVal);
169
- }, [parseInternal, updateValue, onBlur]);
170
- const getIncrementValue = React.useCallback((increment) => {
171
- if (typeof step === "function") {
172
- const stepVal = step(increment ? "up" : "down");
173
- return stepVal ? stepVal : 1;
174
- }
175
- return !step ? 1 : step;
176
- }, [step]);
177
- /**
178
- * The internal method that actually sets the new value on the input
179
- */
180
- const applyStep = React.useCallback((increment) => {
181
- const incrementValue = getIncrementValue(increment);
182
- let num = parseInternal(formattedValue) + (increment ? incrementValue : -incrementValue);
183
- if (snap) {
184
- num = Math.round(num / incrementValue) * incrementValue;
185
- }
186
- const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
187
- const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
188
- num = Math.min(Math.max(num, localMin), localMax);
189
- updateValue(num);
190
- }, [formattedValue, getIncrementValue, max, min, parseInternal, snap, updateValue]);
191
- const handleKeyDown = React.useCallback((event) => {
192
- // istanbul ignore else
193
- if (event.key === SpecialKey.Enter) {
194
- updateValueFromString(event.currentTarget.value);
195
- event.preventDefault();
196
- }
197
- else if (event.key === SpecialKey.Escape) {
198
- setFormattedValue(formatValue(rawValueRef.current));
199
- event.preventDefault();
200
- }
201
- else if (event.key === SpecialKey.ArrowDown) {
202
- applyStep(false);
203
- event.preventDefault();
204
- }
205
- else if (event.key === SpecialKey.ArrowUp) {
206
- applyStep(true);
207
- event.preventDefault();
208
- }
209
- onKeyDown && onKeyDown(event);
210
- }, [onKeyDown, updateValueFromString, formatValue, applyStep]);
211
- const handleDownClick = React.useCallback((event) => {
212
- applyStep(false);
213
- event.preventDefault();
214
- }, [applyStep]);
215
- const handleUpClick = React.useCallback((event) => {
216
- applyStep(true);
217
- event.preventDefault();
218
- }, [applyStep]);
219
- // istanbul ignore next
220
- const handleFocus = React.useCallback((event) => {
221
- event.currentTarget.select();
222
- }, []);
223
- const isDisabled = !!otherProps.disabled;
224
- const containerClasses = classnames("component-quantity-number-input-container", containerClassName, showTouchButtons && "component-number-buttons-for-touch", isDisabled && "component-quantity-number-input-disabled");
225
- const caretUp = showTouchButtons ? React.createElement(SvgCaretUp, null) : React.createElement(SvgCaretUpSmall, null);
226
- const caretDown = showTouchButtons ? React.createElement(SvgCaretDown, null) : React.createElement(SvgCaretDownSmall, null);
227
- return (React.createElement("div", { className: containerClasses },
228
- React.createElement("div", { className: "component-quantity-number-input-value-and-buttons-container" },
229
- React.createElement(Input, { ref: ref, value: formattedValue, onChange: handleDisplayValueChange, onKeyDown: handleKeyDown, onBlur: handleBlur, onFocus: handleFocus, size: "small", ...otherProps }),
230
- React.createElement("div", { className: classnames("component-quantity-number-input-buttons-container", showTouchButtons && "component-number-buttons-for-touch") },
231
- React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-up", tabIndex: -1, onClick: handleUpClick },
232
- React.createElement(Icon, { iconSpec: caretUp })),
233
- React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-down", tabIndex: -1, onClick: handleDownClick },
234
- React.createElement(Icon, { iconSpec: caretDown })))),
235
- React.createElement("span", { className: "component-quantity-number-input-suffix" }, unitLabel)));
236
- });
237
- /** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's
238
- * "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).
239
- * The control also display buttons to increment and decrement the "displayed" value. The value reported by via the onChange function is in "persistence"
240
- * units that can be stored in the iModel.
241
- * @beta
242
- */
243
- 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 { Icon } 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
+ import { SvgCaretDown, SvgCaretDownSmall, SvgCaretUp, SvgCaretUpSmall } from "@itwin/itwinui-icons-react";
17
+ /** adjust formatter spec to show only primary unit without a label. */
18
+ function adjustFormatterSpec(formatterSpec) {
19
+ if (undefined === formatterSpec)
20
+ return formatterSpec;
21
+ const singleUnitConversion = [];
22
+ singleUnitConversion.push(formatterSpec.unitConversions[0]);
23
+ const newFormat = formatterSpec.format.clone({
24
+ showOnlyPrimaryUnit: true,
25
+ traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,
26
+ type: FormatType.Decimal,
27
+ precision: FormatType.Decimal !== formatterSpec.format.type ? DecimalPrecision.Four : formatterSpec.format.precision,
28
+ });
29
+ return new FormatterSpec("single-value", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);
30
+ }
31
+ function convertValueFromDisplayToPersistence(value, unitConversions, unit) {
32
+ // istanbul ignore next
33
+ if (!unitConversions || 0 === unitConversions.length)
34
+ return value;
35
+ const unitConversion = unitConversions.find((spec) => spec.name === unit.name);
36
+ // istanbul ignore next
37
+ if (!unitConversion)
38
+ return value;
39
+ const convertedValue = (value * unitConversion.conversion.factor) + unitConversion.conversion.offset;
40
+ return convertedValue;
41
+ }
42
+ function getUnitLabel(parserSpec) {
43
+ if (undefined === parserSpec)
44
+ return "";
45
+ const format = parserSpec.format;
46
+ // istanbul ignore else
47
+ if (!format.units || !format.units[0])
48
+ return parserSpec.outUnit.label;
49
+ const [unit, label] = format.units[0];
50
+ // istanbul ignore next
51
+ return label ?? unit.label;
52
+ }
53
+ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuantityNumberInput(props, ref) {
54
+ const { containerClassName, persistenceValue, min, max, onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;
55
+ const rawValueRef = React.useRef(persistenceValue);
56
+ const [formatterSpec, setFormatterSpec] = React.useState(() => adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
57
+ const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
58
+ const formatValue = React.useCallback((value) => {
59
+ if (undefined === value)
60
+ return "";
61
+ // istanbul ignore else
62
+ if (formatterSpec) {
63
+ return formatterSpec.applyFormatting(value);
64
+ }
65
+ // istanbul ignore next
66
+ return value.toFixed(2);
67
+ }, [formatterSpec]);
68
+ const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));
69
+ const [formattedValue, setFormattedValue] = React.useState(() => lastFormattedValueRef.current);
70
+ React.useEffect(() => {
71
+ const handleUnitSystemChanged = (() => {
72
+ setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
73
+ setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
74
+ });
75
+ IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(handleUnitSystemChanged);
76
+ return () => {
77
+ IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(handleUnitSystemChanged);
78
+ };
79
+ }, [quantityType]);
80
+ React.useEffect(() => {
81
+ const handleUnitSystemChanged = ((args) => {
82
+ const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);
83
+ // istanbul ignore else
84
+ if (args.quantityType === quantityKey) {
85
+ setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
86
+ setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
87
+ }
88
+ });
89
+ IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(handleUnitSystemChanged);
90
+ return () => {
91
+ IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(handleUnitSystemChanged);
92
+ };
93
+ }, [quantityType]);
94
+ const unitLabel = getUnitLabel(parserSpec);
95
+ // See if new initialValue props have changed since component mounted
96
+ React.useEffect(() => {
97
+ rawValueRef.current = persistenceValue;
98
+ const currentFormattedValue = formatValue(rawValueRef.current);
99
+ setFormattedValue(currentFormattedValue);
100
+ }, [formatValue, persistenceValue]);
101
+ // this is the unprocessed input from user, it is not processed until blur or enter key press
102
+ const handleDisplayValueChange = React.useCallback((event) => {
103
+ setFormattedValue(event.currentTarget.value);
104
+ }, []);
105
+ const updateValue = React.useCallback((newValue) => {
106
+ let persistedValue = newValue;
107
+ // istanbul ignore else
108
+ if (parserSpec) {
109
+ // convert value from display unit to persistence unit
110
+ const [unit] = parserSpec.format.units ? parserSpec.format.units[0] : /* istanbul ignore next */ [parserSpec.outUnit];
111
+ persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);
112
+ rawValueRef.current = persistedValue;
113
+ }
114
+ const newFormattedVal = formatValue(persistedValue);
115
+ onChange && onChange(persistedValue);
116
+ setFormattedValue(newFormattedVal);
117
+ }, [formatValue, onChange, parserSpec]);
118
+ /**
119
+ * Used internally to parse the argument x to it's numeric representation.
120
+ * If the argument cannot be converted to finite number returns 0; If a
121
+ * "precision" prop is specified uses it round the number with that
122
+ * precision (no fixed precision here because the return value is float, not
123
+ * string).
124
+ */
125
+ const parseInternal = React.useCallback((x) => {
126
+ if (!x)
127
+ return 0;
128
+ let n = parseFloat(x);
129
+ // istanbul ignore next
130
+ if (isNaN(n) || !isFinite(n)) {
131
+ n = 0;
132
+ }
133
+ const localPrecision = 6; // TODO get a reasonable value from format
134
+ const q = Math.pow(10, localPrecision);
135
+ const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
136
+ const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
137
+ n = Math.min(Math.max(n, localMin), localMax);
138
+ n = Math.round(n * q) / q;
139
+ return n;
140
+ }, [min, max]);
141
+ const updateValueFromString = React.useCallback((strValue) => {
142
+ // istanbul ignore else
143
+ if (parserSpec) {
144
+ const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);
145
+ // at this point we should have a string value in persistence units without a label
146
+ if (Parser.isParsedQuantity(parseResult)) {
147
+ const persistedValue = parseResult.value; // in persistence units
148
+ // set strValue and let it go through parseInternal which will ensure min/max limits are observed
149
+ strValue = formatValue(persistedValue);
150
+ }
151
+ else {
152
+ // istanbul ignore else
153
+ if (rawValueRef.current) { // restore last known good value
154
+ const lastKnownFormattedVal = formatValue(rawValueRef.current);
155
+ setFormattedValue(lastKnownFormattedVal);
156
+ return;
157
+ }
158
+ }
159
+ }
160
+ const newValue = parseInternal(strValue);
161
+ // istanbul ignore else
162
+ if (undefined !== newValue)
163
+ updateValue(newValue);
164
+ }, [formatValue, parseInternal, parserSpec, updateValue]);
165
+ const handleBlur = React.useCallback((event) => {
166
+ const newVal = parseInternal(event.target.value);
167
+ onBlur && onBlur(event);
168
+ updateValue(newVal);
169
+ }, [parseInternal, updateValue, onBlur]);
170
+ const getIncrementValue = React.useCallback((increment) => {
171
+ if (typeof step === "function") {
172
+ const stepVal = step(increment ? "up" : "down");
173
+ return stepVal ? stepVal : 1;
174
+ }
175
+ return !step ? 1 : step;
176
+ }, [step]);
177
+ /**
178
+ * The internal method that actually sets the new value on the input
179
+ */
180
+ const applyStep = React.useCallback((increment) => {
181
+ const incrementValue = getIncrementValue(increment);
182
+ let num = parseInternal(formattedValue) + (increment ? incrementValue : -incrementValue);
183
+ if (snap) {
184
+ num = Math.round(num / incrementValue) * incrementValue;
185
+ }
186
+ const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
187
+ const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
188
+ num = Math.min(Math.max(num, localMin), localMax);
189
+ updateValue(num);
190
+ }, [formattedValue, getIncrementValue, max, min, parseInternal, snap, updateValue]);
191
+ const handleKeyDown = React.useCallback((event) => {
192
+ // istanbul ignore else
193
+ if (event.key === SpecialKey.Enter) {
194
+ updateValueFromString(event.currentTarget.value);
195
+ event.preventDefault();
196
+ }
197
+ else if (event.key === SpecialKey.Escape) {
198
+ setFormattedValue(formatValue(rawValueRef.current));
199
+ event.preventDefault();
200
+ }
201
+ else if (event.key === SpecialKey.ArrowDown) {
202
+ applyStep(false);
203
+ event.preventDefault();
204
+ }
205
+ else if (event.key === SpecialKey.ArrowUp) {
206
+ applyStep(true);
207
+ event.preventDefault();
208
+ }
209
+ onKeyDown && onKeyDown(event);
210
+ }, [onKeyDown, updateValueFromString, formatValue, applyStep]);
211
+ const handleDownClick = React.useCallback((event) => {
212
+ applyStep(false);
213
+ event.preventDefault();
214
+ }, [applyStep]);
215
+ const handleUpClick = React.useCallback((event) => {
216
+ applyStep(true);
217
+ event.preventDefault();
218
+ }, [applyStep]);
219
+ // istanbul ignore next
220
+ const handleFocus = React.useCallback((event) => {
221
+ event.currentTarget.select();
222
+ }, []);
223
+ const isDisabled = !!otherProps.disabled;
224
+ const containerClasses = classnames("component-quantity-number-input-container", containerClassName, showTouchButtons && "component-number-buttons-for-touch", isDisabled && "component-quantity-number-input-disabled");
225
+ const caretUp = showTouchButtons ? React.createElement(SvgCaretUp, null) : React.createElement(SvgCaretUpSmall, null);
226
+ const caretDown = showTouchButtons ? React.createElement(SvgCaretDown, null) : React.createElement(SvgCaretDownSmall, null);
227
+ return (React.createElement("div", { className: containerClasses },
228
+ React.createElement("div", { className: "component-quantity-number-input-value-and-buttons-container" },
229
+ React.createElement(Input, { ref: ref, value: formattedValue, onChange: handleDisplayValueChange, onKeyDown: handleKeyDown, onBlur: handleBlur, onFocus: handleFocus, size: "small", ...otherProps }),
230
+ React.createElement("div", { className: classnames("component-quantity-number-input-buttons-container", showTouchButtons && "component-number-buttons-for-touch") },
231
+ React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-up", tabIndex: -1, onClick: handleUpClick },
232
+ React.createElement(Icon, { iconSpec: caretUp })),
233
+ React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-down", tabIndex: -1, onClick: handleDownClick },
234
+ React.createElement(Icon, { iconSpec: caretDown })))),
235
+ React.createElement("span", { className: "component-quantity-number-input-suffix" }, unitLabel)));
236
+ });
237
+ /** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's
238
+ * "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).
239
+ * The control also display buttons to increment and decrement the "displayed" value. The value reported by via the onChange function is in "persistence"
240
+ * units that can be stored in the iModel.
241
+ * @beta
242
+ */
243
+ export const QuantityNumberInput = ForwardRefQuantityNumberInput;
244
244
  //# 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,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,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;AACzD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAkC1G,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,CA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;;;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 { Icon } 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\nimport { SvgCaretDown, SvgCaretDownSmall, SvgCaretUp, SvgCaretUpSmall } from \"@itwin/itwinui-icons-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\r\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\r\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\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 <Icon iconSpec={caretUp} />\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 <Icon iconSpec={caretDown} />\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"]}
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,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAA+C,MAAM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G,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,IAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;gBAEN,6BAAK,SAAS,EAAC,oFAAoF,EAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe;oBACxI,oBAAC,IAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,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 { Icon } 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\";\nimport { SvgCaretDown, SvgCaretDownSmall, SvgCaretUp, SvgCaretUpSmall } from \"@itwin/itwinui-icons-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\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 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 <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 className=\"component-quantity-number-input-button component-quantity-number-input-button-down\" tabIndex={-1} onClick={handleDownClick}>\n <Icon iconSpec={caretDown} />\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"]}