@itwin/imodel-components-react 3.0.0-dev.99 → 3.1.0-dev.1

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 (117) hide show
  1. package/LICENSE.md +1 -1
  2. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts +3 -2
  3. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts.map +1 -1
  4. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js +17 -4
  5. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  6. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.d.ts +2 -2
  7. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.d.ts.map +1 -1
  8. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js +1 -1
  9. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  10. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts +4 -3
  11. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts.map +1 -1
  12. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js +41 -22
  13. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  14. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.scss +12 -2
  15. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  16. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +3 -2
  17. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  18. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.scss +19 -1
  19. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js +1 -1
  20. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  21. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js +1 -1
  22. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  23. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js +1 -1
  24. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  25. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js +1 -1
  26. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  27. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  28. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js +1 -1
  29. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  30. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js +1 -1
  31. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  32. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js +1 -1
  33. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  34. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js +1 -1
  35. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  36. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js +1 -1
  37. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  38. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js +1 -1
  39. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  40. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +1 -1
  41. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  42. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js +1 -1
  43. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  44. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js +1 -1
  45. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  46. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js +2 -2
  47. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  48. package/lib/cjs/imodel-components-react/timeline/InlineEdit.d.ts.map +1 -1
  49. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js +1 -1
  50. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  51. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts +1 -25
  52. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  53. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +199 -188
  54. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  55. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts +1 -1
  56. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts.map +1 -1
  57. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js +7 -7
  58. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  59. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts +3 -2
  60. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts.map +1 -1
  61. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js +17 -4
  62. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  63. package/lib/esm/imodel-components-react/color/ColorPickerPanel.d.ts +2 -2
  64. package/lib/esm/imodel-components-react/color/ColorPickerPanel.d.ts.map +1 -1
  65. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js +1 -1
  66. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  67. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts +4 -3
  68. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts.map +1 -1
  69. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js +41 -22
  70. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  71. package/lib/esm/imodel-components-react/color/ColorPickerPopup.scss +12 -2
  72. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  73. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +3 -2
  74. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  75. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.scss +19 -1
  76. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +1 -1
  77. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  78. package/lib/esm/imodel-components-react/quantityformat/FormatType.js +1 -1
  79. package/lib/esm/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  80. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +1 -1
  81. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  82. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +1 -1
  83. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  84. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  85. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js +1 -1
  86. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  87. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js +1 -1
  88. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  89. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js +1 -1
  90. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  91. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js +1 -1
  92. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  93. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js +1 -1
  94. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  95. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js +1 -1
  96. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  97. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +1 -1
  98. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  99. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js +1 -1
  100. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  101. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js +1 -1
  102. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  103. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js +2 -2
  104. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  105. package/lib/esm/imodel-components-react/timeline/InlineEdit.d.ts.map +1 -1
  106. package/lib/esm/imodel-components-react/timeline/InlineEdit.js +1 -1
  107. package/lib/esm/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  108. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts +1 -25
  109. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  110. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +199 -188
  111. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  112. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts +1 -1
  113. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts.map +1 -1
  114. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js +1 -1
  115. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  116. package/lib/public/locales/en/UiIModelComponents.json +3 -1
  117. package/package.json +29 -31
@@ -1 +1 @@
1
- {"version":3,"file":"ThousandsSelector.js","sourceRoot":"","sources":["../../../../../src/imodel-components-react/quantityformat/misc/ThousandsSelector.tsx"],"names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IAAC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,KAAM,UAAU,GAAI,CACtH,CAAC;AACJ,CAAC;AAxBD,8CAwBC","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 QuantityFormat\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { UiIModelComponents } from \"../../UiIModelComponents\";\r\nimport { Select, SelectOption } from \"@itwin/itwinui-react\";\r\n\r\n/** Properties of [[ThousandsSelector]] component.\r\n * @internal\r\n */\r\nexport interface ThousandsSelectorProps extends CommonProps {\r\n separator: string;\r\n disabled: boolean;\r\n onChange: (value: string) => void;\r\n}\r\n\r\n/** Component use to set Quantity Format thousand group separator.\r\n * @internal\r\n */\r\nexport function ThousandsSelector(props: ThousandsSelectorProps) {\r\n const { separator, disabled, onChange, ...otherProps } = props;\r\n const uomDefaultEntries = React.useRef<SelectOption<string>[]>([\r\n { value: \",\", label: UiIModelComponents.translate(\"QuantityFormat.thousand_separator.comma\") },\r\n { value: \".\", label: UiIModelComponents.translate(\"QuantityFormat.thousand_separator.point\") },\r\n ]);\r\n\r\n const handleOnChange = React.useCallback((newValue: string) => {\r\n onChange && onChange(newValue);\r\n }, [onChange]);\r\n\r\n const separatorOptions = React.useMemo(() => {\r\n const completeListOfEntries: SelectOption<string>[] = [];\r\n // istanbul ignore next (only used if format already has a character that does not match standard options)\r\n if (undefined === uomDefaultEntries.current.find((option) => option.value === separator)) {\r\n completeListOfEntries.push({ value: separator, label: separator });\r\n }\r\n completeListOfEntries.push(...uomDefaultEntries.current);\r\n return completeListOfEntries;\r\n }, [separator]);\r\n\r\n return (\r\n <Select options={separatorOptions} disabled={disabled} value={separator} onChange={handleOnChange} {...otherProps} />\r\n );\r\n}\r\n"]}
1
+ {"version":3,"file":"ThousandsSelector.js","sourceRoot":"","sources":["../../../../../src/imodel-components-react/quantityformat/misc/ThousandsSelector.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAE/B,iEAA8D;AAC9D,wDAA4D;AAW5D;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAA6B;IAC7D,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC;IAC/D,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAyB;QAC7D,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,uCAAkB,CAAC,SAAS,CAAC,yCAAyC,CAAC,EAAE;QAC9F,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,uCAAkB,CAAC,SAAS,CAAC,yCAAyC,CAAC,EAAE;KAC/F,CAAC,CAAC;IAEH,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,QAAgB,EAAE,EAAE;QAC5D,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC1C,MAAM,qBAAqB,GAA2B,EAAE,CAAC;QACzD,0GAA0G;QAC1G,IAAI,SAAS,KAAK,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE;YACxF,qBAAqB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;SACpE;QACD,qBAAqB,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACzD,OAAO,qBAAqB,CAAC;IAC/B,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CACL,oBAAC,sBAAM,IAAC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAC,OAAO,KAAK,UAAU,GAAI,CACnI,CAAC;AACJ,CAAC;AAxBD,8CAwBC","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 QuantityFormat\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { UiIModelComponents } from \"../../UiIModelComponents\";\r\nimport { Select, SelectOption } from \"@itwin/itwinui-react\";\r\n\r\n/** Properties of [[ThousandsSelector]] component.\r\n * @internal\r\n */\r\nexport interface ThousandsSelectorProps extends CommonProps {\r\n separator: string;\r\n disabled: boolean;\r\n onChange: (value: string) => void;\r\n}\r\n\r\n/** Component use to set Quantity Format thousand group separator.\r\n * @internal\r\n */\r\nexport function ThousandsSelector(props: ThousandsSelectorProps) {\r\n const { separator, disabled, onChange, ...otherProps } = props;\r\n const uomDefaultEntries = React.useRef<SelectOption<string>[]>([\r\n { value: \",\", label: UiIModelComponents.translate(\"QuantityFormat.thousand_separator.comma\") },\r\n { value: \".\", label: UiIModelComponents.translate(\"QuantityFormat.thousand_separator.point\") },\r\n ]);\r\n\r\n const handleOnChange = React.useCallback((newValue: string) => {\r\n onChange && onChange(newValue);\r\n }, [onChange]);\r\n\r\n const separatorOptions = React.useMemo(() => {\r\n const completeListOfEntries: SelectOption<string>[] = [];\r\n // istanbul ignore next (only used if format already has a character that does not match standard options)\r\n if (undefined === uomDefaultEntries.current.find((option) => option.value === separator)) {\r\n completeListOfEntries.push({ value: separator, label: separator });\r\n }\r\n completeListOfEntries.push(...uomDefaultEntries.current);\r\n return completeListOfEntries;\r\n }, [separator]);\r\n\r\n return (\r\n <Select options={separatorOptions} disabled={disabled} value={separator} onChange={handleOnChange} size=\"small\" {...otherProps} />\r\n );\r\n}\r\n"]}
@@ -113,8 +113,8 @@ function UnitDescr(props) {
113
113
  onLabelChange && onLabelChange(e.target.value, index);
114
114
  }, [index, onLabelChange]);
115
115
  return (React.createElement(React.Fragment, null,
116
- React.createElement(itwinui_react_1.Select, { options: unitOptions, "data-testid": `unit-${currentUnit.name}`, value: `${currentUnit.name}:${currentUnit.label}`, onChange: handleOnUnitChange, disabled: readonly }),
117
- React.createElement(itwinui_react_1.Input, { "data-testid": `unit-label-${currentUnit.name}`, value: label, onChange: handleOnLabelChange })));
116
+ React.createElement(itwinui_react_1.Select, { options: unitOptions, "data-testid": `unit-${currentUnit.name}`, value: `${currentUnit.name}:${currentUnit.label}`, onChange: handleOnUnitChange, disabled: readonly, size: "small" }),
117
+ React.createElement(itwinui_react_1.Input, { "data-testid": `unit-label-${currentUnit.name}`, value: label, onChange: handleOnLabelChange, size: "small" })));
118
118
  }
119
119
  exports.UnitDescr = UnitDescr;
120
120
  //# sourceMappingURL=UnitDescr.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnitDescr.js","sourceRoot":"","sources":["../../../../../src/imodel-components-react/quantityformat/misc/UnitDescr.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAG/B,wDAAmE;AAgBnE,KAAK,UAAU,qBAAqB,CAAC,aAA0B,EAAE,MAAiB,EAAE,aAA4B;IAC9G,MAAM,qBAAqB,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7D,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,IAA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,uBAAuB;gBACvB,IAAI,SAAS,CAAC,OAAO,EAAE;oBACrB,cAAc,CAAC,OAAO,CAAC,CAAC;oBACxB,cAAc,CAAC,gBAAgB,CAAC,CAAC;iBAClC;aACF;QACH,CAAC;QACD,4BAA4B,EAAE,CAAC,CAAC,8DAA8D;IAChG,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;IAExD,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,QAAgB,EAAE,EAAE;QAChE,YAAY,IAAI,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAE1B,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAsC,EAAE,EAAE;QACvF,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,aAAa,IAAI,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;IAE3B,OAAO,CACL;QACE,oBAAC,sBAAM,IAAC,OAAO,EAAE,WAAW,iBAAe,QAAQ,WAAW,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,KAAK,EAAE,EACtH,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,GAAI;QACtD,oBAAC,qBAAK,mBAAc,cAAc,WAAW,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,mBAAmB,GAAI,CACpG,CACJ,CAAC;AACJ,CAAC;AArED,8BAqEC","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 QuantityFormat\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { UnitProps, UnitsProvider } from \"@itwin/core-quantity\";\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { Input, Select, SelectOption } from \"@itwin/itwinui-react\";\r\n\r\n/** Properties of [[UnitDescr]] component.\r\n * @internal\r\n */\r\nexport interface UnitDescrProps extends CommonProps {\r\n name: string;\r\n parentUnitName?: string;\r\n label: string;\r\n index: number;\r\n unitsProvider: UnitsProvider;\r\n readonly?: boolean;\r\n onUnitChange: (value: string, index: number) => void;\r\n onLabelChange: (value: string, index: number) => void;\r\n}\r\n\r\nasync function getUnitConversionData(possibleUnits: UnitProps[], toUnit: UnitProps, unitsProvider: UnitsProvider) {\r\n const unitConversionEntries = possibleUnits.map(async (unit) => {\r\n const conversion = await unitsProvider.getConversion(unit, toUnit);\r\n return { conversion, unitProps: unit };\r\n });\r\n return unitConversionEntries;\r\n}\r\n\r\nasync function getPossibleUnits(parentUnit: UnitProps, unitsProvider: UnitsProvider, ensureCompatibleComposite: boolean) {\r\n const phenomenon = parentUnit.phenomenon;\r\n const possibleUnits = await unitsProvider.getUnitsByFamily(phenomenon);\r\n if (!ensureCompatibleComposite)\r\n return possibleUnits;\r\n\r\n const conversionPromises = await getUnitConversionData(possibleUnits, parentUnit, unitsProvider);\r\n const conversionEntries = await Promise.all(conversionPromises);\r\n // sort the entries so the best potential sub unit will be the first one in the array\r\n return conversionEntries.filter((entry) => ((entry.unitProps.system === parentUnit.system) && (entry.conversion.factor < 1)))\r\n .sort((a, b) => b.conversion.factor - a.conversion.factor)\r\n .map((value) => value.unitProps);\r\n}\r\n\r\nfunction getUnitName(fullUnitName: string) {\r\n const nameParts = fullUnitName.split(/[.:]/);\r\n // istanbul ignore else\r\n if (nameParts.length > 0)\r\n return nameParts[nameParts.length - 1];\r\n // istanbul ignore next\r\n throw Error(\"Bad unit name encountered\");\r\n}\r\n\r\n/** Component use to display dropdown list of possible units.\r\n * @internal\r\n */\r\nexport function UnitDescr(props: UnitDescrProps) {\r\n const { name, label, parentUnitName, index, onUnitChange, onLabelChange, readonly, unitsProvider } = props;\r\n const [unitOptions, setUnitOptions] = React.useState<SelectOption<string>[]>([{ value: name, label: getUnitName(name) }]);\r\n const [currentUnit, setCurrentUnit] = React.useState({ name, label });\r\n const isMounted = React.useRef(false);\r\n\r\n React.useEffect(() => {\r\n isMounted.current = true;\r\n return () => {\r\n isMounted.current = false;\r\n };\r\n });\r\n\r\n React.useEffect(() => {\r\n async function fetchAllowableUnitSelections() {\r\n const currentUnitProps = await unitsProvider.findUnitByName(name);\r\n const parentUnit = await unitsProvider.findUnitByName(parentUnitName ? parentUnitName : name);\r\n // istanbul ignore else\r\n if (parentUnit && currentUnitProps) {\r\n let potentialSubUnit: UnitProps | undefined;\r\n const potentialUnits = await getPossibleUnits(parentUnit, unitsProvider, index !== 0);\r\n // istanbul ignore else\r\n if (index < 3) {\r\n const potentialSubUnits = await getPossibleUnits(currentUnitProps, unitsProvider, true);\r\n if (potentialSubUnits.length)\r\n potentialSubUnit = potentialSubUnits[0];\r\n }\r\n\r\n const options = (potentialUnits.length > 0) ?\r\n potentialUnits.map((unitValue) => {\r\n return { value: `${unitValue.name}:${unitValue.label}`, label: getUnitName(unitValue.name) };\r\n }).sort((a, b) => a.label.localeCompare(b.label))\r\n : /* istanbul ignore next */\r\n [{ value: `${currentUnitProps.name}:${currentUnitProps.label}`, label: getUnitName(name) }];\r\n\r\n if (potentialSubUnit) {\r\n // construct an entry that will provide the name and label of the unit to add\r\n options.push({ value: `ADDSUBUNIT:${potentialSubUnit.name}:${potentialSubUnit.label}`, label: \"Add sub-unit\" }); // NEEDSWORK - i18n\r\n }\r\n\r\n if (index !== 0)\r\n options.push({ value: \"REMOVEUNIT\", label: \"Remove\" }); // NEEDSWORK - i18n\r\n\r\n // istanbul ignore else\r\n if (isMounted.current) {\r\n setUnitOptions(options);\r\n setCurrentUnit(currentUnitProps);\r\n }\r\n }\r\n }\r\n fetchAllowableUnitSelections(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }, [index, label, name, parentUnitName, unitsProvider]);\r\n\r\n const handleOnUnitChange = React.useCallback((newValue: string) => {\r\n onUnitChange && onUnitChange(newValue, index);\r\n }, [index, onUnitChange]);\r\n\r\n const handleOnLabelChange = React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => {\r\n e.preventDefault();\r\n onLabelChange && onLabelChange(e.target.value, index);\r\n }, [index, onLabelChange]);\r\n\r\n return (\r\n <>\r\n <Select options={unitOptions} data-testid={`unit-${currentUnit.name}`} value={`${currentUnit.name}:${currentUnit.label}`}\r\n onChange={handleOnUnitChange} disabled={readonly} />\r\n <Input data-testid={`unit-label-${currentUnit.name}`} value={label} onChange={handleOnLabelChange} />\r\n </>\r\n );\r\n}\r\n"]}
1
+ {"version":3,"file":"UnitDescr.js","sourceRoot":"","sources":["../../../../../src/imodel-components-react/quantityformat/misc/UnitDescr.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAG/B,wDAAmE;AAgBnE,KAAK,UAAU,qBAAqB,CAAC,aAA0B,EAAE,MAAiB,EAAE,aAA4B;IAC9G,MAAM,qBAAqB,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7D,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,UAAqB,EAAE,aAA4B,EAAE,yBAAkC;IACrH,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;IACzC,MAAM,aAAa,GAA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ExD,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,QAAgB,EAAE,EAAE;QAChE,YAAY,IAAI,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAE1B,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAsC,EAAE,EAAE;QACvF,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,aAAa,IAAI,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;IAE3B,OAAO,CACL;QACE,oBAAC,sBAAM,IAAC,OAAO,EAAE,WAAW,iBAAe,QAAQ,WAAW,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,KAAK,EAAE,EACtH,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAC,OAAO,GAAG;QACnE,oBAAC,qBAAK,mBAAc,cAAc,WAAW,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,IAAI,EAAC,OAAO,GAAG,CACjH,CACJ,CAAC;AACJ,CAAC;AArED,8BAqEC","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 QuantityFormat\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { UnitProps, UnitsProvider } from \"@itwin/core-quantity\";\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { Input, Select, SelectOption } from \"@itwin/itwinui-react\";\r\n\r\n/** Properties of [[UnitDescr]] component.\r\n * @internal\r\n */\r\nexport interface UnitDescrProps extends CommonProps {\r\n name: string;\r\n parentUnitName?: string;\r\n label: string;\r\n index: number;\r\n unitsProvider: UnitsProvider;\r\n readonly?: boolean;\r\n onUnitChange: (value: string, index: number) => void;\r\n onLabelChange: (value: string, index: number) => void;\r\n}\r\n\r\nasync function getUnitConversionData(possibleUnits: UnitProps[], toUnit: UnitProps, unitsProvider: UnitsProvider) {\r\n const unitConversionEntries = possibleUnits.map(async (unit) => {\r\n const conversion = await unitsProvider.getConversion(unit, toUnit);\r\n return { conversion, unitProps: unit };\r\n });\r\n return unitConversionEntries;\r\n}\r\n\r\nasync function getPossibleUnits(parentUnit: UnitProps, unitsProvider: UnitsProvider, ensureCompatibleComposite: boolean) {\r\n const phenomenon = parentUnit.phenomenon;\r\n const possibleUnits = await unitsProvider.getUnitsByFamily(phenomenon);\r\n if (!ensureCompatibleComposite)\r\n return possibleUnits;\r\n\r\n const conversionPromises = await getUnitConversionData(possibleUnits, parentUnit, unitsProvider);\r\n const conversionEntries = await Promise.all(conversionPromises);\r\n // sort the entries so the best potential sub unit will be the first one in the array\r\n return conversionEntries.filter((entry) => ((entry.unitProps.system === parentUnit.system) && (entry.conversion.factor < 1)))\r\n .sort((a, b) => b.conversion.factor - a.conversion.factor)\r\n .map((value) => value.unitProps);\r\n}\r\n\r\nfunction getUnitName(fullUnitName: string) {\r\n const nameParts = fullUnitName.split(/[.:]/);\r\n // istanbul ignore else\r\n if (nameParts.length > 0)\r\n return nameParts[nameParts.length - 1];\r\n // istanbul ignore next\r\n throw Error(\"Bad unit name encountered\");\r\n}\r\n\r\n/** Component use to display dropdown list of possible units.\r\n * @internal\r\n */\r\nexport function UnitDescr(props: UnitDescrProps) {\r\n const { name, label, parentUnitName, index, onUnitChange, onLabelChange, readonly, unitsProvider } = props;\r\n const [unitOptions, setUnitOptions] = React.useState<SelectOption<string>[]>([{ value: name, label: getUnitName(name) }]);\r\n const [currentUnit, setCurrentUnit] = React.useState({ name, label });\r\n const isMounted = React.useRef(false);\r\n\r\n React.useEffect(() => {\r\n isMounted.current = true;\r\n return () => {\r\n isMounted.current = false;\r\n };\r\n });\r\n\r\n React.useEffect(() => {\r\n async function fetchAllowableUnitSelections() {\r\n const currentUnitProps = await unitsProvider.findUnitByName(name);\r\n const parentUnit = await unitsProvider.findUnitByName(parentUnitName ? parentUnitName : name);\r\n // istanbul ignore else\r\n if (parentUnit && currentUnitProps) {\r\n let potentialSubUnit: UnitProps | undefined;\r\n const potentialUnits = await getPossibleUnits(parentUnit, unitsProvider, index !== 0);\r\n // istanbul ignore else\r\n if (index < 3) {\r\n const potentialSubUnits = await getPossibleUnits(currentUnitProps, unitsProvider, true);\r\n if (potentialSubUnits.length)\r\n potentialSubUnit = potentialSubUnits[0];\r\n }\r\n\r\n const options = (potentialUnits.length > 0) ?\r\n potentialUnits.map((unitValue) => {\r\n return { value: `${unitValue.name}:${unitValue.label}`, label: getUnitName(unitValue.name) };\r\n }).sort((a, b) => a.label.localeCompare(b.label))\r\n : /* istanbul ignore next */\r\n [{ value: `${currentUnitProps.name}:${currentUnitProps.label}`, label: getUnitName(name) }];\r\n\r\n if (potentialSubUnit) {\r\n // construct an entry that will provide the name and label of the unit to add\r\n options.push({ value: `ADDSUBUNIT:${potentialSubUnit.name}:${potentialSubUnit.label}`, label: \"Add sub-unit\" }); // NEEDSWORK - i18n\r\n }\r\n\r\n if (index !== 0)\r\n options.push({ value: \"REMOVEUNIT\", label: \"Remove\" }); // NEEDSWORK - i18n\r\n\r\n // istanbul ignore else\r\n if (isMounted.current) {\r\n setUnitOptions(options);\r\n setCurrentUnit(currentUnitProps);\r\n }\r\n }\r\n }\r\n fetchAllowableUnitSelections(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }, [index, label, name, parentUnitName, unitsProvider]);\r\n\r\n const handleOnUnitChange = React.useCallback((newValue: string) => {\r\n onUnitChange && onUnitChange(newValue, index);\r\n }, [index, onUnitChange]);\r\n\r\n const handleOnLabelChange = React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => {\r\n e.preventDefault();\r\n onLabelChange && onLabelChange(e.target.value, index);\r\n }, [index, onLabelChange]);\r\n\r\n return (\r\n <>\r\n <Select options={unitOptions} data-testid={`unit-${currentUnit.name}`} value={`${currentUnit.name}:${currentUnit.label}`}\r\n onChange={handleOnUnitChange} disabled={readonly} size=\"small\" />\r\n <Input data-testid={`unit-label-${currentUnit.name}`} value={label} onChange={handleOnLabelChange} size=\"small\" />\r\n </>\r\n );\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"InlineEdit.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/timeline/InlineEdit.tsx"],"names":[],"mappings":"AAIA,OAAO,mBAAmB,CAAC;AAE3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,UAAU,eAAgB,SAAQ,WAAW;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK,CAAC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAC/E,OAAO,CAAC,SAAS,CAAuC;gBAE5C,KAAK,EAAE,eAAe;IAMlC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe;IAS1F,OAAO,CAAC,OAAO,CAEb;IAEF,OAAO,CAAC,QAAQ,CAEd;IAEF,OAAO,CAAC,UAAU,CAWhB;IAEF,OAAO,CAAC,SAAS,CAEf;IAEF,OAAO,CAAC,WAAW;IAMH,MAAM;CAcvB"}
1
+ {"version":3,"file":"InlineEdit.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/timeline/InlineEdit.tsx"],"names":[],"mappings":"AAIA,OAAO,mBAAmB,CAAC;AAE3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,UAAU,eAAgB,SAAQ,WAAW;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK,CAAC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAC/E,OAAO,CAAC,SAAS,CAAuC;gBAE5C,KAAK,EAAE,eAAe;IAMlC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,eAAe;IAS1F,OAAO,CAAC,OAAO,CAEb;IAEF,OAAO,CAAC,QAAQ,CAEd;IAEF,OAAO,CAAC,UAAU,CAWhB;IAEF,OAAO,CAAC,SAAS,CAEf;IAEF,OAAO,CAAC,WAAW;IAMH,MAAM;CAgBvB"}
@@ -75,7 +75,7 @@ class InlineEdit extends React.Component {
75
75
  this.props.onChange(value);
76
76
  }
77
77
  render() {
78
- return (React.createElement(itwinui_react_1.Input, { "data-testid": "timeline-duration-edit-input", className: (0, classnames_1.default)("inline-edit-input", this.props.className), ref: this._inputRef, type: "text", value: this.state.value, onFocus: this._onFocus, onBlur: this._onBlur, onKeyDown: this._onKeyDown, onChange: this._onChange }));
78
+ return (React.createElement(itwinui_react_1.Input, { "data-testid": "timeline-duration-edit-input", className: (0, classnames_1.default)("inline-edit-input", this.props.className), style: this.props.style, ref: this._inputRef, type: "text", value: this.state.value, size: "small", onFocus: this._onFocus, onBlur: this._onBlur, onKeyDown: this._onKeyDown, onChange: this._onChange }));
79
79
  }
80
80
  }
81
81
  exports.InlineEdit = InlineEdit;
@@ -1 +1 @@
1
- {"version":3,"file":"InlineEdit.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/timeline/InlineEdit.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,6BAA2B;AAC3B,4DAAoC;AACpC,6CAA+B;AAC/B,0DAAmD;AAEnD,wDAA6C;AAY7C;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK,CAAC,SAA2C;IAG/E,YAAY,KAAsB;QAChC,KAAK,CAAC,KAAK,CAAC,CAAC;QAHP,cAAS,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAiBxD,uBAAuB;QACf,YAAO,GAAG,CAAC,KAA0C,EAAE,EAAE;YAC/D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC,CAAC;QAEM,aAAQ,GAAG,CAAC,KAA0C,EAAE,EAAE;YAChE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC;QAEM,eAAU,GAAG,CAAC,KAA4C,EAAE,EAAE;YACpE,QAAQ,KAAK,CAAC,GAAG,EAAE;gBACjB,KAAK,2BAAU,CAAC,MAAM;oBACpB,IAAI,CAAC,QAAQ,CACX,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,aAAa,EAAE,CAAC,EACnD,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;oBAC1C,MAAM;gBACR,KAAK,2BAAU,CAAC,KAAK;oBACnB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACnC,MAAM;aACT;QACH,CAAC,CAAC;QAEM,cAAS,GAAG,CAAC,KAA0C,EAAE,EAAE;YACjE,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC;QApCA,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IAC1F,CAAC;IAED,gBAAgB;IACA,kBAAkB,CAAC,SAA0B,EAAE,UAA2B;QACxF,IAAI,SAAS,CAAC,YAAY,KAAK,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE;YACtD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;gBACzB,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE,aAAa,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC;YAC1E,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IA4BO,WAAW,CAAC,KAAa;QAC/B,uBAAuB;QACvB,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ;YACrB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAEe,MAAM;QACpB,OAAO,CACL,oBAAC,qBAAK,mBACQ,8BAA8B,EAC1C,SAAS,EAAE,IAAA,oBAAU,EAAC,mBAAmB,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAChE,GAAG,EAAE,IAAI,CAAC,SAAS,EACnB,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,OAAO,EAAE,IAAI,CAAC,QAAQ,EACtB,MAAM,EAAE,IAAI,CAAC,OAAO,EACpB,SAAS,EAAE,IAAI,CAAC,UAAU,EAC1B,QAAQ,EAAE,IAAI,CAAC,SAAS,GAAI,CAC/B,CAAC;IACJ,CAAC;CACF;AAhED,gCAgEC","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\nimport \"./InlineEdit.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { SpecialKey } from \"@itwin/appui-abstract\";\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { Input } from \"@itwin/itwinui-react\";\r\n\r\ninterface InlineEditProps extends CommonProps {\r\n defaultValue: string;\r\n onChange?: (value: string) => void;\r\n}\r\n\r\ninterface InlineEditState {\r\n value: string;\r\n originalValue: string;\r\n}\r\n\r\n/** Duration Inline Editor\r\n * @internal\r\n */\r\nexport class InlineEdit extends React.Component<InlineEditProps, InlineEditState> {\r\n private _inputRef = React.createRef<HTMLInputElement>();\r\n\r\n constructor(props: InlineEditProps) {\r\n super(props);\r\n\r\n this.state = { value: this.props.defaultValue, originalValue: this.props.defaultValue };\r\n }\r\n\r\n /** @internal */\r\n public override componentDidUpdate(prevProps: InlineEditProps, _prevState: InlineEditState) { // eslint-disable-line @typescript-eslint/naming-convention\r\n if (prevProps.defaultValue !== this.props.defaultValue) {\r\n this.setState((_, props) => {\r\n return { value: props.defaultValue, originalValue: props.defaultValue };\r\n });\r\n }\r\n }\r\n\r\n // istanbul ignore next\r\n private _onBlur = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n this._sendChange(event.target.value);\r\n };\r\n\r\n private _onFocus = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n event.target.select();\r\n };\r\n\r\n private _onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n switch (event.key) {\r\n case SpecialKey.Escape:\r\n this.setState(\r\n (prevState) => ({ value: prevState.originalValue }),\r\n () => this._inputRef.current!.select());\r\n break;\r\n case SpecialKey.Enter:\r\n this._sendChange(this.state.value);\r\n break;\r\n }\r\n };\r\n\r\n private _onChange = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n this.setState({ value: event.target.value });\r\n };\r\n\r\n private _sendChange(value: string) {\r\n // istanbul ignore else\r\n if (this.props.onChange)\r\n this.props.onChange(value);\r\n }\r\n\r\n public override render() {\r\n return (\r\n <Input\r\n data-testid=\"timeline-duration-edit-input\"\r\n className={classnames(\"inline-edit-input\", this.props.className)}\r\n ref={this._inputRef}\r\n type=\"text\"\r\n value={this.state.value}\r\n onFocus={this._onFocus}\r\n onBlur={this._onBlur}\r\n onKeyDown={this._onKeyDown}\r\n onChange={this._onChange} />\r\n );\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"InlineEdit.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/timeline/InlineEdit.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,6BAA2B;AAC3B,4DAAoC;AACpC,6CAA+B;AAC/B,0DAAmD;AAEnD,wDAA6C;AAY7C;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK,CAAC,SAA2C;IAG/E,YAAY,KAAsB;QAChC,KAAK,CAAC,KAAK,CAAC,CAAC;QAHP,cAAS,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAiBxD,uBAAuB;QACf,YAAO,GAAG,CAAC,KAA0C,EAAE,EAAE;YAC/D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC,CAAC;QAEM,aAAQ,GAAG,CAAC,KAA0C,EAAE,EAAE;YAChE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC;QAEM,eAAU,GAAG,CAAC,KAA4C,EAAE,EAAE;YACpE,QAAQ,KAAK,CAAC,GAAG,EAAE;gBACjB,KAAK,2BAAU,CAAC,MAAM;oBACpB,IAAI,CAAC,QAAQ,CACX,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,aAAa,EAAE,CAAC,EACnD,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAQ,CAAC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MAAM,EACX,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,IAAI,EAAC,OAAO,EACZ,OAAO,EAAE,IAAI,CAAC,QAAQ,EACtB,MAAM,EAAE,IAAI,CAAC,OAAO,EACpB,SAAS,EAAE,IAAI,CAAC,UAAU,EAC1B,QAAQ,EAAE,IAAI,CAAC,SAAS,GAAI,CAC/B,CAAC;IACJ,CAAC;CACF;AAlED,gCAkEC","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\nimport \"./InlineEdit.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { SpecialKey } from \"@itwin/appui-abstract\";\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { Input } from \"@itwin/itwinui-react\";\r\n\r\ninterface InlineEditProps extends CommonProps {\r\n defaultValue: string;\r\n onChange?: (value: string) => void;\r\n}\r\n\r\ninterface InlineEditState {\r\n value: string;\r\n originalValue: string;\r\n}\r\n\r\n/** Duration Inline Editor\r\n * @internal\r\n */\r\nexport class InlineEdit extends React.Component<InlineEditProps, InlineEditState> {\r\n private _inputRef = React.createRef<HTMLInputElement>();\r\n\r\n constructor(props: InlineEditProps) {\r\n super(props);\r\n\r\n this.state = { value: this.props.defaultValue, originalValue: this.props.defaultValue };\r\n }\r\n\r\n /** @internal */\r\n public override componentDidUpdate(prevProps: InlineEditProps, _prevState: InlineEditState) { // eslint-disable-line @typescript-eslint/naming-convention\r\n if (prevProps.defaultValue !== this.props.defaultValue) {\r\n this.setState((_, props) => {\r\n return { value: props.defaultValue, originalValue: props.defaultValue };\r\n });\r\n }\r\n }\r\n\r\n // istanbul ignore next\r\n private _onBlur = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n this._sendChange(event.target.value);\r\n };\r\n\r\n private _onFocus = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n event.target.select();\r\n };\r\n\r\n private _onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n switch (event.key) {\r\n case SpecialKey.Escape:\r\n this.setState(\r\n (prevState) => ({ value: prevState.originalValue }),\r\n () => this._inputRef.current!.select());\r\n break;\r\n case SpecialKey.Enter:\r\n this._sendChange(this.state.value);\r\n break;\r\n }\r\n };\r\n\r\n private _onChange = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n this.setState({ value: event.target.value });\r\n };\r\n\r\n private _sendChange(value: string) {\r\n // istanbul ignore else\r\n if (this.props.onChange)\r\n this.props.onChange(value);\r\n }\r\n\r\n public override render() {\r\n return (\r\n <Input\r\n data-testid=\"timeline-duration-edit-input\"\r\n className={classnames(\"inline-edit-input\", this.props.className)}\r\n style={this.props.style}\r\n ref={this._inputRef}\r\n type=\"text\"\r\n value={this.state.value}\r\n size=\"small\"\r\n onFocus={this._onFocus}\r\n onBlur={this._onBlur}\r\n onKeyDown={this._onKeyDown}\r\n onChange={this._onChange} />\r\n );\r\n }\r\n}\r\n"]}
@@ -35,33 +35,9 @@ export interface ViewportProps extends CommonProps {
35
35
  /** @internal used only for testing */
36
36
  tentativePointOverride?: TentativePoint;
37
37
  }
38
- /** @internal */
39
- interface ViewportState {
40
- viewId: string;
41
- }
42
38
  /**
43
39
  * A viewport React component that creates a ScreenViewport.
44
40
  * @public
45
41
  */
46
- export declare class ViewportComponent extends React.Component<ViewportProps, ViewportState> {
47
- private _viewportDiv;
48
- private _vp?;
49
- private _viewClassFullName;
50
- private _lastTargetPoint?;
51
- private _mounted;
52
- constructor(props: ViewportProps);
53
- private _handleDisconnectFromViewManager;
54
- componentDidMount(): Promise<void>;
55
- componentWillUnmount(): void;
56
- componentDidUpdate(prevProps: ViewportProps): Promise<void>;
57
- private getViewState;
58
- private _handleDrawingViewportChangeEvent;
59
- private _getRotatePoint;
60
- private _handleCubeRotationChangeEvent;
61
- private _handleStandardRotationChangeEvent;
62
- private _handleViewChanged;
63
- private _handleContextMenu;
64
- render(): JSX.Element;
65
- }
66
- export {};
42
+ export declare function ViewportComponent(props: ViewportProps): JSX.Element;
67
43
  //# sourceMappingURL=ViewportComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ViewportComponent.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/viewport/ViewportComponent.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAU,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EACM,gBAAgB,EAAE,cAAc,EAC3C,cAAc,EAAgB,WAAW,EAC/B,SAAS,EACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD;;GAEG;AACH,oBAAY,aAAa,GAAG,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,wBAAwB;IACxB,MAAM,EAAE,gBAAgB,CAAC;IACzB,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC;IACjD,gBAAgB;IAChB,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/D,sCAAsC;IACtC,mBAAmB,CAAC,EAAE,WAAW,CAAC;IAClC,sCAAsC;IACtC,sBAAsB,CAAC,EAAE,OAAO,cAAc,CAAC;IAC/C,sCAAsC;IACtC,sBAAsB,CAAC,EAAE,cAAc,CAAC;CACzC;AAED,gBAAgB;AAChB,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK,CAAC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAElF,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,GAAG,CAAC,CAAiB;IAC7B,OAAO,CAAC,kBAAkB,CAAc;IACxC,OAAO,CAAC,gBAAgB,CAAC,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAkB;gBAEf,KAAK,EAAE,aAAa;IAQvC,OAAO,CAAC,gCAAgC,CAetC;IAEoB,iBAAiB;IA2CvB,oBAAoB;IAQd,kBAAkB,CAAC,SAAS,EAAE,aAAa;YAsBnD,YAAY;IAwB1B,OAAO,CAAC,iCAAiC,CASvC;IAEF,OAAO,CAAC,eAAe;IA6BvB,OAAO,CAAC,8BAA8B,CAmBpC;IAEF,OAAO,CAAC,kCAAkC,CASxC;IAEF,OAAO,CAAC,kBAAkB,CAqBxB;IAEF,OAAO,CAAC,kBAAkB,CAKxB;IAEc,MAAM;CAyBvB"}
1
+ {"version":3,"file":"ViewportComponent.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/viewport/ViewportComponent.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAU,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EACM,gBAAgB,EAAE,cAAc,EAC3C,cAAc,EAAgB,WAAW,EAC/B,SAAS,EACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhD;;GAEG;AACH,oBAAY,aAAa,GAAG,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,wBAAwB;IACxB,MAAM,EAAE,gBAAgB,CAAC;IACzB,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC;IACjD,gBAAgB;IAChB,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/D,sCAAsC;IACtC,mBAAmB,CAAC,EAAE,WAAW,CAAC;IAClC,sCAAsC;IACtC,sBAAsB,CAAC,EAAE,OAAO,cAAc,CAAC;IAC/C,sCAAsC;IACtC,sBAAsB,CAAC,EAAE,cAAc,CAAC;CACzC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,eA2PrD"}
@@ -32,186 +32,66 @@ const core_bentley_1 = require("@itwin/core-bentley");
32
32
  const core_geometry_1 = require("@itwin/core-geometry");
33
33
  const core_common_1 = require("@itwin/core-common");
34
34
  const core_frontend_1 = require("@itwin/core-frontend");
35
- const UiIModelComponents_1 = require("../UiIModelComponents");
36
35
  const ViewportComponentEvents_1 = require("./ViewportComponentEvents");
37
36
  /**
38
37
  * A viewport React component that creates a ScreenViewport.
39
38
  * @public
40
39
  */
41
- class ViewportComponent extends React.Component {
42
- constructor(props) {
43
- super(props);
44
- this._viewClassFullName = "";
45
- this._mounted = false;
46
- this._handleDisconnectFromViewManager = () => {
47
- const screenViewport = this._vp;
48
- const parentDiv = this._viewportDiv.current;
49
- if (screenViewport) {
50
- const viewManager = core_frontend_1.IModelApp.viewManager;
51
- viewManager.dropViewport(screenViewport, true);
52
- screenViewport.onViewChanged.removeListener(this._handleViewChanged);
53
- this._vp = undefined;
54
- }
55
- // istanbul ignore else
56
- if (parentDiv) {
57
- const parentWindow = parentDiv.ownerDocument.defaultView;
58
- parentWindow.removeEventListener("beforeunload", this._handleDisconnectFromViewManager, false);
59
- }
60
- };
61
- this._handleDrawingViewportChangeEvent = (args) => {
62
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
63
- /* istanbul ignore else */
64
- if (this._vp && viewManager.selectedView === this._vp) {
65
- this._vp.view.setOrigin(args.origin);
66
- this._vp.view.setRotation(args.rotation);
67
- this._vp.synchWithView({ noSaveInUndo: args.complete !== true });
68
- }
69
- };
70
- this._handleCubeRotationChangeEvent = (args) => {
71
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
72
- /* istanbul ignore else */
73
- if (this._vp && viewManager.selectedView === this._vp) {
74
- const rotMatrix = args.rotMatrix;
75
- /* istanbul ignore else */
76
- if (this._vp.rotation !== rotMatrix) {
77
- const inverse = rotMatrix.transpose(); // rotation is from current nav cube state...
78
- const center = this._getRotatePoint(this._vp);
79
- const targetMatrix = inverse.multiplyMatrixMatrix(this._vp.view.getRotation());
80
- const worldTransform = core_geometry_1.Transform.createFixedPointAndMatrix(center, targetMatrix);
81
- const frustum = this._vp.getWorldFrustum();
82
- frustum.multiply(worldTransform);
83
- this._vp.view.setupFromFrustum(frustum);
84
- this._vp.synchWithView({ noSaveInUndo: !args.complete });
85
- }
86
- }
87
- };
88
- this._handleStandardRotationChangeEvent = (args) => {
89
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
90
- /* istanbul ignore else */
91
- if (this._vp && viewManager.selectedView === this._vp) {
92
- // this._vp.view.setStandardRotation(args.standardRotation);
93
- this._vp.view.setRotationAboutPoint(core_frontend_1.ViewState.getStandardViewMatrix(args.standardRotation));
94
- this._vp.synchWithView();
95
- }
96
- };
97
- this._handleViewChanged = (vp) => {
98
- ViewportComponentEvents_1.ViewportComponentEvents.setViewMatrix(vp);
99
- /* istanbul ignore else */
100
- if (this._viewClassFullName !== vp.view.classFullName) {
101
- setTimeout(() => {
102
- ViewportComponentEvents_1.ViewportComponentEvents.onViewClassFullNameChangedEvent.emit({ viewport: vp, oldName: this._viewClassFullName, newName: vp.view.classFullName });
103
- this._viewClassFullName = vp.view.classFullName;
104
- });
105
- }
106
- /* istanbul ignore else */
107
- if (this.state.viewId !== vp.view.id) {
108
- setTimeout(() => {
109
- ViewportComponentEvents_1.ViewportComponentEvents.onViewIdChangedEvent.emit({ viewport: vp, oldId: this.state.viewId, newId: vp.view.id });
110
- /* istanbul ignore next - flaky mounted condition in the setTimeout */
111
- if (this._mounted)
112
- this.setState({ viewId: vp.view.id });
113
- });
114
- }
115
- };
116
- this._handleContextMenu = (e) => {
117
- e.preventDefault();
118
- if (this.props.onContextMenu)
119
- this.props.onContextMenu(e);
120
- return false;
121
- };
122
- this._viewportDiv = React.createRef();
123
- this.state = {
124
- viewId: "",
125
- };
126
- }
127
- async componentDidMount() {
128
- this._mounted = true;
129
- // istanbul ignore next
130
- if (!this._viewportDiv.current) {
131
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Parent <div> failed to load`);
132
- return;
133
- }
134
- const viewState = await this.getViewState();
135
- if (viewState === undefined) {
136
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Failed to obtain ViewState`);
137
- return;
138
- }
139
- /* istanbul ignore next */
140
- if (!this._mounted)
141
- return;
142
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
143
- const screenViewportFactory = this.props.screenViewportOverride ? this.props.screenViewportOverride : /* istanbul ignore next */ core_frontend_1.ScreenViewport;
144
- const parentDiv = this._viewportDiv.current;
145
- const screenViewport = screenViewportFactory.create(parentDiv, viewState);
146
- this._vp = screenViewport;
147
- viewManager.addViewport(this._vp);
148
- const parentWindow = parentDiv.ownerDocument.defaultView;
149
- parentWindow.addEventListener("beforeunload", this._handleDisconnectFromViewManager, false);
150
- ViewportComponentEvents_1.ViewportComponentEvents.initialize();
151
- ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.addListener(this._handleDrawingViewportChangeEvent);
152
- ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.addListener(this._handleCubeRotationChangeEvent);
153
- ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.addListener(this._handleStandardRotationChangeEvent);
154
- this._vp.onViewChanged.addListener(this._handleViewChanged);
155
- this._viewClassFullName = this._vp.view.classFullName;
156
- this.setState({ viewId: this._vp.view.id });
157
- /* istanbul ignore else */
158
- if (this.props.viewportRef)
159
- this.props.viewportRef(this._vp);
160
- }
161
- componentWillUnmount() {
162
- this._mounted = false;
163
- this._handleDisconnectFromViewManager();
164
- ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.removeListener(this._handleDrawingViewportChangeEvent);
165
- ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.removeListener(this._handleCubeRotationChangeEvent);
166
- ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.removeListener(this._handleStandardRotationChangeEvent);
167
- }
168
- async componentDidUpdate(prevProps) {
169
- if (this.props.imodel === prevProps.imodel &&
170
- this.props.viewState === prevProps.viewState &&
171
- this.props.viewDefinitionId === prevProps.viewDefinitionId)
172
- return;
173
- /* istanbul ignore else */
174
- if (this._vp) {
175
- const viewState = await this.getViewState();
176
- if (viewState === undefined) {
177
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Failed to obtain ViewState`);
178
- return;
179
- }
180
- this._vp.changeView(viewState);
181
- /* istanbul ignore else */
182
- if (this._mounted)
183
- this.setState({ viewId: this._vp.view.id });
40
+ function ViewportComponent(props) {
41
+ const { viewState, imodel, viewDefinitionId, getViewOverlay, viewManagerOverride, tentativePointOverride, onContextMenu, style, className, screenViewportOverride, controlId, viewportRef } = props;
42
+ // istanbul ignore next
43
+ const viewManagerRef = React.useRef(viewManagerOverride !== null && viewManagerOverride !== void 0 ? viewManagerOverride : core_frontend_1.IModelApp.viewManager);
44
+ const tentativePointOverrideRef = React.useRef(tentativePointOverride);
45
+ const screenViewportCreated = React.useRef(false);
46
+ const viewportDiv = React.useRef(null);
47
+ const screenViewportRef = React.useRef(null);
48
+ const isMounted = React.useRef(false);
49
+ const viewClassFullName = React.useRef("");
50
+ const viewId = React.useRef("0");
51
+ const handleViewChanged = (vp) => {
52
+ ViewportComponentEvents_1.ViewportComponentEvents.setViewMatrix(vp);
53
+ // istanbul ignore else
54
+ if (viewClassFullName.current !== vp.view.classFullName) {
55
+ setTimeout(() => {
56
+ ViewportComponentEvents_1.ViewportComponentEvents.onViewClassFullNameChangedEvent.emit({ viewport: vp, oldName: viewClassFullName.current, newName: vp.view.classFullName });
57
+ viewClassFullName.current = vp.view.classFullName;
58
+ });
184
59
  }
185
- }
186
- async getViewState() {
187
- let viewState;
188
- if (this.props.viewState) {
189
- if (typeof this.props.viewState === "function")
190
- viewState = this.props.viewState();
191
- else
192
- viewState = this.props.viewState;
60
+ // istanbul ignore else
61
+ if (viewId.current !== vp.view.id) {
62
+ setTimeout(() => {
63
+ ViewportComponentEvents_1.ViewportComponentEvents.onViewIdChangedEvent.emit({ viewport: vp, oldId: viewId.current, newId: vp.view.id });
64
+ viewId.current = vp.view.id;
65
+ });
193
66
  }
194
- else if (this.props.viewDefinitionId) {
195
- viewState = await this.props.imodel.views.load(this.props.viewDefinitionId);
196
- if (!viewState) {
197
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `View state failed to load`);
198
- return undefined;
199
- }
200
- else {
201
- return viewState;
202
- }
67
+ };
68
+ const handleStandardRotationChangeEvent = (args) => {
69
+ const viewManager = viewManagerRef.current;
70
+ const currentScreenViewport = screenViewportRef.current;
71
+ if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {
72
+ currentScreenViewport.view.setRotationAboutPoint(core_frontend_1.ViewState.getStandardViewMatrix(args.standardRotation));
73
+ currentScreenViewport.synchWithView();
203
74
  }
204
- else {
205
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Either viewDefinitionId or viewState must be provided as a ViewportComponent Prop`);
206
- return undefined;
75
+ };
76
+ const handleDrawingViewportChangeEvent = (args) => {
77
+ const viewManager = viewManagerRef.current;
78
+ const currentScreenViewport = screenViewportRef.current;
79
+ if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {
80
+ currentScreenViewport.view.setOrigin(args.origin);
81
+ currentScreenViewport.view.setRotation(args.rotation);
82
+ currentScreenViewport.synchWithView({ noSaveInUndo: args.complete !== true });
207
83
  }
208
- return viewState.clone();
209
- }
210
- _getRotatePoint(vp) {
211
- const tentativePoint = this.props.tentativePointOverride ? this.props.tentativePointOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.tentativePoint;
84
+ };
85
+ const targetPoint = React.useRef(null);
86
+ const getRotatePoint = (vp) => {
87
+ var _a, _b;
88
+ const lastTargetPoint = targetPoint.current;
89
+ // istanbul ignore next
90
+ const tentativePoint = (_a = tentativePointOverrideRef.current) !== null && _a !== void 0 ? _a : core_frontend_1.IModelApp.tentativePoint;
91
+ // istanbul ignore else
212
92
  if (tentativePoint.isActive)
213
93
  return tentativePoint.getPoint();
214
- /* istanbul ignore else */
94
+ // istanbul ignore else
215
95
  if (undefined !== vp.viewCmdTargetCenter) {
216
96
  const testPt = vp.worldToView(vp.viewCmdTargetCenter);
217
97
  const viewRect = vp.viewRect;
@@ -219,32 +99,163 @@ class ViewportComponent extends React.Component {
219
99
  return vp.viewCmdTargetCenter;
220
100
  vp.viewCmdTargetCenter = undefined;
221
101
  }
222
- if (undefined !== this._lastTargetPoint) {
223
- const testPt = vp.worldToView(this._lastTargetPoint);
102
+ // istanbul ignore else
103
+ if (null !== lastTargetPoint) {
104
+ const testPt = vp.worldToView(lastTargetPoint);
224
105
  const viewRect = vp.viewRect.clone();
225
106
  viewRect.scaleAboutCenter(0.25, 0.25);
226
107
  // istanbul ignore next hard to reach because of mocks
227
108
  if (viewRect.containsPoint(testPt))
228
- return this._lastTargetPoint;
229
- this._lastTargetPoint = undefined;
109
+ return lastTargetPoint;
110
+ targetPoint.current = null;
230
111
  }
231
112
  const visiblePoint = vp.pickNearestVisibleGeometry(vp.npcToWorld(core_common_1.NpcCenter), vp.pixelsFromInches(core_frontend_1.ToolSettings.viewToolPickRadiusInches));
232
- this._lastTargetPoint = (undefined !== visiblePoint ? visiblePoint : vp.view.getTargetPoint());
233
- return this._lastTargetPoint;
234
- }
235
- render() {
236
- const viewOverlay = this._vp && this.props.getViewOverlay ? this.props.getViewOverlay(this._vp) : null;
237
- const parentDivStyle = {
238
- height: "100%", width: "100%", position: "relative",
239
- };
240
- const viewportDivStyle = {
241
- height: "100%", width: "100%",
242
- ...this.props.style,
113
+ targetPoint.current = (undefined !== visiblePoint ? visiblePoint : vp.view.getTargetPoint());
114
+ // istanbul ignore next
115
+ return (_b = targetPoint.current) !== null && _b !== void 0 ? _b : vp.view.getCenter();
116
+ };
117
+ const handleCubeRotationChangeEvent = (args) => {
118
+ const viewManager = viewManagerRef.current;
119
+ const currentScreenViewport = screenViewportRef.current;
120
+ // istanbul ignore else
121
+ if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {
122
+ const rotMatrix = args.rotMatrix;
123
+ // istanbul ignore else
124
+ if (currentScreenViewport.rotation !== rotMatrix) {
125
+ const inverse = rotMatrix.transpose(); // rotation is from current nav cube state...
126
+ const center = getRotatePoint(currentScreenViewport);
127
+ const targetMatrix = inverse.multiplyMatrixMatrix(currentScreenViewport.view.getRotation());
128
+ const worldTransform = core_geometry_1.Transform.createFixedPointAndMatrix(center, targetMatrix);
129
+ const frustum = currentScreenViewport.getWorldFrustum();
130
+ frustum.multiply(worldTransform);
131
+ currentScreenViewport.view.setupFromFrustum(frustum);
132
+ currentScreenViewport.synchWithView({ noSaveInUndo: !args.complete });
133
+ }
134
+ }
135
+ };
136
+ const handleDisconnectFromViewManager = () => {
137
+ const screenViewport = screenViewportRef.current;
138
+ if (screenViewport) {
139
+ const viewManager = core_frontend_1.IModelApp.viewManager;
140
+ viewManager.dropViewport(screenViewport, true);
141
+ screenViewport.onViewChanged.removeListener(handleViewChanged);
142
+ screenViewportRef.current = null;
143
+ screenViewportCreated.current = false;
144
+ ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.removeListener(handleDrawingViewportChangeEvent);
145
+ ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.removeListener(handleCubeRotationChangeEvent);
146
+ ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.removeListener(handleStandardRotationChangeEvent);
147
+ }
148
+ };
149
+ const getScreenViewport = (parentDiv, inViewState) => {
150
+ // istanbul ignore next
151
+ const screenViewportFactory = screenViewportOverride ? screenViewportOverride : core_frontend_1.ScreenViewport;
152
+ const parentWindow = parentDiv.ownerDocument.defaultView;
153
+ parentWindow.addEventListener("beforeunload", handleDisconnectFromViewManager, true); // listener clear after being called
154
+ ViewportComponentEvents_1.ViewportComponentEvents.initialize();
155
+ ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.addListener(handleDrawingViewportChangeEvent);
156
+ ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.addListener(handleCubeRotationChangeEvent);
157
+ ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.addListener(handleStandardRotationChangeEvent);
158
+ const screenViewport = screenViewportFactory.create(parentDiv, inViewState);
159
+ screenViewportCreated.current = true;
160
+ viewClassFullName.current = screenViewport.view.classFullName;
161
+ viewId.current = screenViewport.view.id;
162
+ screenViewport.onViewChanged.addListener(handleViewChanged);
163
+ return screenViewport;
164
+ };
165
+ React.useEffect(() => {
166
+ isMounted.current = true;
167
+ core_bentley_1.Logger.logInfo("ViewportComponent", `mounting ViewportComponent for controlId=${controlId}`);
168
+ return () => {
169
+ isMounted.current = false;
170
+ core_bentley_1.Logger.logInfo("ViewportComponent", `un-mounting ViewportComponent for controlId=${controlId}`);
171
+ handleDisconnectFromViewManager();
243
172
  };
244
- return (React.createElement("div", { style: parentDivStyle },
245
- React.createElement("div", { ref: this._viewportDiv, "data-testid": "viewport-component", className: this.props.className, style: viewportDivStyle, onContextMenu: this._handleContextMenu }),
246
- viewOverlay));
247
- }
173
+ // eslint-disable-next-line react-hooks/exhaustive-deps
174
+ }, []);
175
+ const [initialViewState, setInitialViewState] = React.useState(() => {
176
+ if (viewState) {
177
+ if (typeof viewState === "function")
178
+ return viewState().clone();
179
+ else
180
+ return viewState.clone();
181
+ }
182
+ return undefined;
183
+ });
184
+ React.useEffect(() => {
185
+ setInitialViewState(undefined);
186
+ }, [viewDefinitionId, viewState]);
187
+ React.useEffect(() => {
188
+ async function fetchInitialViewstate() {
189
+ let currentViewState;
190
+ if (viewState) {
191
+ if (typeof viewState === "function")
192
+ currentViewState = viewState();
193
+ else
194
+ currentViewState = viewState;
195
+ }
196
+ else if (viewDefinitionId && imodel) {
197
+ try {
198
+ currentViewState = await imodel.views.load(viewDefinitionId);
199
+ // istanbul ignore next
200
+ if (!currentViewState) {
201
+ core_bentley_1.Logger.logError("ViewportComponent", `Viewstate failed to load`);
202
+ }
203
+ }
204
+ catch (_e) {
205
+ // istanbul ignore next
206
+ core_bentley_1.Logger.logError("ViewportComponent", `Viewstate failed to load`);
207
+ }
208
+ }
209
+ else {
210
+ core_bentley_1.Logger.logError("ViewportComponent", `A Viewstate or a viewId and imodel must be provided`);
211
+ }
212
+ // istanbul ignore else
213
+ if (isMounted.current)
214
+ setInitialViewState(currentViewState === null || currentViewState === void 0 ? void 0 : currentViewState.clone());
215
+ }
216
+ if (undefined === initialViewState)
217
+ fetchInitialViewstate(); // eslint-disable-line @typescript-eslint/no-floating-promises
218
+ }, [imodel, initialViewState, viewDefinitionId, viewState]);
219
+ const [viewOverlay, setViewOverlay] = React.useState(null);
220
+ // This useEffect connects to ViewManger as soon as initialViewState is available once component is mounted.
221
+ React.useEffect(() => {
222
+ var _a;
223
+ const parentDiv = viewportDiv.current;
224
+ const viewManager = viewManagerRef.current;
225
+ if (parentDiv && initialViewState) {
226
+ if (!screenViewportCreated.current) {
227
+ const screenViewport = getScreenViewport(parentDiv, initialViewState);
228
+ screenViewportRef.current = screenViewport;
229
+ if (viewportRef)
230
+ viewportRef(screenViewport);
231
+ core_bentley_1.Logger.logInfo("ViewportComponent", `processing viewManager.addViewport for controlId=${controlId}`);
232
+ viewManager.addViewport(screenViewport);
233
+ // overlay component is set up once a ScreenViewport is available. The overlay component must handle any view changes itself.
234
+ setViewOverlay(getViewOverlay ? getViewOverlay(screenViewport) : null);
235
+ }
236
+ else {
237
+ // istanbul ignore next
238
+ (_a = screenViewportRef.current) === null || _a === void 0 ? void 0 : _a.changeView(initialViewState);
239
+ }
240
+ }
241
+ // eslint-disable-next-line react-hooks/exhaustive-deps
242
+ }, [controlId, initialViewState, viewportRef]);
243
+ const handleContextMenu = React.useCallback((e) => {
244
+ e.preventDefault();
245
+ if (onContextMenu)
246
+ onContextMenu(e);
247
+ }, [onContextMenu]);
248
+ const parentDivStyle = {
249
+ height: "100%", width: "100%", position: "relative",
250
+ };
251
+ const viewportDivStyle = {
252
+ ...style,
253
+ height: "100%", width: "100%",
254
+ };
255
+ return (React.createElement("div", { style: parentDivStyle, "data-item-id": controlId },
256
+ React.createElement(React.Fragment, null,
257
+ React.createElement("div", { ref: viewportDiv, "data-testid": "viewport-component", className: className, style: viewportDivStyle, onContextMenu: handleContextMenu }),
258
+ viewOverlay)));
248
259
  }
249
260
  exports.ViewportComponent = ViewportComponent;
250
261
  //# sourceMappingURL=ViewportComponent.js.map