@itwin/imodel-components-react 4.6.0 → 4.6.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.
- package/CHANGELOG.md +6 -1
- package/lib/cjs/imodel-components-react/UiIModelComponents.js +2 -4
- package/lib/cjs/imodel-components-react/UiIModelComponents.js.map +1 -1
- package/lib/cjs/imodel-components-react/color/ColorPickerButton.js +1 -1
- package/lib/cjs/imodel-components-react/color/ColorPickerButton.js.map +1 -1
- package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +1 -1
- package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
- package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js +5 -10
- package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js +1 -2
- package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js +2 -2
- package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatType.js +3 -2
- package/lib/cjs/imodel-components-react/quantityformat/FormatType.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js +1 -2
- package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js +6 -10
- package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js +3 -7
- package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
- package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +1 -2
- package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
- package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +7 -9
- package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
- package/lib/esm/imodel-components-react/UiIModelComponents.js +2 -4
- package/lib/esm/imodel-components-react/UiIModelComponents.js.map +1 -1
- package/lib/esm/imodel-components-react/color/ColorPickerButton.js +1 -1
- package/lib/esm/imodel-components-react/color/ColorPickerButton.js.map +1 -1
- package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +1 -1
- package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
- package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js +5 -10
- package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js +1 -2
- package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +2 -2
- package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatType.js +3 -2
- package/lib/esm/imodel-components-react/quantityformat/FormatType.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +1 -2
- package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +6 -10
- package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js +3 -7
- package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
- package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +1 -2
- package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
- package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +7 -9
- package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Change Log - @itwin/imodel-components-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 12 Oct 2023 16:59:20 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.6.1
|
|
6
|
+
Thu, 12 Oct 2023 16:59:20 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
4
9
|
|
|
5
10
|
## 4.6.0
|
|
6
11
|
Wed, 04 Oct 2023 18:05:34 GMT
|
|
@@ -22,12 +22,11 @@ class UiIModelComponents {
|
|
|
22
22
|
* initialize UiIModelComponents.
|
|
23
23
|
*/
|
|
24
24
|
static async initialize() {
|
|
25
|
-
var _a;
|
|
26
25
|
if (UiIModelComponents._initialized) {
|
|
27
26
|
core_bentley_1.Logger.logInfo(UiIModelComponents.loggerCategory(UiIModelComponents), `UiIModelComponents.initialize already called`);
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
|
-
await
|
|
29
|
+
await core_frontend_1.IModelApp.localization?.registerNamespace(UiIModelComponents.localizationNamespace);
|
|
31
30
|
if (!core_frontend_1.IModelApp.localization) {
|
|
32
31
|
// it should only get here in unit test where IModelApp is not setup
|
|
33
32
|
const localization = new core_common_1.EmptyLocalization();
|
|
@@ -41,8 +40,7 @@ class UiIModelComponents {
|
|
|
41
40
|
}
|
|
42
41
|
/** Unregisters the UiIModelComponents localization namespace */
|
|
43
42
|
static terminate() {
|
|
44
|
-
|
|
45
|
-
(_a = core_frontend_1.IModelApp.localization) === null || _a === void 0 ? void 0 : _a.unregisterNamespace(UiIModelComponents.localizationNamespace);
|
|
43
|
+
core_frontend_1.IModelApp.localization?.unregisterNamespace(UiIModelComponents.localizationNamespace);
|
|
46
44
|
components_react_1.UiComponents.terminate();
|
|
47
45
|
UiIModelComponents._initialized = false;
|
|
48
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UiIModelComponents.js","sourceRoot":"","sources":["../../../src/imodel-components-react/UiIModelComponents.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAA6C;AAC7C,wDAAiD;AACjD,0DAAqD;AACrD,8DAAuD;AACvD,oDAAuD;AAEvD;;;GAGG;AACH,MAAa,kBAAkB;IAG7B;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU
|
|
1
|
+
{"version":3,"file":"UiIModelComponents.js","sourceRoot":"","sources":["../../../src/imodel-components-react/UiIModelComponents.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAA6C;AAC7C,wDAAiD;AACjD,0DAAqD;AACrD,8DAAuD;AACvD,oDAAuD;AAEvD;;;GAGG;AACH,MAAa,kBAAkB;IAG7B;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU;QAC5B,IAAI,kBAAkB,CAAC,YAAY,EAAE;YACnC,qBAAM,CAAC,OAAO,CACZ,kBAAkB,CAAC,cAAc,CAAC,kBAAkB,CAAC,EACrD,8CAA8C,CAC/C,CAAC;YACF,OAAO;SACR;QAED,MAAM,yBAAS,CAAC,YAAY,EAAE,iBAAiB,CAC7C,kBAAkB,CAAC,qBAAqB,CACzC,CAAC;QAEF,IAAI,CAAC,yBAAS,CAAC,YAAY,EAAE;YAC3B,oEAAoE;YACpE,MAAM,YAAY,GAAG,IAAI,+BAAiB,EAAE,CAAC;YAC7C,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;YAChC,MAAM,+BAAY,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;SAC7C;aAAM;YACL,MAAM,+BAAY,CAAC,UAAU,CAAC,yBAAS,CAAC,YAAY,CAAC,CAAC;SACvD;QAED,kBAAkB,CAA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":["/*---------------------------------------------------------------------------------------------\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 Common\n */\n\nimport { Logger } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { getClassName } from \"@itwin/appui-abstract\";\nimport { UiComponents } from \"@itwin/components-react\";\nimport { EmptyLocalization } from \"@itwin/core-common\";\n\n/**\n * Manages the localization service for the imodel-components-react package.\n * @public\n */\nexport class UiIModelComponents {\n private static _initialized = false;\n\n /**\n * initialize UiIModelComponents.\n */\n public static async initialize(): Promise<void> {\n if (UiIModelComponents._initialized) {\n Logger.logInfo(\n UiIModelComponents.loggerCategory(UiIModelComponents),\n `UiIModelComponents.initialize already called`\n );\n return;\n }\n\n await IModelApp.localization?.registerNamespace(\n UiIModelComponents.localizationNamespace\n );\n\n if (!IModelApp.localization) {\n // it should only get here in unit test where IModelApp is not setup\n const localization = new EmptyLocalization();\n await localization.initialize();\n await UiComponents.initialize(localization);\n } else {\n await UiComponents.initialize(IModelApp.localization);\n }\n\n UiIModelComponents._initialized = true;\n }\n\n /** Unregisters the UiIModelComponents localization namespace */\n public static terminate() {\n IModelApp.localization?.unregisterNamespace(\n UiIModelComponents.localizationNamespace\n );\n UiComponents.terminate();\n UiIModelComponents._initialized = false;\n }\n\n /** Determines if UiIModelComponents has been initialized */\n public static get initialized(): boolean {\n return UiIModelComponents._initialized;\n }\n\n /** The internationalization service namespace. */\n public static get localizationNamespace(): string {\n return \"UiIModelComponents\";\n }\n\n /** @internal */\n public static get packageName(): string {\n return \"imodel-components-react\";\n }\n\n /** Calls localization.getLocalizedStringWithNamespace with the \"UiIModelComponents\" namespace. Do NOT include the namespace in the key.\n * @internal\n */\n public static translate(key: string | string[]): string {\n if (\n !UiIModelComponents.initialized ||\n /* istanbul ignore next */ !IModelApp.localization\n ) {\n Logger.logError(\n UiIModelComponents.loggerCategory(this),\n `translate: IModelApp.localization has not been setup. Returning blank string.`\n );\n return \"\";\n }\n return IModelApp.localization.getLocalizedString(key, {\n ns: UiIModelComponents.localizationNamespace,\n });\n }\n\n /** @internal */\n public static loggerCategory(obj: any): string {\n const className = getClassName(obj);\n const category =\n UiIModelComponents.packageName + (className ? `.${className}` : \"\");\n return category;\n }\n}\n"]}
|
|
@@ -105,7 +105,7 @@ const ForwardRefColorPickerButton = React.forwardRef(function ForwardRefColorPic
|
|
|
105
105
|
React.createElement("div", { className: "components-colorpicker-button-color-swatch", style: swatchStyle, "data-testid": showPopup ? "caret-up" : "caret-down" }),
|
|
106
106
|
showCaret && (React.createElement(core_react_1.Icon, { className: "components-caret", iconSpec: showPopup ? React.createElement(itwinui_icons_react_1.SvgCaretUpSmall, null) : React.createElement(itwinui_icons_react_1.SvgCaretDownSmall, null) })))),
|
|
107
107
|
React.createElement(core_react_1.Popup, { className: "components-colorpicker-popup", isOpen: showPopup, position: appui_abstract_1.RelativePosition.BottomLeft, onClose: closePopup, target: target.current, closeOnNestedPopupOutsideClick: true },
|
|
108
|
-
React.createElement(ColorOptions, { handleColorPicked: handleColorPicked, options: colorOptions, numColumns: numColumns
|
|
108
|
+
React.createElement(ColorOptions, { handleColorPicked: handleColorPicked, options: colorOptions, numColumns: numColumns ?? 4, round: !!round, title: dropDownTitle }))));
|
|
109
109
|
});
|
|
110
110
|
/** ColorPickerButton component
|
|
111
111
|
* @note Using forwardRef so the ColorEditor (Type Editor) can access the ref of the button element inside this component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorPickerButton.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/color/ColorPickerButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oCAAkC;AAClC,4DAAoC;AACpC,6CAA+B;AAC/B,oDAA2D;AAC3D,0DAAyD;AAEzD,kDAAyD;AACzD,qCAAuC;AAC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AAC,CAAC,YAAY,GAClD;gBACD,SAAS,IAAI,CACZ,oBAAC,iBAAI,IACH,SAAS,EAAC,kBAAkB,EAC5B,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,oBAAC,qCAAe,OAAG,CAAC,CAAC,CAAC,oBAAC,uCAAiB,OAAG,GACjE,CACH,CACG,CACC;QACT,oBAAC,kBAAK,IACJ,SAAS,EAAC,8BAA8B,EACxC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,iCAAgB,CAAC,UAAU,EACrC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,MAAM,CAAC,OAAO,EACtB,8BAA8B;YAE9B,oBAAC,YAAY,IACX,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,CAAC,EAC3B,KAAK,EAAE,CAAC,CAAC,KAAK,EACd,KAAK,EAAE,aAAa,GACpB,CACI,CACP,CACJ,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACU,QAAA,iBAAiB,GAEG,2BAA2B,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 Color\n */\n\nimport \"./ColorPickerButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ColorByName, ColorDef } from \"@itwin/core-common\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Icon, Popup, useRefs } from \"@itwin/core-react\";\nimport { ColorSwatch } from \"./Swatch\";\nimport { getCSSColorFromDef } from \"./getCSSColorFromDef\";\nimport { SvgCaretDownSmall, SvgCaretUpSmall } from \"@itwin/itwinui-icons-react\";\n\n// cSpell:ignore colorpicker\n\nfunction ColorOptions({\n handleColorPicked,\n options,\n numColumns,\n round,\n title,\n}: {\n handleColorPicked: (color: ColorDef) => void;\n options: ColorDef[];\n numColumns: number;\n round: boolean;\n title?: string;\n}) {\n const containerStyle: React.CSSProperties = {\n gridTemplateColumns: `repeat(${numColumns}, 1fr)`,\n };\n return (\n <div className=\"components-colorpicker-popup-container\">\n {title && <h4>{title}</h4>}\n <div\n data-testid=\"components-colorpicker-popup-colors\"\n className=\"components-colorpicker-popup-colors\"\n style={containerStyle}\n >\n {options.map((color, index) => (\n <ColorSwatch\n className=\"components-colorpicker-swatch\"\n key={index}\n colorDef={color}\n onColorPick={handleColorPicked}\n round={round}\n />\n ))}\n </div>\n </div>\n );\n}\n\n/** Properties for the [[ColorPickerButton]] React component\n * @beta\n */\nexport interface ColorPickerProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n CommonProps {\n /** Active color */\n initialColor: ColorDef;\n /** Available colors */\n colorDefs?: ColorDef[];\n /** Function to run when user selects color swatch */\n onColorPick?: ((color: ColorDef) => void) | undefined;\n /** Show swatches as squares unless round is set to true */\n round?: boolean;\n /** Disabled or not */\n disabled?: boolean;\n /** Readonly or not */\n readonly?: boolean;\n /** Title to show at top of DropDown */\n dropDownTitle?: string;\n /** Number of columns */\n numColumns?: number;\n /** Provides ability to return reference to HTMLButtonElement */\n ref?: React.Ref<HTMLButtonElement>;\n /** If true show up/down caret next to color */\n showCaret?: boolean;\n}\n\n// Defined using following pattern (const ColorPickerButton at bottom) to ensure useful API documentation is extracted\nconst ForwardRefColorPickerButton = React.forwardRef<\n HTMLButtonElement,\n ColorPickerProps\n>(function ForwardRefColorPickerButton(\n {\n className,\n colorDefs,\n disabled,\n dropDownTitle,\n initialColor,\n numColumns,\n onColorPick,\n readonly,\n round,\n showCaret,\n style,\n },\n ref\n) {\n const target = React.useRef<HTMLButtonElement>(null);\n const refs = useRefs(target, ref); // combine ref needed for target with the forwardRef needed by the Parent when parent is a Type Editor.\n const [showPopup, setShowPopup] = React.useState(false);\n const [colorDef, setColorDef] = React.useState(initialColor);\n\n // See if new initialColor props have changed since component mounted\n React.useEffect(() => {\n setColorDef(initialColor);\n }, [initialColor]);\n\n const defaultColors = React.useRef([\n ColorDef.create(ColorByName.red),\n ColorDef.create(ColorByName.orange),\n ColorDef.create(ColorByName.yellow),\n ColorDef.create(ColorByName.green),\n ColorDef.create(ColorByName.blue),\n ColorDef.create(ColorByName.indigo),\n ColorDef.create(ColorByName.violet),\n ColorDef.create(ColorByName.black),\n ColorDef.create(ColorByName.white),\n ColorDef.create(ColorByName.cyan),\n ColorDef.create(ColorByName.fuchsia),\n ColorDef.create(ColorByName.tan),\n ColorDef.create(ColorByName.gray),\n ColorDef.create(ColorByName.brown),\n ColorDef.create(ColorByName.purple),\n ColorDef.create(ColorByName.olive),\n ]);\n\n const closePopup = React.useCallback(() => {\n setShowPopup(false);\n }, []);\n\n const togglePopup = React.useCallback(() => {\n setShowPopup(!showPopup);\n }, [showPopup]);\n\n const handleColorPicked = React.useCallback(\n (color: ColorDef) => {\n closePopup();\n\n // istanbul ignore else\n if (!color.equals(colorDef)) {\n setColorDef(color);\n onColorPick && onColorPick(color);\n }\n },\n [closePopup, colorDef, onColorPick]\n );\n\n const rgbaString = getCSSColorFromDef(colorDef);\n\n const buttonStyle = { ...style } as React.CSSProperties;\n const swatchStyle = { backgroundColor: rgbaString } as React.CSSProperties;\n\n const buttonClassNames = classnames(\n \"components-colorpicker-button\",\n round && \"round\",\n readonly && \"readonly\",\n className\n );\n\n const colorOptions =\n colorDefs && colorDefs.length ? colorDefs : defaultColors.current;\n return (\n <>\n <button\n data-testid=\"components-colorpicker-button\"\n data-value={rgbaString}\n onClick={togglePopup}\n className={buttonClassNames}\n style={buttonStyle}\n disabled={disabled}\n ref={refs}\n >\n <div className=\"components-colorpicker-button-container\">\n <div\n className=\"components-colorpicker-button-color-swatch\"\n style={swatchStyle}\n data-testid={showPopup ? \"caret-up\" : \"caret-down\"}\n />\n {showCaret && (\n <Icon\n className=\"components-caret\"\n iconSpec={showPopup ? <SvgCaretUpSmall /> : <SvgCaretDownSmall />}\n />\n )}\n </div>\n </button>\n <Popup\n className=\"components-colorpicker-popup\"\n isOpen={showPopup}\n position={RelativePosition.BottomLeft}\n onClose={closePopup}\n target={target.current}\n closeOnNestedPopupOutsideClick\n >\n <ColorOptions\n handleColorPicked={handleColorPicked}\n options={colorOptions}\n numColumns={numColumns ?? 4}\n round={!!round}\n title={dropDownTitle}\n />\n </Popup>\n </>\n );\n});\n\n/** ColorPickerButton component\n * @note Using forwardRef so the ColorEditor (Type Editor) can access the ref of the button element inside this component.\n * @beta\n */\nexport const ColorPickerButton: (\n props: ColorPickerProps\n) => React.ReactElement | null = ForwardRefColorPickerButton;\n"]}
|
|
1
|
+
{"version":3,"file":"ColorPickerButton.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/color/ColorPickerButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oCAAkC;AAClC,4DAAoC;AACpC,6CAA+B;AAC/B,oDAA2D;AAC3D,0DAAyD;AAEzD,kDAAyD;AACzD,qCAAuC;AACvC,6DAA0D;AAC1D,oEAAgF;AAEhF,4BAA4B;AAE5B,SAAS,YAAY,CAAC,EACpB,iBAAiB,EACjB,OAAO,EACP,UAAU,EACV,KAAK,EACL,KAAK,GAON;IACC,MAAM,cAAc,GAAwB;QAC1C,mBAAmB,EAAE,UAAU,UAAU,QAAQ;KAClD,CAAC;IACF,OAAO,CACL,6BAAK,SAAS,EAAC,wCAAwC;QACpD,KAAK,IAAI,gCAAK,KAAK,CAAM;QAC1B,4CACc,qCAAqC,EACjD,SAAS,EAAC,qCAAqC,EAC/C,KAAK,EAAE,cAAc,IAEpB,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAC7B,oBAAC,oBAAW,IACV,SAAS,EAAC,+BAA+B,EACzC,GAAG,EAAE,KAAK,EACV,QAAQ,EAAE,K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C,CAAC,KAAK,EACd,KAAK,EAAE,aAAa,GACpB,CACI,CACP,CACJ,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACU,QAAA,iBAAiB,GAEG,2BAA2B,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 Color\n */\n\nimport \"./ColorPickerButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ColorByName, ColorDef } from \"@itwin/core-common\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Icon, Popup, useRefs } from \"@itwin/core-react\";\nimport { ColorSwatch } from \"./Swatch\";\nimport { getCSSColorFromDef } from \"./getCSSColorFromDef\";\nimport { SvgCaretDownSmall, SvgCaretUpSmall } from \"@itwin/itwinui-icons-react\";\n\n// cSpell:ignore colorpicker\n\nfunction ColorOptions({\n handleColorPicked,\n options,\n numColumns,\n round,\n title,\n}: {\n handleColorPicked: (color: ColorDef) => void;\n options: ColorDef[];\n numColumns: number;\n round: boolean;\n title?: string;\n}) {\n const containerStyle: React.CSSProperties = {\n gridTemplateColumns: `repeat(${numColumns}, 1fr)`,\n };\n return (\n <div className=\"components-colorpicker-popup-container\">\n {title && <h4>{title}</h4>}\n <div\n data-testid=\"components-colorpicker-popup-colors\"\n className=\"components-colorpicker-popup-colors\"\n style={containerStyle}\n >\n {options.map((color, index) => (\n <ColorSwatch\n className=\"components-colorpicker-swatch\"\n key={index}\n colorDef={color}\n onColorPick={handleColorPicked}\n round={round}\n />\n ))}\n </div>\n </div>\n );\n}\n\n/** Properties for the [[ColorPickerButton]] React component\n * @beta\n */\nexport interface ColorPickerProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n CommonProps {\n /** Active color */\n initialColor: ColorDef;\n /** Available colors */\n colorDefs?: ColorDef[];\n /** Function to run when user selects color swatch */\n onColorPick?: ((color: ColorDef) => void) | undefined;\n /** Show swatches as squares unless round is set to true */\n round?: boolean;\n /** Disabled or not */\n disabled?: boolean;\n /** Readonly or not */\n readonly?: boolean;\n /** Title to show at top of DropDown */\n dropDownTitle?: string;\n /** Number of columns */\n numColumns?: number;\n /** Provides ability to return reference to HTMLButtonElement */\n ref?: React.Ref<HTMLButtonElement>;\n /** If true show up/down caret next to color */\n showCaret?: boolean;\n}\n\n// Defined using following pattern (const ColorPickerButton at bottom) to ensure useful API documentation is extracted\nconst ForwardRefColorPickerButton = React.forwardRef<\n HTMLButtonElement,\n ColorPickerProps\n>(function ForwardRefColorPickerButton(\n {\n className,\n colorDefs,\n disabled,\n dropDownTitle,\n initialColor,\n numColumns,\n onColorPick,\n readonly,\n round,\n showCaret,\n style,\n },\n ref\n) {\n const target = React.useRef<HTMLButtonElement>(null);\n const refs = useRefs(target, ref); // combine ref needed for target with the forwardRef needed by the Parent when parent is a Type Editor.\n const [showPopup, setShowPopup] = React.useState(false);\n const [colorDef, setColorDef] = React.useState(initialColor);\n\n // See if new initialColor props have changed since component mounted\n React.useEffect(() => {\n setColorDef(initialColor);\n }, [initialColor]);\n\n const defaultColors = React.useRef([\n ColorDef.create(ColorByName.red),\n ColorDef.create(ColorByName.orange),\n ColorDef.create(ColorByName.yellow),\n ColorDef.create(ColorByName.green),\n ColorDef.create(ColorByName.blue),\n ColorDef.create(ColorByName.indigo),\n ColorDef.create(ColorByName.violet),\n ColorDef.create(ColorByName.black),\n ColorDef.create(ColorByName.white),\n ColorDef.create(ColorByName.cyan),\n ColorDef.create(ColorByName.fuchsia),\n ColorDef.create(ColorByName.tan),\n ColorDef.create(ColorByName.gray),\n ColorDef.create(ColorByName.brown),\n ColorDef.create(ColorByName.purple),\n ColorDef.create(ColorByName.olive),\n ]);\n\n const closePopup = React.useCallback(() => {\n setShowPopup(false);\n }, []);\n\n const togglePopup = React.useCallback(() => {\n setShowPopup(!showPopup);\n }, [showPopup]);\n\n const handleColorPicked = React.useCallback(\n (color: ColorDef) => {\n closePopup();\n\n // istanbul ignore else\n if (!color.equals(colorDef)) {\n setColorDef(color);\n onColorPick && onColorPick(color);\n }\n },\n [closePopup, colorDef, onColorPick]\n );\n\n const rgbaString = getCSSColorFromDef(colorDef);\n\n const buttonStyle = { ...style } as React.CSSProperties;\n const swatchStyle = { backgroundColor: rgbaString } as React.CSSProperties;\n\n const buttonClassNames = classnames(\n \"components-colorpicker-button\",\n round && \"round\",\n readonly && \"readonly\",\n className\n );\n\n const colorOptions =\n colorDefs && colorDefs.length ? colorDefs : defaultColors.current;\n return (\n <>\n <button\n data-testid=\"components-colorpicker-button\"\n data-value={rgbaString}\n onClick={togglePopup}\n className={buttonClassNames}\n style={buttonStyle}\n disabled={disabled}\n ref={refs}\n >\n <div className=\"components-colorpicker-button-container\">\n <div\n className=\"components-colorpicker-button-color-swatch\"\n style={swatchStyle}\n data-testid={showPopup ? \"caret-up\" : \"caret-down\"}\n />\n {showCaret && (\n <Icon\n className=\"components-caret\"\n iconSpec={showPopup ? <SvgCaretUpSmall /> : <SvgCaretDownSmall />}\n />\n )}\n </div>\n </button>\n <Popup\n className=\"components-colorpicker-popup\"\n isOpen={showPopup}\n position={RelativePosition.BottomLeft}\n onClose={closePopup}\n target={target.current}\n closeOnNestedPopupOutsideClick\n >\n <ColorOptions\n handleColorPicked={handleColorPicked}\n options={colorOptions}\n numColumns={numColumns ?? 4}\n round={!!round}\n title={dropDownTitle}\n />\n </Popup>\n </>\n );\n});\n\n/** ColorPickerButton component\n * @note Using forwardRef so the ColorEditor (Type Editor) can access the ref of the button element inside this component.\n * @beta\n */\nexport const ColorPickerButton: (\n props: ColorPickerProps\n) => React.ReactElement | null = ForwardRefColorPickerButton;\n"]}
|
|
@@ -79,7 +79,7 @@ function getUnitLabel(parserSpec) {
|
|
|
79
79
|
return parserSpec.outUnit.label;
|
|
80
80
|
const [unit, label] = format.units[0];
|
|
81
81
|
// istanbul ignore next
|
|
82
|
-
return label
|
|
82
|
+
return label ?? unit.label;
|
|
83
83
|
}
|
|
84
84
|
const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuantityNumberInput(props, ref) {
|
|
85
85
|
const { containerClassName, persistenceValue, min, max, onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuantityNumberInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sCAAoC;AACpC,4DAAoC;AACpC,6CAA+B;AAC/B,kDAAyC;AACzC,0DAAmD;AAKnD,wDAAiD;AAMjD,wDAM8B;AAE9B,wDAA6C;AAC7C,oEAKoC;AAwCpC,wEAAwE;AACxE,SAAS,mBAAmB,CAAC,aAAwC;IACnE,IAAI,SAAS,KAAK,aAAa;QAAE,OAAO,aAAa,CAAC;IACtD,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,4BAAY,CAAC,aAAa;QACvE,IAAI,EAAE,0BAAU,CAAC,OAAO;QACxB,SAAS,EACP,0BAAU,CAAC,OAAO,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI;YAC9C,CAAC,CAAC,gCAAgB,CAAC,IAAI;YACvB,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS;KACrC,CAAC,CAAC;IACH,OAAO,IAAI,6BAAa,CACtB,cAAc,EACd,SAAS,EACT,oBAAoB,EACpB,a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G,CAAC;IACxE,MAAM,SAAS,GAAG,gBAAgB,CAAC,CAAC,CAAC,oBAAC,kCAAY,OAAG,CAAC,CAAC,CAAC,oBAAC,uCAAiB,OAAG,CAAC;IAE9E,OAAO,CACL,6BAAK,SAAS,EAAE,gBAAgB;QAC9B,6BAAK,SAAS,EAAC,6DAA6D;YAC1E,oBAAC,qBAAK,IACJ,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,wBAAwB,EAClC,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAC,OAAO,KACR,UAAU,GACd;YACF,6BACE,SAAS,EAAE,IAAA,oBAAU,EACnB,mDAAmD,EACnD,gBAAgB,IAAI,oCAAoC,CACzD;gBAGD,6BACE,SAAS,EAAC,kFAAkF,EAC5F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,aAAa;oBAEtB,oBAAC,iBAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;gBAEN,6BACE,SAAS,EAAC,oFAAoF,EAC9F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,eAAe;oBAExB,oBAAC,iBAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,CACF,CACF;QACN,8BAAM,SAAS,EAAC,wCAAwC,IACrD,SAAS,CACL,CACH,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,mBAAmB,GAEC,6BAA6B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Inputs\n */\n\nimport \"./QuantityNumberInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Icon } from \"@itwin/core-react\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport type {\n QuantityFormatsChangedArgs,\n QuantityTypeArg,\n} from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport type {\n ParserSpec,\n UnitConversionSpec,\n UnitProps,\n} from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatterSpec,\n FormatTraits,\n FormatType,\n Parser,\n} from \"@itwin/core-quantity\";\nimport type { InputProps } from \"@itwin/itwinui-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport {\n SvgCaretDown,\n SvgCaretDownSmall,\n SvgCaretUp,\n SvgCaretUpSmall,\n} from \"@itwin/itwinui-icons-react\";\n\n/** Step function prototype for [[QuantityNumberInput]] component\n * @beta\n */\nexport type StepFunctionProp =\n | number\n | ((direction: string) => number | undefined);\n\n/** Properties for the [[QuantityNumberInput]] component\n * @beta\n */\nexport interface QuantityNumberInputProps\n extends Omit<\n InputProps,\n \"value\" | \"min\" | \"max\" | \"step\" | \"onFocus\" | \"onChange\"\n > {\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend).\n * Set to `undefined` to show placeholder text */\n persistenceValue?: number;\n /** CSS class name for the QuantityNumberInput component container div */\n containerClassName?: string;\n /** number or function\tNumber.MIN_SAFE_INTEGER */\n min?: number;\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\n max?: number;\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\n step?: StepFunctionProp;\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\n snap?: boolean;\n /** Function to call when the quantity value is changed. The value returned will be in 'persistence' units. */\n onChange?: (value: number) => void;\n /** if true up/down buttons are shown larger and side by side */\n showTouchButtons?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n /** Type of quantity being input. */\n quantityType: QuantityTypeArg;\n}\n\n/** adjust formatter spec to show only primary unit without a label. */\nfunction adjustFormatterSpec(formatterSpec: FormatterSpec | undefined) {\n if (undefined === formatterSpec) return formatterSpec;\n const singleUnitConversion: UnitConversionSpec[] = [];\n singleUnitConversion.push(formatterSpec.unitConversions[0]);\n const newFormat = formatterSpec.format.clone({\n showOnlyPrimaryUnit: true,\n traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,\n type: FormatType.Decimal,\n precision:\n FormatType.Decimal !== formatterSpec.format.type\n ? DecimalPrecision.Four\n : formatterSpec.format.precision,\n });\n return new FormatterSpec(\n \"single-value\",\n newFormat,\n singleUnitConversion,\n formatterSpec.persistenceUnit\n );\n}\n\nfunction convertValueFromDisplayToPersistence(\n value: number,\n unitConversions: UnitConversionSpec[] | undefined,\n unit: UnitProps\n) {\n // istanbul ignore next\n if (!unitConversions || 0 === unitConversions.length) return value;\n\n const unitConversion = unitConversions.find(\n (spec) => spec.name === unit.name\n );\n // istanbul ignore next\n if (!unitConversion) return value;\n\n const convertedValue =\n value * unitConversion.conversion.factor + unitConversion.conversion.offset;\n return convertedValue;\n}\n\nfunction getUnitLabel(parserSpec: ParserSpec | undefined) {\n if (undefined === parserSpec) return \"\";\n\n const format = parserSpec.format;\n // istanbul ignore else\n if (!format.units || !format.units[0]) return parserSpec.outUnit.label;\n const [unit, label] = format.units[0];\n // istanbul ignore next\n return label ?? unit.label;\n}\n\nconst ForwardRefQuantityNumberInput = React.forwardRef<\n HTMLInputElement,\n QuantityNumberInputProps\n>(function ForwardRefQuantityNumberInput(props, ref) {\n const {\n containerClassName,\n persistenceValue,\n min,\n max,\n onChange,\n onBlur,\n onKeyDown,\n step,\n snap,\n showTouchButtons,\n quantityType,\n ...otherProps\n } = props;\n const rawValueRef = React.useRef(persistenceValue);\n\n const [formatterSpec, setFormatterSpec] = React.useState(() =>\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)\n )\n );\n const [parserSpec, setParserSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n\n const formatValue = React.useCallback(\n (value: number | undefined) => {\n if (undefined === value) return \"\";\n\n // istanbul ignore else\n if (formatterSpec) {\n return formatterSpec.applyFormatting(value);\n }\n // istanbul ignore next\n return value.toFixed(2);\n },\n [formatterSpec]\n );\n\n const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));\n const [formattedValue, setFormattedValue] = React.useState(\n () => lastFormattedValueRef.current\n );\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (): void => {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n };\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (\n args: QuantityFormatsChangedArgs\n ): void => {\n const quantityKey =\n IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n // istanbul ignore else\n if (args.quantityType === quantityKey) {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n }\n };\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n const unitLabel = getUnitLabel(parserSpec);\n\n // See if new initialValue props have changed since component mounted\n React.useEffect(() => {\n rawValueRef.current = persistenceValue;\n const currentFormattedValue = formatValue(rawValueRef.current);\n setFormattedValue(currentFormattedValue);\n }, [formatValue, persistenceValue]);\n\n // this is the unprocessed input from user, it is not processed until blur or enter key press\n const handleDisplayValueChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setFormattedValue(event.currentTarget.value);\n },\n []\n );\n\n const updateValue = React.useCallback(\n (newValue: number) => {\n let persistedValue = newValue;\n // istanbul ignore else\n if (parserSpec) {\n // convert value from display unit to persistence unit\n const [unit] = parserSpec.format.units\n ? parserSpec.format.units[0]\n : /* istanbul ignore next */ [parserSpec.outUnit];\n persistedValue = convertValueFromDisplayToPersistence(\n newValue,\n parserSpec.unitConversions,\n unit\n );\n rawValueRef.current = persistedValue;\n }\n const newFormattedVal = formatValue(persistedValue);\n onChange && onChange(persistedValue);\n setFormattedValue(newFormattedVal);\n },\n [formatValue, onChange, parserSpec]\n );\n\n /**\n * Used internally to parse the argument x to it's numeric representation.\n * If the argument cannot be converted to finite number returns 0; If a\n * \"precision\" prop is specified uses it round the number with that\n * precision (no fixed precision here because the return value is float, not\n * string).\n */\n const parseInternal = React.useCallback(\n (x: string | undefined) => {\n if (!x) return 0;\n\n let n = parseFloat(x);\n // istanbul ignore next\n if (isNaN(n) || !isFinite(n)) {\n n = 0;\n }\n\n const localPrecision = 6; // TODO get a reasonable value from format\n const q = Math.pow(10, localPrecision);\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n n = Math.min(Math.max(n, localMin), localMax);\n n = Math.round(n * q) / q;\n\n return n;\n },\n [min, max]\n );\n\n const updateValueFromString = React.useCallback(\n (strValue: string) => {\n // istanbul ignore else\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(\n strValue,\n parserSpec\n );\n // at this point we should have a string value in persistence units without a label\n if (Parser.isParsedQuantity(parseResult)) {\n const persistedValue = parseResult.value; // in persistence units\n // set strValue and let it go through parseInternal which will ensure min/max limits are observed\n strValue = formatValue(persistedValue)!;\n } else {\n // istanbul ignore else\n if (rawValueRef.current) {\n // restore last known good value\n const lastKnownFormattedVal = formatValue(rawValueRef.current);\n setFormattedValue(lastKnownFormattedVal);\n return;\n }\n }\n }\n const newValue = parseInternal(strValue);\n // istanbul ignore else\n if (undefined !== newValue) updateValue(newValue);\n },\n [formatValue, parseInternal, parserSpec, updateValue]\n );\n\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n },\n [parseInternal, updateValue, onBlur]\n );\n\n const getIncrementValue = React.useCallback(\n (increment: boolean) => {\n if (typeof step === \"function\") {\n const stepVal = step(increment ? \"up\" : \"down\");\n return stepVal ? stepVal : 1;\n }\n\n return !step ? 1 : step;\n },\n [step]\n );\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback(\n (increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num =\n parseInternal(formattedValue) +\n (increment ? incrementValue : -incrementValue);\n if (snap) {\n num = Math.round(num / incrementValue) * incrementValue;\n }\n\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n num = Math.min(Math.max(num, localMin), localMax);\n\n updateValue(num);\n },\n [\n formattedValue,\n getIncrementValue,\n max,\n min,\n parseInternal,\n snap,\n updateValue,\n ]\n );\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === 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 },\n [onKeyDown, updateValueFromString, formatValue, applyStep]\n );\n\n const handleDownClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleUpClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n },\n [applyStep]\n );\n\n // istanbul ignore next\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\n \"component-quantity-number-input-container\",\n containerClassName,\n showTouchButtons && \"component-number-buttons-for-touch\",\n isDisabled && \"component-quantity-number-input-disabled\"\n );\n\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\n\n return (\n <div className={containerClasses}>\n <div className=\"component-quantity-number-input-value-and-buttons-container\">\n <Input\n ref={ref}\n value={formattedValue}\n onChange={handleDisplayValueChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n onFocus={handleFocus}\n size=\"small\"\n {...otherProps}\n />\n <div\n className={classnames(\n \"component-quantity-number-input-buttons-container\",\n showTouchButtons && \"component-number-buttons-for-touch\"\n )}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-up\"\n tabIndex={-1}\n onClick={handleUpClick}\n >\n <Icon iconSpec={caretUp} />\n </div>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-down\"\n tabIndex={-1}\n onClick={handleDownClick}\n >\n <Icon iconSpec={caretDown} />\n </div>\n </div>\n </div>\n <span className=\"component-quantity-number-input-suffix\">\n {unitLabel}\n </span>\n </div>\n );\n});\n\n/** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's\n * \"display\" unit is shown next to the input control. The \"display\" unit is determined by the active unit system as defined by the [QuantityFormatter]($frontend).\n * The control also display buttons to increment and decrement the \"displayed\" value. The value reported by via the onChange function is in \"persistence\"\n * units that can be stored in the iModel.\n * @beta\n */\nexport const QuantityNumberInput: (\n props: QuantityNumberInputProps\n) => React.ReactElement | null = ForwardRefQuantityNumberInput;\n"]}
|
|
1
|
+
{"version":3,"file":"QuantityNumberInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sCAAoC;AACpC,4DAAoC;AACpC,6CAA+B;AAC/B,kDAAyC;AACzC,0DAAmD;AAKnD,wDAAiD;AAMjD,wDAM8B;AAE9B,wDAA6C;AAC7C,oEAKoC;AAwCpC,wEAAwE;AACxE,SAAS,mBAAmB,CAAC,aAAwC;IACnE,IAAI,SAAS,KAAK,aAAa;QAAE,OAAO,aAAa,CAAC;IACtD,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,4BAAY,CAAC,aAAa;QACvE,IAAI,EAAE,0BAAU,CAAC,OAAO;QACxB,SAAS,EACP,0BAAU,CAAC,OAAO,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI;YAC9C,CAAC,CAAC,gCAAgB,CAAC,IAAI;YACvB,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS;KACrC,CAAC,CAAC;IACH,OAAO,IAAI,6BAAa,CACtB,cAAc,EACd,SAAS,EACT,oBAAoB,EACpB,aAAa,CAAC,eAAe,CAC9B,CAAC;AACJ,CAAC;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kCAAY,OAAG,CAAC,CAAC,CAAC,oBAAC,uCAAiB,OAAG,CAAC;IAE9E,OAAO,CACL,6BAAK,SAAS,EAAE,gBAAgB;QAC9B,6BAAK,SAAS,EAAC,6DAA6D;YAC1E,oBAAC,qBAAK,IACJ,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,wBAAwB,EAClC,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAC,OAAO,KACR,UAAU,GACd;YACF,6BACE,SAAS,EAAE,IAAA,oBAAU,EACnB,mDAAmD,EACnD,gBAAgB,IAAI,oCAAoC,CACzD;gBAGD,6BACE,SAAS,EAAC,kFAAkF,EAC5F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,aAAa;oBAEtB,oBAAC,iBAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;gBAEN,6BACE,SAAS,EAAC,oFAAoF,EAC9F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,eAAe;oBAExB,oBAAC,iBAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,CACF,CACF;QACN,8BAAM,SAAS,EAAC,wCAAwC,IACrD,SAAS,CACL,CACH,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,mBAAmB,GAEC,6BAA6B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Inputs\n */\n\nimport \"./QuantityNumberInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Icon } from \"@itwin/core-react\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport type {\n QuantityFormatsChangedArgs,\n QuantityTypeArg,\n} from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport type {\n ParserSpec,\n UnitConversionSpec,\n UnitProps,\n} from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatterSpec,\n FormatTraits,\n FormatType,\n Parser,\n} from \"@itwin/core-quantity\";\nimport type { InputProps } from \"@itwin/itwinui-react\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport {\n SvgCaretDown,\n SvgCaretDownSmall,\n SvgCaretUp,\n SvgCaretUpSmall,\n} from \"@itwin/itwinui-icons-react\";\n\n/** Step function prototype for [[QuantityNumberInput]] component\n * @beta\n */\nexport type StepFunctionProp =\n | number\n | ((direction: string) => number | undefined);\n\n/** Properties for the [[QuantityNumberInput]] component\n * @beta\n */\nexport interface QuantityNumberInputProps\n extends Omit<\n InputProps,\n \"value\" | \"min\" | \"max\" | \"step\" | \"onFocus\" | \"onChange\"\n > {\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend).\n * Set to `undefined` to show placeholder text */\n persistenceValue?: number;\n /** CSS class name for the QuantityNumberInput component container div */\n containerClassName?: string;\n /** number or function\tNumber.MIN_SAFE_INTEGER */\n min?: number;\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\n max?: number;\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\n step?: StepFunctionProp;\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\n snap?: boolean;\n /** Function to call when the quantity value is changed. The value returned will be in 'persistence' units. */\n onChange?: (value: number) => void;\n /** if true up/down buttons are shown larger and side by side */\n showTouchButtons?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n /** Type of quantity being input. */\n quantityType: QuantityTypeArg;\n}\n\n/** adjust formatter spec to show only primary unit without a label. */\nfunction adjustFormatterSpec(formatterSpec: FormatterSpec | undefined) {\n if (undefined === formatterSpec) return formatterSpec;\n const singleUnitConversion: UnitConversionSpec[] = [];\n singleUnitConversion.push(formatterSpec.unitConversions[0]);\n const newFormat = formatterSpec.format.clone({\n showOnlyPrimaryUnit: true,\n traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,\n type: FormatType.Decimal,\n precision:\n FormatType.Decimal !== formatterSpec.format.type\n ? DecimalPrecision.Four\n : formatterSpec.format.precision,\n });\n return new FormatterSpec(\n \"single-value\",\n newFormat,\n singleUnitConversion,\n formatterSpec.persistenceUnit\n );\n}\n\nfunction convertValueFromDisplayToPersistence(\n value: number,\n unitConversions: UnitConversionSpec[] | undefined,\n unit: UnitProps\n) {\n // istanbul ignore next\n if (!unitConversions || 0 === unitConversions.length) return value;\n\n const unitConversion = unitConversions.find(\n (spec) => spec.name === unit.name\n );\n // istanbul ignore next\n if (!unitConversion) return value;\n\n const convertedValue =\n value * unitConversion.conversion.factor + unitConversion.conversion.offset;\n return convertedValue;\n}\n\nfunction getUnitLabel(parserSpec: ParserSpec | undefined) {\n if (undefined === parserSpec) return \"\";\n\n const format = parserSpec.format;\n // istanbul ignore else\n if (!format.units || !format.units[0]) return parserSpec.outUnit.label;\n const [unit, label] = format.units[0];\n // istanbul ignore next\n return label ?? unit.label;\n}\n\nconst ForwardRefQuantityNumberInput = React.forwardRef<\n HTMLInputElement,\n QuantityNumberInputProps\n>(function ForwardRefQuantityNumberInput(props, ref) {\n const {\n containerClassName,\n persistenceValue,\n min,\n max,\n onChange,\n onBlur,\n onKeyDown,\n step,\n snap,\n showTouchButtons,\n quantityType,\n ...otherProps\n } = props;\n const rawValueRef = React.useRef(persistenceValue);\n\n const [formatterSpec, setFormatterSpec] = React.useState(() =>\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)\n )\n );\n const [parserSpec, setParserSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n\n const formatValue = React.useCallback(\n (value: number | undefined) => {\n if (undefined === value) return \"\";\n\n // istanbul ignore else\n if (formatterSpec) {\n return formatterSpec.applyFormatting(value);\n }\n // istanbul ignore next\n return value.toFixed(2);\n },\n [formatterSpec]\n );\n\n const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));\n const [formattedValue, setFormattedValue] = React.useState(\n () => lastFormattedValueRef.current\n );\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (): void => {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n };\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (\n args: QuantityFormatsChangedArgs\n ): void => {\n const quantityKey =\n IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n // istanbul ignore else\n if (args.quantityType === quantityKey) {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n }\n };\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n const unitLabel = getUnitLabel(parserSpec);\n\n // See if new initialValue props have changed since component mounted\n React.useEffect(() => {\n rawValueRef.current = persistenceValue;\n const currentFormattedValue = formatValue(rawValueRef.current);\n setFormattedValue(currentFormattedValue);\n }, [formatValue, persistenceValue]);\n\n // this is the unprocessed input from user, it is not processed until blur or enter key press\n const handleDisplayValueChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setFormattedValue(event.currentTarget.value);\n },\n []\n );\n\n const updateValue = React.useCallback(\n (newValue: number) => {\n let persistedValue = newValue;\n // istanbul ignore else\n if (parserSpec) {\n // convert value from display unit to persistence unit\n const [unit] = parserSpec.format.units\n ? parserSpec.format.units[0]\n : /* istanbul ignore next */ [parserSpec.outUnit];\n persistedValue = convertValueFromDisplayToPersistence(\n newValue,\n parserSpec.unitConversions,\n unit\n );\n rawValueRef.current = persistedValue;\n }\n const newFormattedVal = formatValue(persistedValue);\n onChange && onChange(persistedValue);\n setFormattedValue(newFormattedVal);\n },\n [formatValue, onChange, parserSpec]\n );\n\n /**\n * Used internally to parse the argument x to it's numeric representation.\n * If the argument cannot be converted to finite number returns 0; If a\n * \"precision\" prop is specified uses it round the number with that\n * precision (no fixed precision here because the return value is float, not\n * string).\n */\n const parseInternal = React.useCallback(\n (x: string | undefined) => {\n if (!x) return 0;\n\n let n = parseFloat(x);\n // istanbul ignore next\n if (isNaN(n) || !isFinite(n)) {\n n = 0;\n }\n\n const localPrecision = 6; // TODO get a reasonable value from format\n const q = Math.pow(10, localPrecision);\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n n = Math.min(Math.max(n, localMin), localMax);\n n = Math.round(n * q) / q;\n\n return n;\n },\n [min, max]\n );\n\n const updateValueFromString = React.useCallback(\n (strValue: string) => {\n // istanbul ignore else\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(\n strValue,\n parserSpec\n );\n // at this point we should have a string value in persistence units without a label\n if (Parser.isParsedQuantity(parseResult)) {\n const persistedValue = parseResult.value; // in persistence units\n // set strValue and let it go through parseInternal which will ensure min/max limits are observed\n strValue = formatValue(persistedValue)!;\n } else {\n // istanbul ignore else\n if (rawValueRef.current) {\n // restore last known good value\n const lastKnownFormattedVal = formatValue(rawValueRef.current);\n setFormattedValue(lastKnownFormattedVal);\n return;\n }\n }\n }\n const newValue = parseInternal(strValue);\n // istanbul ignore else\n if (undefined !== newValue) updateValue(newValue);\n },\n [formatValue, parseInternal, parserSpec, updateValue]\n );\n\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n },\n [parseInternal, updateValue, onBlur]\n );\n\n const getIncrementValue = React.useCallback(\n (increment: boolean) => {\n if (typeof step === \"function\") {\n const stepVal = step(increment ? \"up\" : \"down\");\n return stepVal ? stepVal : 1;\n }\n\n return !step ? 1 : step;\n },\n [step]\n );\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback(\n (increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num =\n parseInternal(formattedValue) +\n (increment ? incrementValue : -incrementValue);\n if (snap) {\n num = Math.round(num / incrementValue) * incrementValue;\n }\n\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n num = Math.min(Math.max(num, localMin), localMax);\n\n updateValue(num);\n },\n [\n formattedValue,\n getIncrementValue,\n max,\n min,\n parseInternal,\n snap,\n updateValue,\n ]\n );\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === 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 },\n [onKeyDown, updateValueFromString, formatValue, applyStep]\n );\n\n const handleDownClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleUpClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n },\n [applyStep]\n );\n\n // istanbul ignore next\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\n \"component-quantity-number-input-container\",\n containerClassName,\n showTouchButtons && \"component-number-buttons-for-touch\",\n isDisabled && \"component-quantity-number-input-disabled\"\n );\n\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\n\n return (\n <div className={containerClasses}>\n <div className=\"component-quantity-number-input-value-and-buttons-container\">\n <Input\n ref={ref}\n value={formattedValue}\n onChange={handleDisplayValueChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n onFocus={handleFocus}\n size=\"small\"\n {...otherProps}\n />\n <div\n className={classnames(\n \"component-quantity-number-input-buttons-container\",\n showTouchButtons && \"component-number-buttons-for-touch\"\n )}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-up\"\n tabIndex={-1}\n onClick={handleUpClick}\n >\n <Icon iconSpec={caretUp} />\n </div>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-down\"\n tabIndex={-1}\n onClick={handleDownClick}\n >\n <Icon iconSpec={caretDown} />\n </div>\n </div>\n </div>\n <span className=\"component-quantity-number-input-suffix\">\n {unitLabel}\n </span>\n </div>\n );\n});\n\n/** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's\n * \"display\" unit is shown next to the input control. The \"display\" unit is determined by the active unit system as defined by the [QuantityFormatter]($frontend).\n * The control also display buttons to increment and decrement the \"displayed\" value. The value reported by via the onChange function is in \"persistence\"\n * units that can be stored in the iModel.\n * @beta\n */\nexport const QuantityNumberInput: (\n props: QuantityNumberInputProps\n) => React.ReactElement | null = ForwardRefQuantityNumberInput;\n"]}
|
|
@@ -204,9 +204,8 @@ class CubeNavigationAid extends React.Component {
|
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
206
|
this._handleCellHoverChange = (vect, state) => {
|
|
207
|
-
var _a, _b;
|
|
208
207
|
if (this._isInteractionLocked()) {
|
|
209
|
-
|
|
208
|
+
this.props.onAnimationEnd?.();
|
|
210
209
|
return;
|
|
211
210
|
}
|
|
212
211
|
const hoverMap = this.state.hoverMap;
|
|
@@ -222,10 +221,9 @@ class CubeNavigationAid extends React.Component {
|
|
|
222
221
|
return false;
|
|
223
222
|
};
|
|
224
223
|
this._onArrowClick = (arrow) => {
|
|
225
|
-
var _a, _b;
|
|
226
224
|
if (this._isInteractionLocked()) {
|
|
227
225
|
// istanbul ignore next
|
|
228
|
-
|
|
226
|
+
this.props.onAnimationEnd?.();
|
|
229
227
|
return;
|
|
230
228
|
}
|
|
231
229
|
const { newRotation, face } = this.getArrowRotationAndFace(arrow);
|
|
@@ -233,9 +231,8 @@ class CubeNavigationAid extends React.Component {
|
|
|
233
231
|
};
|
|
234
232
|
this._lastClientXY = core_geometry_1.Vector2d.createZero();
|
|
235
233
|
this._handleBoxMouseDown = (event) => {
|
|
236
|
-
var _a, _b;
|
|
237
234
|
if (this._isInteractionLocked()) {
|
|
238
|
-
|
|
235
|
+
this.props.onAnimationEnd?.();
|
|
239
236
|
return;
|
|
240
237
|
}
|
|
241
238
|
event.preventDefault();
|
|
@@ -260,9 +257,8 @@ class CubeNavigationAid extends React.Component {
|
|
|
260
257
|
};
|
|
261
258
|
// istanbul ignore next - unable to test touch
|
|
262
259
|
this._handleBoxTouchStart = (event) => {
|
|
263
|
-
var _a, _b;
|
|
264
260
|
if (this._isInteractionLocked()) {
|
|
265
|
-
|
|
261
|
+
this.props.onAnimationEnd?.();
|
|
266
262
|
return;
|
|
267
263
|
}
|
|
268
264
|
if (1 !== event.targetTouches.length)
|
|
@@ -291,9 +287,8 @@ class CubeNavigationAid extends React.Component {
|
|
|
291
287
|
window.removeEventListener("touchend", this._onTouchEnd);
|
|
292
288
|
};
|
|
293
289
|
this._handleFaceCellClick = (pos, face) => {
|
|
294
|
-
var _a, _b;
|
|
295
290
|
if (this._isInteractionLocked()) {
|
|
296
|
-
|
|
291
|
+
this.props.onAnimationEnd?.();
|
|
297
292
|
return;
|
|
298
293
|
}
|
|
299
294
|
const { endRotMatrix } = this.state;
|