@itwin/components-react 5.18.0 → 5.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/components-react/UiComponents.js +2 -1
- package/lib/components-react/UiComponents.js.map +1 -1
- package/lib/components-react/common/ImageRenderer.js +1 -1
- package/lib/components-react/common/ImageRenderer.js.map +1 -1
- package/lib/components-react/common/SubscriptionScheduler.js +1 -1
- package/lib/components-react/common/SubscriptionScheduler.js.map +1 -1
- package/lib/components-react/common/selection/SelectionHandler.js +20 -2
- package/lib/components-react/common/selection/SelectionHandler.js.map +1 -1
- package/lib/components-react/converters/BooleanTypeConverter.js +4 -4
- package/lib/components-react/converters/BooleanTypeConverter.js.map +1 -1
- package/lib/components-react/converters/PointTypeConverter.js +1 -0
- package/lib/components-react/converters/PointTypeConverter.js.map +1 -1
- package/lib/components-react/converters/TypeConverterManager.js +2 -1
- package/lib/components-react/converters/TypeConverterManager.js.map +1 -1
- package/lib/components-react/datepicker/IntlFormatter.js +1 -0
- package/lib/components-react/datepicker/IntlFormatter.js.map +1 -1
- package/lib/components-react/editors/BooleanEditor.js +23 -26
- package/lib/components-react/editors/BooleanEditor.js.map +1 -1
- package/lib/components-react/editors/CustomNumberEditor.js +92 -97
- package/lib/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/components-react/editors/DateTimeEditor.js +60 -63
- package/lib/components-react/editors/DateTimeEditor.js.map +1 -1
- package/lib/components-react/editors/EnumButtonGroupEditor.js +23 -26
- package/lib/components-react/editors/EnumButtonGroupEditor.js.map +1 -1
- package/lib/components-react/editors/EnumEditor.js +30 -33
- package/lib/components-react/editors/EnumEditor.js.map +1 -1
- package/lib/components-react/editors/IconEditor.js +16 -16
- package/lib/components-react/editors/IconEditor.js.map +1 -1
- package/lib/components-react/editors/ImageCheckBoxEditor.js +22 -25
- package/lib/components-react/editors/ImageCheckBoxEditor.js.map +1 -1
- package/lib/components-react/editors/NumericInputEditor.js +26 -29
- package/lib/components-react/editors/NumericInputEditor.js.map +1 -1
- package/lib/components-react/editors/PopupButton.js +26 -29
- package/lib/components-react/editors/PopupButton.js.map +1 -1
- package/lib/components-react/editors/PropertyEditorManager.js +2 -4
- package/lib/components-react/editors/PropertyEditorManager.js.map +1 -1
- package/lib/components-react/editors/SliderEditor.js +65 -68
- package/lib/components-react/editors/SliderEditor.js.map +1 -1
- package/lib/components-react/editors/TextEditor.js +22 -25
- package/lib/components-react/editors/TextEditor.js.map +1 -1
- package/lib/components-react/editors/TextareaEditor.js +29 -32
- package/lib/components-react/editors/TextareaEditor.js.map +1 -1
- package/lib/components-react/editors/ToggleEditor.js +26 -29
- package/lib/components-react/editors/ToggleEditor.js.map +1 -1
- package/lib/components-react/filter-builder/FilterBuilderState.js +1 -0
- package/lib/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/components-react/filtering/FilteringInput.js +36 -36
- package/lib/components-react/filtering/FilteringInput.js.map +1 -1
- package/lib/components-react/filtering/ResultSelector.js +50 -50
- package/lib/components-react/filtering/ResultSelector.js.map +1 -1
- package/lib/components-react/iconpicker/IconPickerButton.js +18 -18
- package/lib/components-react/iconpicker/IconPickerButton.js.map +1 -1
- package/lib/components-react/properties/ValueRendererManager.js +6 -7
- package/lib/components-react/properties/ValueRendererManager.js.map +1 -1
- package/lib/components-react/properties/renderers/NonPrimitivePropertyRenderer.js +17 -17
- package/lib/components-react/properties/renderers/NonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/components-react/properties/renderers/PropertyGridColumns.js +4 -3
- package/lib/components-react/properties/renderers/PropertyGridColumns.js.map +1 -1
- package/lib/components-react/properties/renderers/PropertyView.js +23 -23
- package/lib/components-react/properties/renderers/PropertyView.js.map +1 -1
- package/lib/components-react/properties/renderers/label/NonPrimitivePropertyLabelRenderer.js +6 -9
- package/lib/components-react/properties/renderers/label/NonPrimitivePropertyLabelRenderer.js.map +1 -1
- package/lib/components-react/properties/renderers/value/table/NonPrimitiveValueRenderer.js +9 -12
- package/lib/components-react/properties/renderers/value/table/NonPrimitiveValueRenderer.js.map +1 -1
- package/lib/components-react/propertygrid/MergingPropertyDataProvider.js +2 -1
- package/lib/components-react/propertygrid/MergingPropertyDataProvider.js.map +1 -1
- package/lib/components-react/propertygrid/PropertyCategoryRendererManager.js +2 -4
- package/lib/components-react/propertygrid/PropertyCategoryRendererManager.js.map +1 -1
- package/lib/components-react/propertygrid/SimplePropertyDataProvider.js +6 -4
- package/lib/components-react/propertygrid/SimplePropertyDataProvider.js.map +1 -1
- package/lib/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js +26 -29
- package/lib/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyCategoryBlock.js +3 -3
- package/lib/components-react/propertygrid/component/PropertyCategoryBlock.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyGridCommons.js +9 -9
- package/lib/components-react/propertygrid/component/PropertyGridCommons.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js +22 -22
- package/lib/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js.map +1 -1
- package/lib/components-react/propertygrid/component/PropertyList.js +5 -5
- package/lib/components-react/propertygrid/component/PropertyList.js.map +1 -1
- package/lib/components-react/propertygrid/component/VirtualizedPropertyGrid.js +29 -29
- package/lib/components-react/propertygrid/component/VirtualizedPropertyGrid.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.js +12 -14
- package/lib/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js +3 -0
- package/lib/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/LabelPropertyDataFilterer.js +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/LabelPropertyDataFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyCategoryLabelFilterer.js +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyCategoryLabelFilterer.js.map +1 -1
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyDataFiltererBase.js +1 -3
- package/lib/components-react/propertygrid/dataproviders/filterers/PropertyDataFiltererBase.js.map +1 -1
- package/lib/components-react/propertygrid/internal/PropertyGridEventHandler.js +11 -10
- package/lib/components-react/propertygrid/internal/PropertyGridEventHandler.js.map +1 -1
- package/lib/components-react/propertygrid/internal/PropertyGridModel.js +3 -3
- package/lib/components-react/propertygrid/internal/PropertyGridModel.js.map +1 -1
- package/lib/components-react/propertygrid/internal/PropertyGridModelSource.js +4 -2
- package/lib/components-react/propertygrid/internal/PropertyGridModelSource.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedArrayProperty.js +2 -0
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedArrayProperty.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedStructProperty.js +2 -0
- package/lib/components-react/propertygrid/internal/flat-items/MutableCategorizedStructProperty.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js +6 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js +10 -7
- package/lib/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-items/MutableGridCategory.js +3 -0
- package/lib/components-react/propertygrid/internal/flat-items/MutableGridCategory.js.map +1 -1
- package/lib/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js +8 -8
- package/lib/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/components-react/toolbar/InternalToolbarComponent.js +4 -4
- package/lib/components-react/toolbar/InternalToolbarComponent.js.map +1 -1
- package/lib/components-react/toolbar/utilities/Direction.js +12 -12
- package/lib/components-react/toolbar/utilities/Direction.js.map +1 -1
- package/lib/components-react/tree/HighlightingEngine.js +3 -1
- package/lib/components-react/tree/HighlightingEngine.js.map +1 -1
- package/lib/components-react/tree/SimpleTreeDataProvider.js +1 -0
- package/lib/components-react/tree/SimpleTreeDataProvider.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeEventDispatcher.js +5 -1
- package/lib/components-react/tree/controlled/TreeEventDispatcher.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeEventHandler.js +10 -14
- package/lib/components-react/tree/controlled/TreeEventHandler.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeModel.js +7 -9
- package/lib/components-react/tree/controlled/TreeModel.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeModelSource.js +3 -2
- package/lib/components-react/tree/controlled/TreeModelSource.js.map +1 -1
- package/lib/components-react/tree/controlled/TreeNodeLoader.js +11 -3
- package/lib/components-react/tree/controlled/TreeNodeLoader.js.map +1 -1
- package/lib/components-react/tree/controlled/component/TreeRenderer.js +1 -4
- package/lib/components-react/tree/controlled/component/TreeRenderer.js.map +1 -1
- package/lib/components-react/tree/controlled/internal/SparseTree.js +7 -5
- package/lib/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/components-react/tree/controlled/internal/TreeModelMutator.js +3 -0
- package/lib/components-react/tree/controlled/internal/TreeModelMutator.js.map +1 -1
- package/lib/components-react/tree/controlled/internal/TreeSelectionManager.js +56 -51
- package/lib/components-react/tree/controlled/internal/TreeSelectionManager.js.map +1 -1
- package/package.json +6 -7
|
@@ -18,42 +18,39 @@ import { useTranslation } from "../l10n/useTranslation.js";
|
|
|
18
18
|
* @alpha
|
|
19
19
|
*/
|
|
20
20
|
export class PopupButton extends React.PureComponent {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
showPopup: false,
|
|
26
|
-
};
|
|
27
|
-
this._togglePopup = (event) => {
|
|
28
|
-
if (this.props.readonly || this.props.disabled)
|
|
29
|
-
return;
|
|
30
|
-
this.setState((prevState) => ({ showPopup: !prevState.showPopup }), () => this.props.onClick && this.props.onClick(event));
|
|
31
|
-
};
|
|
32
|
-
this._closePopup = () => {
|
|
33
|
-
this.setState({ showPopup: false }, () => {
|
|
34
|
-
this.props.onClose && this.props.onClose();
|
|
35
|
-
if (this._buttonRef.current)
|
|
36
|
-
this._buttonRef.current.focus();
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
this._handleKeyDown = (event) => {
|
|
40
|
-
if ((event.key === Key.ArrowDown.valueOf() ||
|
|
41
|
-
event.key === " " ||
|
|
42
|
-
event.key === Key.Enter.valueOf()) &&
|
|
43
|
-
!this.state.showPopup) {
|
|
44
|
-
event.preventDefault();
|
|
45
|
-
event.stopPropagation();
|
|
46
|
-
this.setState({ showPopup: true });
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
21
|
+
_buttonRef = React.createRef();
|
|
22
|
+
state = {
|
|
23
|
+
showPopup: false,
|
|
24
|
+
};
|
|
50
25
|
componentDidMount() {
|
|
51
26
|
if (this.props.setFocus && this._buttonRef.current)
|
|
52
27
|
this._buttonRef.current.focus();
|
|
53
28
|
}
|
|
29
|
+
_togglePopup = (event) => {
|
|
30
|
+
if (this.props.readonly || this.props.disabled)
|
|
31
|
+
return;
|
|
32
|
+
this.setState((prevState) => ({ showPopup: !prevState.showPopup }), () => this.props.onClick && this.props.onClick(event));
|
|
33
|
+
};
|
|
54
34
|
closePopup() {
|
|
55
35
|
this._closePopup();
|
|
56
36
|
}
|
|
37
|
+
_closePopup = () => {
|
|
38
|
+
this.setState({ showPopup: false }, () => {
|
|
39
|
+
this.props.onClose && this.props.onClose();
|
|
40
|
+
if (this._buttonRef.current)
|
|
41
|
+
this._buttonRef.current.focus();
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
_handleKeyDown = (event) => {
|
|
45
|
+
if ((event.key === Key.ArrowDown.valueOf() ||
|
|
46
|
+
event.key === " " ||
|
|
47
|
+
event.key === Key.Enter.valueOf()) &&
|
|
48
|
+
!this.state.showPopup) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
this.setState({ showPopup: true });
|
|
52
|
+
}
|
|
53
|
+
};
|
|
57
54
|
render() {
|
|
58
55
|
const showArrow = this.props.showArrow ?? false;
|
|
59
56
|
const showShadow = this.props.showShadow ?? false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopupButton.js","sourceRoot":"","sources":["../../../src/components-react/editors/PopupButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,SAAS,GACV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AA+C3D;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK,CAAC,aAGtC;IAHD;;QAIU,eAAU,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QAE9B,UAAK,GAA+B;YAC3D,SAAS,EAAE,KAAK;SACjB,CAAC;QAOM,iB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,oBAAC,MAAM,IACL,SAAS,EAAE,UAAU,CACnB,+BAA+B,EAC/B,4BAA4B,CAC7B,iBACW,4BAA4B,EACxC,SAAS,EAAC,KAAK,EACf,KAAK,EAAE,SAAS,CAAC,WAAW,CAAC,EAC7B,OAAO,EAAE,KAAK,CAAC,IAAI;YAGnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,YAAY,OAAG,GAAI,CAC7B;QACT,oBAAC,MAAM,IACL,SAAS,EAAE,UAAU,CACnB,+BAA+B,EAC/B,gCAAgC,CACjC,iBACW,gCAAgC,EAC5C,KAAK,EAAE,SAAS,CAAC,eAAe,CAAC,EACjC,OAAO,EAAE,KAAK,CAAC,QAAQ;YAGvB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,SAAS,OAAG,GAAI,CAC1B,CACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./PopupButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonDivProps, CommonProps } from \"@itwin/core-react\";\nimport { Div, Icon, Popup } from \"@itwin/core-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport {\n SvgCheckmark,\n SvgChevronDown,\n SvgRemove,\n} from \"@itwin/itwinui-icons-react\";\nimport { useTranslation } from \"../l10n/useTranslation.js\";\n\n/** Properties for [[PopupButton]] component\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport interface PopupButtonProps extends CommonProps {\n /** Label to display in click area. */\n label?: string | React.ReactNode;\n /* Placeholder text used when there is no label yet */\n placeholder?: string;\n /** Contents of the popup */\n children: React.ReactNode;\n /** Title to display as tooltip. */\n title?: string;\n\n /** Set focus to popup - default is to set focus */\n moveFocus?: boolean;\n /** Element to receive focus, specified by React.RefObject or CSS selector string. If undefined and moveFocus is true then focus is moved to first focusable element. */\n focusTarget?: React.RefObject<HTMLElement | null> | string;\n\n /** Show or hide the box shadow (defaults to false) */\n showShadow?: boolean;\n /** Show or hide the arrow (defaults to false) */\n showArrow?: boolean;\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n /** Indicates whether to close the popup when Enter is pressed (defaults to true) */\n closeOnEnter?: boolean;\n /** Disabled or not */\n disabled?: boolean;\n /** Readonly or not */\n readonly?: boolean;\n\n /** Listens for click events on button area */\n onClick?: (event: React.MouseEvent) => void;\n /** Listens for popup close events */\n onClose?: () => void;\n /** Listens for Enter key in popup */\n onEnter?: () => void;\n}\n\n/** @internal */\ninterface PopupButtonState {\n showPopup: boolean;\n}\n\n/** PopupButton React component that is a button and property editor popup host\n * @alpha\n */\nexport class PopupButton extends React.PureComponent<\n PopupButtonProps,\n PopupButtonState\n> {\n private _buttonRef = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<PopupButtonState> = {\n showPopup: false,\n };\n\n public override componentDidMount() {\n if (this.props.setFocus && this._buttonRef.current)\n this._buttonRef.current.focus();\n }\n\n private _togglePopup = (event: React.MouseEvent) => {\n if (this.props.readonly || this.props.disabled) return;\n\n this.setState(\n (prevState) => ({ showPopup: !prevState.showPopup }),\n () => this.props.onClick && this.props.onClick(event)\n );\n };\n\n public closePopup() {\n this._closePopup();\n }\n\n private _closePopup = () => {\n this.setState({ showPopup: false }, () => {\n this.props.onClose && this.props.onClose();\n\n if (this._buttonRef.current) this._buttonRef.current.focus();\n });\n };\n\n private _handleKeyDown = (event: React.KeyboardEvent) => {\n if (\n (event.key === Key.ArrowDown.valueOf() ||\n event.key === \" \" ||\n event.key === Key.Enter.valueOf()) &&\n !this.state.showPopup\n ) {\n event.preventDefault();\n event.stopPropagation();\n this.setState({ showPopup: true });\n }\n };\n\n public override render(): React.ReactNode {\n const showArrow = this.props.showArrow ?? false;\n const showShadow = this.props.showShadow ?? false;\n const moveFocus = this.props.moveFocus ?? true;\n const showPlaceholder =\n this.props.label === undefined && this.props.placeholder !== undefined;\n\n const classNames = classnames(\n \"components-popup-button\",\n this.state.showPopup && \"components-popup-expanded\",\n this.props.readonly && \"components-readonly\",\n this.props.disabled && \"components-disabled\"\n );\n\n const valueClassNames = classnames(\n \"components-popup-button-value\",\n showPlaceholder && \"components-popup-button-placeholder\"\n );\n\n return (\n <div className={this.props.className}>\n <div\n className={classNames}\n onClick={this._togglePopup}\n onKeyDown={this._handleKeyDown}\n data-testid=\"components-popup-button\"\n tabIndex={0}\n ref={this._buttonRef}\n title={this.props.title}\n aria-disabled={this.props.disabled}\n role=\"button\"\n >\n <div className={valueClassNames}>\n {this.props.label || this.props.placeholder}\n </div>\n <div className={\"components-popup-button-arrow\"}>\n <div\n className={classnames(\n \"components-popup-button-arrow-icon\",\n \"icon\"\n )}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon iconSpec={<SvgChevronDown />} />\n </div>\n </div>\n </div>\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Popup\n className=\"components-popup-button-popup\"\n isOpen={this.state.showPopup}\n position={RelativePosition.Bottom}\n onClose={this._closePopup}\n onEnter={this.props.onEnter}\n closeOnEnter={this.props.closeOnEnter}\n target={this._buttonRef.current}\n showArrow={showArrow}\n showShadow={showShadow}\n moveFocus={moveFocus}\n focusTarget={this.props.focusTarget}\n portalTarget={\n this._buttonRef.current?.ownerDocument.querySelector(\n \".uifw-configurableui-portalContainer\"\n ) ?? undefined\n }\n >\n {this.props.children}\n </Popup>\n </div>\n );\n }\n}\n\n/** Popup content with padding\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function PopupContent(props: CommonDivProps) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return <Div {...props} mainClassName=\"components-editor-popup-content\" />;\n}\n\n/** Properties for [[PopupOkCancelButtons]] component\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof PopupOkCancelButtons>`\n */\nexport interface OkCancelProps {\n onOk: (event: React.MouseEvent) => void;\n onCancel: (event: React.MouseEvent) => void;\n}\n\n/** OK/Cancel Buttons\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function PopupOkCancelButtons(props: OkCancelProps) {\n const { translate } = useTranslation();\n return (\n <div className=\"components-popup-bottom-buttons\">\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-ok-button\"\n )}\n data-testid=\"components-popup-ok-button\"\n styleType=\"cta\"\n title={translate(\"dialog.ok\")}\n onClick={props.onOk}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon iconSpec={<SvgCheckmark />} />\n </Button>\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-cancel-button\"\n )}\n data-testid=\"components-popup-cancel-button\"\n title={translate(\"dialog.cancel\")}\n onClick={props.onCancel}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon iconSpec={<SvgRemove />} />\n </Button>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PopupButton.js","sourceRoot":"","sources":["../../../src/components-react/editors/PopupButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,SAAS,GACV,M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AAa,EAAC,iCAAiC,GAAG,CAAC;AAC5E,CAAC;AAWD;;GAEG;AACH,4DAA4D;AAC5D,MAAM,UAAU,oBAAoB,CAAC,KAAoB;IACvD,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,EAAE,CAAC;IACvC,OAAO,CACL,6BAAK,SAAS,EAAC,iCAAiC;QAC9C,oBAAC,MAAM,IACL,SAAS,EAAE,UAAU,CACnB,+BAA+B,EAC/B,4BAA4B,CAC7B,iBACW,4BAA4B,EACxC,SAAS,EAAC,KAAK,EACf,KAAK,EAAE,SAAS,CAAC,WAAW,CAAC,EAC7B,OAAO,EAAE,KAAK,CAAC,IAAI;YAGnB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,YAAY,OAAG,GAAI,CAC7B;QACT,oBAAC,MAAM,IACL,SAAS,EAAE,UAAU,CACnB,+BAA+B,EAC/B,gCAAgC,CACjC,iBACW,gCAAgC,EAC5C,KAAK,EAAE,SAAS,CAAC,eAAe,CAAC,EACjC,OAAO,EAAE,KAAK,CAAC,QAAQ;YAGvB,oBAAC,IAAI,IAAC,QAAQ,EAAE,oBAAC,SAAS,OAAG,GAAI,CAC1B,CACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./PopupButton.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonDivProps, CommonProps } from \"@itwin/core-react\";\nimport { Div, Icon, Popup } from \"@itwin/core-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport {\n SvgCheckmark,\n SvgChevronDown,\n SvgRemove,\n} from \"@itwin/itwinui-icons-react\";\nimport { useTranslation } from \"../l10n/useTranslation.js\";\n\n/** Properties for [[PopupButton]] component\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport interface PopupButtonProps extends CommonProps {\n /** Label to display in click area. */\n label?: string | React.ReactNode;\n /* Placeholder text used when there is no label yet */\n placeholder?: string;\n /** Contents of the popup */\n children: React.ReactNode;\n /** Title to display as tooltip. */\n title?: string;\n\n /** Set focus to popup - default is to set focus */\n moveFocus?: boolean;\n /** Element to receive focus, specified by React.RefObject or CSS selector string. If undefined and moveFocus is true then focus is moved to first focusable element. */\n focusTarget?: React.RefObject<HTMLElement | null> | string;\n\n /** Show or hide the box shadow (defaults to false) */\n showShadow?: boolean;\n /** Show or hide the arrow (defaults to false) */\n showArrow?: boolean;\n /** Indicates whether to set focus to the input element */\n setFocus?: boolean;\n /** Indicates whether to close the popup when Enter is pressed (defaults to true) */\n closeOnEnter?: boolean;\n /** Disabled or not */\n disabled?: boolean;\n /** Readonly or not */\n readonly?: boolean;\n\n /** Listens for click events on button area */\n onClick?: (event: React.MouseEvent) => void;\n /** Listens for popup close events */\n onClose?: () => void;\n /** Listens for Enter key in popup */\n onEnter?: () => void;\n}\n\n/** @internal */\ninterface PopupButtonState {\n showPopup: boolean;\n}\n\n/** PopupButton React component that is a button and property editor popup host\n * @alpha\n */\nexport class PopupButton extends React.PureComponent<\n PopupButtonProps,\n PopupButtonState\n> {\n private _buttonRef = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<PopupButtonState> = {\n showPopup: false,\n };\n\n public override componentDidMount() {\n if (this.props.setFocus && this._buttonRef.current)\n this._buttonRef.current.focus();\n }\n\n private _togglePopup = (event: React.MouseEvent) => {\n if (this.props.readonly || this.props.disabled) return;\n\n this.setState(\n (prevState) => ({ showPopup: !prevState.showPopup }),\n () => this.props.onClick && this.props.onClick(event)\n );\n };\n\n public closePopup() {\n this._closePopup();\n }\n\n private _closePopup = () => {\n this.setState({ showPopup: false }, () => {\n this.props.onClose && this.props.onClose();\n\n if (this._buttonRef.current) this._buttonRef.current.focus();\n });\n };\n\n private _handleKeyDown = (event: React.KeyboardEvent) => {\n if (\n (event.key === Key.ArrowDown.valueOf() ||\n event.key === \" \" ||\n event.key === Key.Enter.valueOf()) &&\n !this.state.showPopup\n ) {\n event.preventDefault();\n event.stopPropagation();\n this.setState({ showPopup: true });\n }\n };\n\n public override render(): React.ReactNode {\n const showArrow = this.props.showArrow ?? false;\n const showShadow = this.props.showShadow ?? false;\n const moveFocus = this.props.moveFocus ?? true;\n const showPlaceholder =\n this.props.label === undefined && this.props.placeholder !== undefined;\n\n const classNames = classnames(\n \"components-popup-button\",\n this.state.showPopup && \"components-popup-expanded\",\n this.props.readonly && \"components-readonly\",\n this.props.disabled && \"components-disabled\"\n );\n\n const valueClassNames = classnames(\n \"components-popup-button-value\",\n showPlaceholder && \"components-popup-button-placeholder\"\n );\n\n return (\n <div className={this.props.className}>\n <div\n className={classNames}\n onClick={this._togglePopup}\n onKeyDown={this._handleKeyDown}\n data-testid=\"components-popup-button\"\n tabIndex={0}\n ref={this._buttonRef}\n title={this.props.title}\n aria-disabled={this.props.disabled}\n role=\"button\"\n >\n <div className={valueClassNames}>\n {this.props.label || this.props.placeholder}\n </div>\n <div className={\"components-popup-button-arrow\"}>\n <div\n className={classnames(\n \"components-popup-button-arrow-icon\",\n \"icon\"\n )}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon iconSpec={<SvgChevronDown />} />\n </div>\n </div>\n </div>\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Popup\n className=\"components-popup-button-popup\"\n isOpen={this.state.showPopup}\n position={RelativePosition.Bottom}\n onClose={this._closePopup}\n onEnter={this.props.onEnter}\n closeOnEnter={this.props.closeOnEnter}\n target={this._buttonRef.current}\n showArrow={showArrow}\n showShadow={showShadow}\n moveFocus={moveFocus}\n focusTarget={this.props.focusTarget}\n portalTarget={\n this._buttonRef.current?.ownerDocument.querySelector(\n \".uifw-configurableui-portalContainer\"\n ) ?? undefined\n }\n >\n {this.props.children}\n </Popup>\n </div>\n );\n }\n}\n\n/** Popup content with padding\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function PopupContent(props: CommonDivProps) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return <Div {...props} mainClassName=\"components-editor-popup-content\" />;\n}\n\n/** Properties for [[PopupOkCancelButtons]] component\n * @alpha\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof PopupOkCancelButtons>`\n */\nexport interface OkCancelProps {\n onOk: (event: React.MouseEvent) => void;\n onCancel: (event: React.MouseEvent) => void;\n}\n\n/** OK/Cancel Buttons\n * @alpha\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function PopupOkCancelButtons(props: OkCancelProps) {\n const { translate } = useTranslation();\n return (\n <div className=\"components-popup-bottom-buttons\">\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-ok-button\"\n )}\n data-testid=\"components-popup-ok-button\"\n styleType=\"cta\"\n title={translate(\"dialog.ok\")}\n onClick={props.onOk}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon iconSpec={<SvgCheckmark />} />\n </Button>\n <Button\n className={classnames(\n \"components-popup-large-button\",\n \"components-popup-cancel-button\"\n )}\n data-testid=\"components-popup-cancel-button\"\n title={translate(\"dialog.cancel\")}\n onClick={props.onCancel}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Icon iconSpec={<SvgRemove />} />\n </Button>\n </div>\n );\n}\n"]}
|
|
@@ -11,9 +11,6 @@ import { TextEditor } from "./TextEditor.js";
|
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export class PropertyEditorBase {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.customDataController = undefined;
|
|
16
|
-
}
|
|
17
14
|
get containerHandlesBlur() {
|
|
18
15
|
return true;
|
|
19
16
|
}
|
|
@@ -29,6 +26,7 @@ export class PropertyEditorBase {
|
|
|
29
26
|
get containerStopsKeydownPropagation() {
|
|
30
27
|
return true;
|
|
31
28
|
}
|
|
29
|
+
customDataController = undefined;
|
|
32
30
|
applyEditorParams(_property, _record) { }
|
|
33
31
|
async commitValue(newValue, record) {
|
|
34
32
|
if (this.customDataController)
|
|
@@ -57,6 +55,7 @@ const editors = {};
|
|
|
57
55
|
* @public
|
|
58
56
|
*/
|
|
59
57
|
export class PropertyEditorManager {
|
|
58
|
+
static _dataControllers = {};
|
|
60
59
|
static registerEditor(editType, editor, editorName) {
|
|
61
60
|
const fullEditorName = getFullEditorName(editType, editorName);
|
|
62
61
|
if (editors.hasOwnProperty(fullEditorName)) {
|
|
@@ -101,7 +100,6 @@ export class PropertyEditorManager {
|
|
|
101
100
|
return editors.hasOwnProperty(fullEditorName);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
PropertyEditorManager._dataControllers = {};
|
|
105
103
|
/** Basic Property Editor registered for the "text" and "string" type names.
|
|
106
104
|
* It uses the [[TextEditor]] React component.
|
|
107
105
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyEditorManager.js","sourceRoot":"","sources":["../../../src/components-react/editors/PropertyEditorManager.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA0C7C;;GAEG;AACH,MAAM,OAAgB,kBAAkB;IAAxC;QAiBS,yBAAoB,GAA+B,SAAS,CAAC;IA4BtE,CAAC;IA5CC,IAAW,oBAAoB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,qBAAqB;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,gCAAgC;QACzC,OAAO,IAAI,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,kBAAkB,CAAC,EAAE,CAAC;;gBAEnE,MAAM,KAAK,CACT,8DAA8D,kBAAkB,qBAAqB,CACtG,CAAC;QACN,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,eAAe,CAAC,QAAgB,EAAE,UAAkB;QAChE,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC/D,OAAO,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;;AAzEc,sCAAgB,GAE3B,EAAE,CAAC;AA0ET;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAAgB,EAAE,UAAmB;IAC9D,IAAI,cAAc,GAAG,QAAQ,CAAC;IAC9B,IAAI,UAAU;QAAE,cAAc,IAAI,IAAI,UAAU,EAAE,CAAC;IACnD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,QAAgB,EAChB,MAAoC,EACpC,UAAmB,EACnB,QAAQ,GAAG,KAAK;IAEhB,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE/D,yDAAyD;IACzD,IAAI,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEhE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC;AACnC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport * as React from \"react\";\nimport { TextEditor } from \"./TextEditor.js\";\nimport type {\n DisplayMessageType,\n MessageSeverity,\n PropertyDescription,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\n\n/** Asynchronous Error Message returned as part of [[AsyncValueProcessingResult]]\n * @public\n */\nexport interface AsyncErrorMessage {\n severity: MessageSeverity;\n briefMessage: string;\n detailedMessage?: string;\n messageType?: DisplayMessageType;\n}\n\n/** Asynchronous Value Process Result\n * @public\n */\nexport interface AsyncValueProcessingResult {\n encounteredError: boolean;\n returnValue?: PropertyValue;\n errorMessage?: AsyncErrorMessage;\n}\n\n/** DataControllers can be implemented per typename to validate and commit values.\n * @public\n */\nexport interface DataController {\n validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n}\n\n/** PropertyEditor is the base class for all property editors.\n * @public\n */\nexport abstract class PropertyEditorBase implements DataController {\n public get containerHandlesBlur(): boolean {\n return true;\n }\n public get containerHandlesEscape(): boolean {\n return true;\n }\n public get containerHandlesEnter(): boolean {\n return true;\n }\n public get containerHandlesTab(): boolean {\n return true;\n }\n public get containerStopsKeydownPropagation(): boolean {\n return true;\n }\n\n public customDataController: DataController | undefined = undefined;\n\n public abstract get reactNode(): React.ReactNode;\n\n public applyEditorParams(\n _property: PropertyDescription,\n _record: PropertyRecord\n ): void {}\n\n public async commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.commitValue(newValue, record);\n\n return { encounteredError: false };\n }\n\n public async validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.validateValue(newValue, record);\n\n return { encounteredError: false };\n }\n}\n\n/** DataControllerBase is the base class for all Data Controllers.\n * @public\n */\nexport abstract class DataControllerBase implements DataController {\n public async commitValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n\n public async validateValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n}\n\nconst editors: { [index: string]: new () => PropertyEditorBase } = {};\n\n/** Manages Property Editors. Property Editors are registered with and created by the manager.\n * @public\n */\nexport class PropertyEditorManager {\n private static _dataControllers: {\n [index: string]: new () => DataControllerBase;\n } = {};\n\n public static registerEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string\n ): void {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n if (editors.hasOwnProperty(fullEditorName)) {\n const nameOfEditor = editors[fullEditorName].name;\n throw Error(\n `PropertyEditorManager.registerEditor error: type '${fullEditorName}' already registered to '${nameOfEditor}'`\n );\n }\n editors[fullEditorName] = editor;\n }\n\n public static registerDataController(\n controllerName: string,\n controller: new () => DataControllerBase\n ): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n throw Error(\n `PropertyEditorManager.registerDataController error: type '${controllerName}' already registered to '${(typeof PropertyEditorManager\n ._dataControllers[controllerName]).toString()}'`\n );\n }\n PropertyEditorManager._dataControllers[controllerName] = controller;\n }\n\n /** @internal */\n public static deregisterDataController(controllerName: string): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n delete PropertyEditorManager._dataControllers[controllerName];\n }\n }\n\n public static createEditor(\n editType: string,\n editorName?: string,\n dataControllerName?: string\n ): PropertyEditorBase {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n let editor: PropertyEditorBase;\n if (editors.hasOwnProperty(fullEditorName))\n editor = new editors[fullEditorName]();\n else if (editors.hasOwnProperty(editType)) editor = new editors[editType]();\n else editor = new BasicPropertyEditor();\n\n if (dataControllerName) {\n if (\n PropertyEditorManager._dataControllers.hasOwnProperty(\n dataControllerName\n )\n )\n editor.customDataController =\n new PropertyEditorManager._dataControllers[dataControllerName]();\n else\n throw Error(\n `PropertyEditorManager.createEditor error: data controller '${dataControllerName}' is not registered`\n );\n }\n\n return editor;\n }\n\n public static hasCustomEditor(editType: string, editorName: string): boolean {\n const fullEditorName = getFullEditorName(editType, editorName);\n return editors.hasOwnProperty(fullEditorName);\n }\n}\n\n/** Basic Property Editor registered for the \"text\" and \"string\" type names.\n * It uses the [[TextEditor]] React component.\n * @public\n */\nexport class BasicPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <TextEditor />;\n }\n}\n\nfunction getFullEditorName(editType: string, editorName?: string) {\n let fullEditorName = editType;\n if (editorName) fullEditorName += `:${editorName}`;\n return fullEditorName;\n}\n\n/** Used to override the default property editors from the `appui-react` package.\n * @internal\n */\nexport function registerDefaultPropertyEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string,\n override = false\n) {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n // Ignore if already registered and override is disabled.\n if (editors.hasOwnProperty(fullEditorName) && !override) return;\n\n editors[fullEditorName] = editor;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PropertyEditorManager.js","sourceRoot":"","sources":["../../../src/components-react/editors/PropertyEditorManager.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA0C7C;;GAEG;AACH,MAAM,OAAgB,kBAAkB;IACtC,IAAW,oBAAoB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,qBAAqB;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,mBAAmB;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAW,gCAAgC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,oBAAoB,GAA+B,SAAS,CAAC;IAI7D,iBAAiB,CACtB,SAA8B,EAC9B,O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,CAAC,EAAE,CAAC;;gBAEnE,MAAM,KAAK,CACT,8DAA8D,kBAAkB,qBAAqB,CACtG,CAAC;QACN,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,eAAe,CAAC,QAAgB,EAAE,UAAkB;QAChE,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC/D,OAAO,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;;AAGH;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS;QAClB,OAAO,oBAAC,UAAU,OAAG,CAAC;IACxB,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAAgB,EAAE,UAAmB;IAC9D,IAAI,cAAc,GAAG,QAAQ,CAAC;IAC9B,IAAI,UAAU;QAAE,cAAc,IAAI,IAAI,UAAU,EAAE,CAAC;IACnD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,QAAgB,EAChB,MAAoC,EACpC,UAAmB,EACnB,QAAQ,GAAG,KAAK;IAEhB,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE/D,yDAAyD;IACzD,IAAI,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEhE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC;AACnC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport * as React from \"react\";\nimport { TextEditor } from \"./TextEditor.js\";\nimport type {\n DisplayMessageType,\n MessageSeverity,\n PropertyDescription,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\n\n/** Asynchronous Error Message returned as part of [[AsyncValueProcessingResult]]\n * @public\n */\nexport interface AsyncErrorMessage {\n severity: MessageSeverity;\n briefMessage: string;\n detailedMessage?: string;\n messageType?: DisplayMessageType;\n}\n\n/** Asynchronous Value Process Result\n * @public\n */\nexport interface AsyncValueProcessingResult {\n encounteredError: boolean;\n returnValue?: PropertyValue;\n errorMessage?: AsyncErrorMessage;\n}\n\n/** DataControllers can be implemented per typename to validate and commit values.\n * @public\n */\nexport interface DataController {\n validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult>;\n}\n\n/** PropertyEditor is the base class for all property editors.\n * @public\n */\nexport abstract class PropertyEditorBase implements DataController {\n public get containerHandlesBlur(): boolean {\n return true;\n }\n public get containerHandlesEscape(): boolean {\n return true;\n }\n public get containerHandlesEnter(): boolean {\n return true;\n }\n public get containerHandlesTab(): boolean {\n return true;\n }\n public get containerStopsKeydownPropagation(): boolean {\n return true;\n }\n\n public customDataController: DataController | undefined = undefined;\n\n public abstract get reactNode(): React.ReactNode;\n\n public applyEditorParams(\n _property: PropertyDescription,\n _record: PropertyRecord\n ): void {}\n\n public async commitValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.commitValue(newValue, record);\n\n return { encounteredError: false };\n }\n\n public async validateValue(\n newValue: PropertyValue,\n record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n if (this.customDataController)\n return this.customDataController.validateValue(newValue, record);\n\n return { encounteredError: false };\n }\n}\n\n/** DataControllerBase is the base class for all Data Controllers.\n * @public\n */\nexport abstract class DataControllerBase implements DataController {\n public async commitValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n\n public async validateValue(\n _newValue: PropertyValue,\n _record: PropertyRecord\n ): Promise<AsyncValueProcessingResult> {\n return { encounteredError: false };\n }\n}\n\nconst editors: { [index: string]: new () => PropertyEditorBase } = {};\n\n/** Manages Property Editors. Property Editors are registered with and created by the manager.\n * @public\n */\nexport class PropertyEditorManager {\n private static _dataControllers: {\n [index: string]: new () => DataControllerBase;\n } = {};\n\n public static registerEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string\n ): void {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n if (editors.hasOwnProperty(fullEditorName)) {\n const nameOfEditor = editors[fullEditorName].name;\n throw Error(\n `PropertyEditorManager.registerEditor error: type '${fullEditorName}' already registered to '${nameOfEditor}'`\n );\n }\n editors[fullEditorName] = editor;\n }\n\n public static registerDataController(\n controllerName: string,\n controller: new () => DataControllerBase\n ): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n throw Error(\n `PropertyEditorManager.registerDataController error: type '${controllerName}' already registered to '${(typeof PropertyEditorManager\n ._dataControllers[controllerName]).toString()}'`\n );\n }\n PropertyEditorManager._dataControllers[controllerName] = controller;\n }\n\n /** @internal */\n public static deregisterDataController(controllerName: string): void {\n if (PropertyEditorManager._dataControllers.hasOwnProperty(controllerName)) {\n delete PropertyEditorManager._dataControllers[controllerName];\n }\n }\n\n public static createEditor(\n editType: string,\n editorName?: string,\n dataControllerName?: string\n ): PropertyEditorBase {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n let editor: PropertyEditorBase;\n if (editors.hasOwnProperty(fullEditorName))\n editor = new editors[fullEditorName]();\n else if (editors.hasOwnProperty(editType)) editor = new editors[editType]();\n else editor = new BasicPropertyEditor();\n\n if (dataControllerName) {\n if (\n PropertyEditorManager._dataControllers.hasOwnProperty(\n dataControllerName\n )\n )\n editor.customDataController =\n new PropertyEditorManager._dataControllers[dataControllerName]();\n else\n throw Error(\n `PropertyEditorManager.createEditor error: data controller '${dataControllerName}' is not registered`\n );\n }\n\n return editor;\n }\n\n public static hasCustomEditor(editType: string, editorName: string): boolean {\n const fullEditorName = getFullEditorName(editType, editorName);\n return editors.hasOwnProperty(fullEditorName);\n }\n}\n\n/** Basic Property Editor registered for the \"text\" and \"string\" type names.\n * It uses the [[TextEditor]] React component.\n * @public\n */\nexport class BasicPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <TextEditor />;\n }\n}\n\nfunction getFullEditorName(editType: string, editorName?: string) {\n let fullEditorName = editType;\n if (editorName) fullEditorName += `:${editorName}`;\n return fullEditorName;\n}\n\n/** Used to override the default property editors from the `appui-react` package.\n * @internal\n */\nexport function registerDefaultPropertyEditor(\n editType: string,\n editor: new () => PropertyEditorBase,\n editorName?: string,\n override = false\n) {\n const fullEditorName = getFullEditorName(editType, editorName);\n\n // Ignore if already registered and override is disabled.\n if (editors.hasOwnProperty(fullEditorName) && !override) return;\n\n editors[fullEditorName] = editor;\n}\n"]}
|
|
@@ -17,74 +17,14 @@ import { PopupButton, PopupContent, PopupOkCancelButtons, } from "./PopupButton.
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export class SliderEditor extends React.PureComponent {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
max: 100,
|
|
29
|
-
};
|
|
30
|
-
this._handleChange = (values) => {
|
|
31
|
-
const newValue = values[0];
|
|
32
|
-
if (this._isMounted)
|
|
33
|
-
this.setState({
|
|
34
|
-
value: newValue,
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
this.internalFormatTooltip = (value, step = 1) => {
|
|
38
|
-
if (Number.isInteger(step))
|
|
39
|
-
return value.toFixed(0);
|
|
40
|
-
const stepString = step.toString();
|
|
41
|
-
const decimalIndex = stepString.indexOf(".");
|
|
42
|
-
const numDecimals = step.toString().length - (decimalIndex + 1);
|
|
43
|
-
return value.toFixed(numDecimals);
|
|
44
|
-
};
|
|
45
|
-
this._handleEnter = async () => {
|
|
46
|
-
this._enterKey = true;
|
|
47
|
-
await this._handleCommit();
|
|
48
|
-
};
|
|
49
|
-
this._handleClose = async () => {
|
|
50
|
-
if (this._enterKey) {
|
|
51
|
-
this._enterKey = false;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
if (this.props.onCancel)
|
|
55
|
-
this.props.onCancel();
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
this._handleOk = async (_event) => {
|
|
59
|
-
await this._handleCommit();
|
|
60
|
-
};
|
|
61
|
-
this._handleCancel = (_event) => {
|
|
62
|
-
if (this.props.onCancel) {
|
|
63
|
-
this.props.onCancel();
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
this._handleCommit = async () => {
|
|
67
|
-
if (this.props.propertyRecord && this.props.onCommit) {
|
|
68
|
-
const propertyValue = await this.getPropertyValue();
|
|
69
|
-
if (propertyValue !== undefined) {
|
|
70
|
-
this.props.onCommit({
|
|
71
|
-
propertyRecord: this.props.propertyRecord,
|
|
72
|
-
newValue: propertyValue,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
this.tooltipProps = (_index, val) => {
|
|
78
|
-
const content = this.state.formatTooltip
|
|
79
|
-
? this.state.formatTooltip(val)
|
|
80
|
-
: this.internalFormatTooltip(val, this.state.step);
|
|
81
|
-
return {
|
|
82
|
-
placement: this.state.tooltipBelow ? "bottom" : "top",
|
|
83
|
-
content,
|
|
84
|
-
visible: this.state.showTooltip,
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
}
|
|
20
|
+
_isMounted = false;
|
|
21
|
+
_enterKey = false;
|
|
22
|
+
_divElement = React.createRef();
|
|
23
|
+
state = {
|
|
24
|
+
value: 0,
|
|
25
|
+
min: 0,
|
|
26
|
+
max: 100,
|
|
27
|
+
};
|
|
88
28
|
async getPropertyValue() {
|
|
89
29
|
const record = this.props.propertyRecord;
|
|
90
30
|
let propertyValue;
|
|
@@ -106,6 +46,13 @@ export class SliderEditor extends React.PureComponent {
|
|
|
106
46
|
containsFocus = this.htmlElement.contains(document.activeElement);
|
|
107
47
|
return containsFocus;
|
|
108
48
|
}
|
|
49
|
+
_handleChange = (values) => {
|
|
50
|
+
const newValue = values[0];
|
|
51
|
+
if (this._isMounted)
|
|
52
|
+
this.setState({
|
|
53
|
+
value: newValue,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
109
56
|
componentDidMount() {
|
|
110
57
|
this._isMounted = true;
|
|
111
58
|
void this.setStateFromProps();
|
|
@@ -119,6 +66,14 @@ export class SliderEditor extends React.PureComponent {
|
|
|
119
66
|
void this.setStateFromProps();
|
|
120
67
|
}
|
|
121
68
|
}
|
|
69
|
+
internalFormatTooltip = (value, step = 1) => {
|
|
70
|
+
if (Number.isInteger(step))
|
|
71
|
+
return value.toFixed(0);
|
|
72
|
+
const stepString = step.toString();
|
|
73
|
+
const decimalIndex = stepString.indexOf(".");
|
|
74
|
+
const numDecimals = step.toString().length - (decimalIndex + 1);
|
|
75
|
+
return value.toFixed(numDecimals);
|
|
76
|
+
};
|
|
122
77
|
async setStateFromProps() {
|
|
123
78
|
const record = this.props.propertyRecord;
|
|
124
79
|
let initialValue = 0;
|
|
@@ -206,6 +161,48 @@ export class SliderEditor extends React.PureComponent {
|
|
|
206
161
|
thumbMode,
|
|
207
162
|
});
|
|
208
163
|
}
|
|
164
|
+
_handleEnter = async () => {
|
|
165
|
+
this._enterKey = true;
|
|
166
|
+
await this._handleCommit();
|
|
167
|
+
};
|
|
168
|
+
_handleClose = async () => {
|
|
169
|
+
if (this._enterKey) {
|
|
170
|
+
this._enterKey = false;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
if (this.props.onCancel)
|
|
174
|
+
this.props.onCancel();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
_handleOk = async (_event) => {
|
|
178
|
+
await this._handleCommit();
|
|
179
|
+
};
|
|
180
|
+
_handleCancel = (_event) => {
|
|
181
|
+
if (this.props.onCancel) {
|
|
182
|
+
this.props.onCancel();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
_handleCommit = async () => {
|
|
186
|
+
if (this.props.propertyRecord && this.props.onCommit) {
|
|
187
|
+
const propertyValue = await this.getPropertyValue();
|
|
188
|
+
if (propertyValue !== undefined) {
|
|
189
|
+
this.props.onCommit({
|
|
190
|
+
propertyRecord: this.props.propertyRecord,
|
|
191
|
+
newValue: propertyValue,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
tooltipProps = (_index, val) => {
|
|
197
|
+
const content = this.state.formatTooltip
|
|
198
|
+
? this.state.formatTooltip(val)
|
|
199
|
+
: this.internalFormatTooltip(val, this.state.step);
|
|
200
|
+
return {
|
|
201
|
+
placement: this.state.tooltipBelow ? "bottom" : "top",
|
|
202
|
+
content,
|
|
203
|
+
visible: this.state.showTooltip,
|
|
204
|
+
};
|
|
205
|
+
};
|
|
209
206
|
render() {
|
|
210
207
|
const className = classnames("components-cell-editor", "components-slider-editor", this.props.className);
|
|
211
208
|
const minSize = this.state.size ? this.state.size : 100;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliderEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/SliderEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EACL,WAAW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CAAC,cAAc,EAAE,UAAU,EAC/C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,UAAU;gBAE/C,oBAAC,YAAY;oBACV,YAAY;oBACb,oBAAC,oBAAoB,IACnB,IAAI,EAAE,IAAI,CAAC,SAAS,EACpB,QAAQ,EAAE,IAAI,CAAC,aAAa,GAC5B,CACW,CACH,CACV,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1D,IAAW,SAAS;QAClB,OAAO,oBAAC,YAAY,OAAG,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./SliderEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n PropertyEditorParams,\n PropertyValue,\n SliderEditorParams,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon } from \"@itwin/core-react\";\nimport type { Tooltip } from \"@itwin/itwinui-react\";\nimport { Slider } from \"@itwin/itwinui-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport {\n PopupButton,\n PopupContent,\n PopupOkCancelButtons,\n} from \"./PopupButton.js\";\n\ntype TooltipProps = React.ComponentPropsWithoutRef<typeof Tooltip>;\n\n/** @internal */\ninterface SliderEditorState {\n value: number;\n min: number;\n max: number;\n size?: number;\n step?: number;\n showTooltip?: boolean;\n tooltipBelow?: boolean;\n formatTooltip?: (value: number) => string;\n thumbMode?: \"allow-crossing\" | \"inhibit-crossing\";\n trackDisplayMode?: \"auto\" | \"none\" | \"odd-segments\" | \"even-segments\";\n minLabel?: React.ReactNode;\n maxLabel?: React.ReactNode;\n tickLabels?: React.ReactNode;\n}\n\n/** SliderEditor React component that is a property editor with numeric input & up/down buttons\n * @public\n */\nexport class SliderEditor\n extends React.PureComponent<PropertyEditorProps, SliderEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _enterKey = false;\n private _divElement = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<SliderEditorState> = {\n value: 0,\n min: 0,\n max: 100,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.value,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this.htmlElement)\n containsFocus = this.htmlElement.contains(document.activeElement);\n return containsFocus;\n }\n\n private _handleChange = (values: readonly number[]): void => {\n const newValue = values[0];\n\n if (this._isMounted)\n this.setState({\n value: newValue,\n });\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private internalFormatTooltip = (value: number, step = 1) => {\n if (Number.isInteger(step)) return value.toFixed(0);\n\n const stepString = step.toString();\n const decimalIndex = stepString.indexOf(\".\");\n const numDecimals = step.toString().length - (decimalIndex + 1);\n return value.toFixed(numDecimals);\n };\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n let size: number | undefined;\n let min = 0;\n let max = 100;\n let step: number | undefined;\n let showTooltip: boolean | undefined;\n let tooltipBelow: boolean | undefined;\n let formatTooltip: ((value: number) => string) | undefined;\n let tickLabels: string[] | undefined;\n let minLabel: React.ReactNode | undefined;\n let maxLabel: React.ReactNode | undefined;\n let trackDisplayMode:\n | \"auto\"\n | \"none\"\n | \"odd-segments\"\n | \"even-segments\"\n | undefined;\n let thumbMode: \"allow-crossing\" | \"inhibit-crossing\" | undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const sliderParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Slider.valueOf()\n ) as SliderEditorParams;\n if (sliderParams) {\n min = sliderParams.minimum;\n max = sliderParams.maximum;\n size = sliderParams.size;\n step = sliderParams.step;\n thumbMode =\n 1 === sliderParams.mode ? \"allow-crossing\" : \"inhibit-crossing\";\n trackDisplayMode = !sliderParams.reversed ? \"auto\" : \"odd-segments\";\n showTooltip = sliderParams.showTooltip;\n tooltipBelow = sliderParams.tooltipBelow;\n formatTooltip = sliderParams.formatTooltip;\n\n minLabel = !sliderParams.showMinMax ? (\n \"\"\n ) : sliderParams.minIconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={sliderParams.minIconSpec} />\n ) : undefined;\n maxLabel = !sliderParams.showMinMax ? (\n \"\"\n ) : sliderParams.maxIconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={sliderParams.maxIconSpec} />\n ) : undefined;\n\n if (sliderParams.showTicks) {\n const count = sliderParams.getTickCount\n ? sliderParams.getTickCount()\n : 0;\n if (count) {\n tickLabels = [];\n const increment = (max - min) / count;\n for (let i = 0; i <= count; i++) {\n const value = i * increment + min;\n if (sliderParams.showTickLabels) {\n const label = sliderParams.formatTick\n ? sliderParams.formatTick(value)\n : this.internalFormatTooltip(value, step);\n tickLabels.push(label);\n } else {\n tickLabels.push(\"\");\n }\n }\n } else if (sliderParams.getTickValues) {\n tickLabels = sliderParams\n .getTickValues()\n .map((val: number) =>\n sliderParams.formatTick\n ? sliderParams.formatTick(val)\n : this.internalFormatTooltip(val, step)\n );\n }\n }\n }\n }\n\n if (this._isMounted)\n this.setState({\n value: initialValue,\n size,\n min,\n max,\n step,\n trackDisplayMode,\n showTooltip,\n tooltipBelow,\n formatTooltip,\n minLabel,\n maxLabel,\n tickLabels,\n thumbMode,\n });\n }\n\n private _handleEnter = async (): Promise<void> => {\n this._enterKey = true;\n await this._handleCommit();\n };\n\n private _handleClose = async (): Promise<void> => {\n if (this._enterKey) {\n this._enterKey = false;\n } else {\n if (this.props.onCancel) this.props.onCancel();\n }\n };\n\n private _handleOk = async (_event: React.MouseEvent): Promise<void> => {\n await this._handleCommit();\n };\n\n private _handleCancel = (_event: React.MouseEvent): void => {\n if (this.props.onCancel) {\n this.props.onCancel();\n }\n };\n\n private _handleCommit = async (): Promise<void> => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n };\n\n private tooltipProps = (_index: number, val: number) => {\n const content = this.state.formatTooltip\n ? this.state.formatTooltip(val)\n : this.internalFormatTooltip(val, this.state.step);\n return {\n placement: this.state.tooltipBelow ? \"bottom\" : \"top\",\n content,\n visible: this.state.showTooltip,\n } as Partial<Omit<TooltipProps, \"children\">>;\n };\n\n public override render(): React.ReactNode {\n const className = classnames(\n \"components-cell-editor\",\n \"components-slider-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 100;\n const style: React.CSSProperties = {\n ...this.props.style,\n minWidth: `${minSize}px`,\n };\n\n const tickProps = {\n \"data-testid\": \"components-tick\",\n } as React.ComponentProps<\"span\">;\n const popupContent = (\n <Slider\n className=\"components-slider-editor-slider\"\n style={style}\n values={[this.state.value]}\n min={this.state.min}\n max={this.state.max}\n step={this.state.step}\n thumbMode={this.state.thumbMode}\n trackDisplayMode={this.state.trackDisplayMode}\n disabled={this.props.propertyRecord?.isDisabled}\n minLabel={this.state.minLabel}\n maxLabel={this.state.maxLabel}\n tooltipProps={this.tooltipProps}\n tickLabels={this.state.tickLabels}\n tickProps={tickProps}\n onChange={this._handleChange}\n />\n );\n\n return (\n <div className={className} ref={this._divElement}>\n <PopupButton\n label={this.state.value}\n onClose={this._handleClose}\n onEnter={this._handleEnter}\n setFocus={this.props.setFocus}\n disabled={this.props.propertyRecord?.isDisabled}\n readonly={this.props.propertyRecord?.isReadonly}\n >\n <PopupContent>\n {popupContent}\n <PopupOkCancelButtons\n onOk={this._handleOk}\n onCancel={this._handleCancel}\n />\n </PopupContent>\n </PopupButton>\n </div>\n );\n }\n}\n\n/** Slider Property Editor registered for the \"number\" type name and \"slider\" editor name.\n * It uses the [[SliderEditor]] React component.\n * @public\n */\nexport class SliderPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <SliderEditor />;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SliderEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/SliderEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAqB1B;;GAEG;AACH,MAAM,OAAO,YACX,SAAQ,KAAK,CAAC,aAAqD;IAG3D,UAAU,GAAG,K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EAAE,IAAI,CAAC,aAAa,GAC5B,CACW,CACH,CACV,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1D,IAAW,SAAS;QAClB,OAAO,oBAAC,YAAY,OAAG,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./SliderEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n PropertyEditorParams,\n PropertyValue,\n SliderEditorParams,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon } from \"@itwin/core-react\";\nimport type { Tooltip } from \"@itwin/itwinui-react\";\nimport { Slider } from \"@itwin/itwinui-react\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport {\n PopupButton,\n PopupContent,\n PopupOkCancelButtons,\n} from \"./PopupButton.js\";\n\ntype TooltipProps = React.ComponentPropsWithoutRef<typeof Tooltip>;\n\n/** @internal */\ninterface SliderEditorState {\n value: number;\n min: number;\n max: number;\n size?: number;\n step?: number;\n showTooltip?: boolean;\n tooltipBelow?: boolean;\n formatTooltip?: (value: number) => string;\n thumbMode?: \"allow-crossing\" | \"inhibit-crossing\";\n trackDisplayMode?: \"auto\" | \"none\" | \"odd-segments\" | \"even-segments\";\n minLabel?: React.ReactNode;\n maxLabel?: React.ReactNode;\n tickLabels?: React.ReactNode;\n}\n\n/** SliderEditor React component that is a property editor with numeric input & up/down buttons\n * @public\n */\nexport class SliderEditor\n extends React.PureComponent<PropertyEditorProps, SliderEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _enterKey = false;\n private _divElement = React.createRef<HTMLDivElement>();\n\n public override readonly state: Readonly<SliderEditorState> = {\n value: 0,\n min: 0,\n max: 100,\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.value,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this.htmlElement)\n containsFocus = this.htmlElement.contains(document.activeElement);\n return containsFocus;\n }\n\n private _handleChange = (values: readonly number[]): void => {\n const newValue = values[0];\n\n if (this._isMounted)\n this.setState({\n value: newValue,\n });\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private internalFormatTooltip = (value: number, step = 1) => {\n if (Number.isInteger(step)) return value.toFixed(0);\n\n const stepString = step.toString();\n const decimalIndex = stepString.indexOf(\".\");\n const numDecimals = step.toString().length - (decimalIndex + 1);\n return value.toFixed(numDecimals);\n };\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n let size: number | undefined;\n let min = 0;\n let max = 100;\n let step: number | undefined;\n let showTooltip: boolean | undefined;\n let tooltipBelow: boolean | undefined;\n let formatTooltip: ((value: number) => string) | undefined;\n let tickLabels: string[] | undefined;\n let minLabel: React.ReactNode | undefined;\n let maxLabel: React.ReactNode | undefined;\n let trackDisplayMode:\n | \"auto\"\n | \"none\"\n | \"odd-segments\"\n | \"even-segments\"\n | undefined;\n let thumbMode: \"allow-crossing\" | \"inhibit-crossing\" | undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const sliderParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Slider.valueOf()\n ) as SliderEditorParams;\n if (sliderParams) {\n min = sliderParams.minimum;\n max = sliderParams.maximum;\n size = sliderParams.size;\n step = sliderParams.step;\n thumbMode =\n 1 === sliderParams.mode ? \"allow-crossing\" : \"inhibit-crossing\";\n trackDisplayMode = !sliderParams.reversed ? \"auto\" : \"odd-segments\";\n showTooltip = sliderParams.showTooltip;\n tooltipBelow = sliderParams.tooltipBelow;\n formatTooltip = sliderParams.formatTooltip;\n\n minLabel = !sliderParams.showMinMax ? (\n \"\"\n ) : sliderParams.minIconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={sliderParams.minIconSpec} />\n ) : undefined;\n maxLabel = !sliderParams.showMinMax ? (\n \"\"\n ) : sliderParams.maxIconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={sliderParams.maxIconSpec} />\n ) : undefined;\n\n if (sliderParams.showTicks) {\n const count = sliderParams.getTickCount\n ? sliderParams.getTickCount()\n : 0;\n if (count) {\n tickLabels = [];\n const increment = (max - min) / count;\n for (let i = 0; i <= count; i++) {\n const value = i * increment + min;\n if (sliderParams.showTickLabels) {\n const label = sliderParams.formatTick\n ? sliderParams.formatTick(value)\n : this.internalFormatTooltip(value, step);\n tickLabels.push(label);\n } else {\n tickLabels.push(\"\");\n }\n }\n } else if (sliderParams.getTickValues) {\n tickLabels = sliderParams\n .getTickValues()\n .map((val: number) =>\n sliderParams.formatTick\n ? sliderParams.formatTick(val)\n : this.internalFormatTooltip(val, step)\n );\n }\n }\n }\n }\n\n if (this._isMounted)\n this.setState({\n value: initialValue,\n size,\n min,\n max,\n step,\n trackDisplayMode,\n showTooltip,\n tooltipBelow,\n formatTooltip,\n minLabel,\n maxLabel,\n tickLabels,\n thumbMode,\n });\n }\n\n private _handleEnter = async (): Promise<void> => {\n this._enterKey = true;\n await this._handleCommit();\n };\n\n private _handleClose = async (): Promise<void> => {\n if (this._enterKey) {\n this._enterKey = false;\n } else {\n if (this.props.onCancel) this.props.onCancel();\n }\n };\n\n private _handleOk = async (_event: React.MouseEvent): Promise<void> => {\n await this._handleCommit();\n };\n\n private _handleCancel = (_event: React.MouseEvent): void => {\n if (this.props.onCancel) {\n this.props.onCancel();\n }\n };\n\n private _handleCommit = async (): Promise<void> => {\n if (this.props.propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue: propertyValue,\n });\n }\n }\n };\n\n private tooltipProps = (_index: number, val: number) => {\n const content = this.state.formatTooltip\n ? this.state.formatTooltip(val)\n : this.internalFormatTooltip(val, this.state.step);\n return {\n placement: this.state.tooltipBelow ? \"bottom\" : \"top\",\n content,\n visible: this.state.showTooltip,\n } as Partial<Omit<TooltipProps, \"children\">>;\n };\n\n public override render(): React.ReactNode {\n const className = classnames(\n \"components-cell-editor\",\n \"components-slider-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 100;\n const style: React.CSSProperties = {\n ...this.props.style,\n minWidth: `${minSize}px`,\n };\n\n const tickProps = {\n \"data-testid\": \"components-tick\",\n } as React.ComponentProps<\"span\">;\n const popupContent = (\n <Slider\n className=\"components-slider-editor-slider\"\n style={style}\n values={[this.state.value]}\n min={this.state.min}\n max={this.state.max}\n step={this.state.step}\n thumbMode={this.state.thumbMode}\n trackDisplayMode={this.state.trackDisplayMode}\n disabled={this.props.propertyRecord?.isDisabled}\n minLabel={this.state.minLabel}\n maxLabel={this.state.maxLabel}\n tooltipProps={this.tooltipProps}\n tickLabels={this.state.tickLabels}\n tickProps={tickProps}\n onChange={this._handleChange}\n />\n );\n\n return (\n <div className={className} ref={this._divElement}>\n <PopupButton\n label={this.state.value}\n onClose={this._handleClose}\n onEnter={this._handleEnter}\n setFocus={this.props.setFocus}\n disabled={this.props.propertyRecord?.isDisabled}\n readonly={this.props.propertyRecord?.isReadonly}\n >\n <PopupContent>\n {popupContent}\n <PopupOkCancelButtons\n onOk={this._handleOk}\n onCancel={this._handleCancel}\n />\n </PopupContent>\n </PopupButton>\n </div>\n );\n }\n}\n\n/** Slider Property Editor registered for the \"number\" type name and \"slider\" editor name.\n * It uses the [[SliderEditor]] React component.\n * @public\n */\nexport class SliderPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <SliderEditor />;\n }\n}\n"]}
|
|
@@ -17,31 +17,11 @@ import { UiComponents } from "../UiComponents.js";
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export class TextEditor extends React.PureComponent {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
inputValue: "",
|
|
26
|
-
};
|
|
27
|
-
this._updateInputValue = (e) => {
|
|
28
|
-
if (this._isMounted)
|
|
29
|
-
this.setState({
|
|
30
|
-
inputValue: e.target.value,
|
|
31
|
-
}, async () => {
|
|
32
|
-
if (this.props.shouldCommitOnChange &&
|
|
33
|
-
this.props.onCommit &&
|
|
34
|
-
this.props.propertyRecord) {
|
|
35
|
-
const newValue = await this.getPropertyValue();
|
|
36
|
-
if (newValue)
|
|
37
|
-
this.props.onCommit({
|
|
38
|
-
propertyRecord: this.props.propertyRecord,
|
|
39
|
-
newValue,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
}
|
|
20
|
+
_isMounted = false;
|
|
21
|
+
_inputElement = React.createRef();
|
|
22
|
+
state = {
|
|
23
|
+
inputValue: "",
|
|
24
|
+
};
|
|
45
25
|
async getPropertyValue() {
|
|
46
26
|
const record = this.props.propertyRecord;
|
|
47
27
|
let propertyValue;
|
|
@@ -57,6 +37,23 @@ export class TextEditor extends React.PureComponent {
|
|
|
57
37
|
get hasFocus() {
|
|
58
38
|
return document.activeElement === this._inputElement.current;
|
|
59
39
|
}
|
|
40
|
+
_updateInputValue = (e) => {
|
|
41
|
+
if (this._isMounted)
|
|
42
|
+
this.setState({
|
|
43
|
+
inputValue: e.target.value,
|
|
44
|
+
}, async () => {
|
|
45
|
+
if (this.props.shouldCommitOnChange &&
|
|
46
|
+
this.props.onCommit &&
|
|
47
|
+
this.props.propertyRecord) {
|
|
48
|
+
const newValue = await this.getPropertyValue();
|
|
49
|
+
if (newValue)
|
|
50
|
+
this.props.onCommit({
|
|
51
|
+
propertyRecord: this.props.propertyRecord,
|
|
52
|
+
newValue,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
60
57
|
componentDidMount() {
|
|
61
58
|
this._isMounted = true;
|
|
62
59
|
void this.setStateFromProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/TextEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAM7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAYlD;;GAEG;AACH,MAAM,OAAO,UACX,SAAQ,KAAK,CAAC,aAAmD;IADnE;;QAIU,eAAU,GAAG,KAAK,C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EAAE,YAAY;IACzC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC5C,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CACL,oBAAC,oBAAoB,IAAC,IAAI,EAAC,OAAO;YAC/B,IAAI,IAAI,CACP,oBAAC,oBAAoB,CAAC,IAAI,IAAC,IAAI,EAAC,OAAO,IACpC,IAAI,CACqB,CAC7B;YACD,oBAAC,oBAAoB,CAAC,KAAK,OACrB,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,wBAAwB,EACpC,IAAI,EAAC,OAAO,GACZ;YACD,UAAU,CACU,CACxB,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,EAAE,CAAC;QACT,OAAO;QACL,4DAA4D;QAC5D,oBAAC,SAAS,OACJ,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,IAAI,iBACE,wBAAwB,GACpC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,CACL,oBAAC,KAAK,OACA,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,wBAAwB,EACpC,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./TextEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input, InputWithDecorations } from \"@itwin/itwinui-react\";\nimport { TypeConverterManager } from \"../converters/TypeConverterManager.js\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { UiComponents } from \"../UiComponents.js\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** @internal */\ninterface TextEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** TextEditor React component that is a property editor with text input\n * @public\n */\nexport class TextEditor\n extends React.PureComponent<PropertyEditorProps, TextEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement = React.createRef<HTMLInputElement>();\n\n public override readonly state: Readonly<TextEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertFromStringToPropertyValue(this.state.inputValue, record);\n (propertyValue as PrimitiveValue).displayValue = this.state.inputValue;\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (this._isMounted)\n this.setState(\n {\n inputValue: e.target.value,\n },\n async () => {\n if (\n this.props.shouldCommitOnChange &&\n this.props.onCommit &&\n this.props.propertyRecord\n ) {\n const newValue = await this.getPropertyValue();\n if (newValue)\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = \"\";\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const value = record.value.value;\n initialValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertPropertyToString(record.property, value);\n }\n\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon.valueOf()\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n if (this._isMounted)\n this.setState({\n inputValue: initialValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const className = classnames(\n \"components-cell-editor\",\n \"components-text-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const inputProps: InputProps = {\n type: \"text\",\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly: this.props.propertyRecord?.isReadonly,\n disabled: this.props.propertyRecord?.isDisabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onBlur: this.props.onBlur,\n onChange: this._updateInputValue,\n autoFocus: this.props.setFocus && !this.props.propertyRecord?.isDisabled,\n \"aria-label\": UiComponents.translate(\"editor.text\"),\n };\n\n const icon = this.state.iconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={this.state.iconSpec} />\n ) : undefined;\n return (\n <LockTextEditor\n {...inputProps}\n ref={this._inputElement}\n id={this.props.propertyRecord?.property.name}\n icon={icon}\n decoration={decoration}\n />\n );\n }\n}\n\ninterface LockTextEditorProps extends InputProps {\n icon?: React.ReactNode;\n decoration?: React.ReactNode;\n}\n\nconst LockTextEditor = React.forwardRef<HTMLInputElement, LockTextEditorProps>(\n function LockTextEditor(props, forwardedRef) {\n const { icon, decoration, ...rest } = props;\n if (decoration) {\n return (\n <InputWithDecorations size=\"small\">\n {icon && (\n <InputWithDecorations.Icon size=\"small\">\n {icon}\n </InputWithDecorations.Icon>\n )}\n <InputWithDecorations.Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-text-editor\"\n size=\"small\"\n />\n {decoration}\n </InputWithDecorations>\n );\n }\n\n if (icon) {\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <IconInput\n {...rest}\n ref={forwardedRef}\n icon={icon}\n data-testid=\"components-text-editor\"\n />\n );\n }\n return (\n <Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-text-editor\"\n size=\"small\"\n />\n );\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"TextEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/TextEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAM7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAYlD;;GAEG;AACH,MAAM,OAAO,UACX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CACrC,SAAS,cAAc,CAAC,KAAK,EAAE,YAAY;IACzC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC5C,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CACL,oBAAC,oBAAoB,IAAC,IAAI,EAAC,OAAO;YAC/B,IAAI,IAAI,CACP,oBAAC,oBAAoB,CAAC,IAAI,IAAC,IAAI,EAAC,OAAO,IACpC,IAAI,CACqB,CAC7B;YACD,oBAAC,oBAAoB,CAAC,KAAK,OACrB,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,wBAAwB,EACpC,IAAI,EAAC,OAAO,GACZ;YACD,UAAU,CACU,CACxB,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,EAAE,CAAC;QACT,OAAO;QACL,4DAA4D;QAC5D,oBAAC,SAAS,OACJ,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,IAAI,iBACE,wBAAwB,GACpC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,CACL,oBAAC,KAAK,OACA,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,wBAAwB,EACpC,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./TextEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input, InputWithDecorations } from \"@itwin/itwinui-react\";\nimport { TypeConverterManager } from \"../converters/TypeConverterManager.js\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { UiComponents } from \"../UiComponents.js\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** @internal */\ninterface TextEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** TextEditor React component that is a property editor with text input\n * @public\n */\nexport class TextEditor\n extends React.PureComponent<PropertyEditorProps, TextEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _inputElement = React.createRef<HTMLInputElement>();\n\n public override readonly state: Readonly<TextEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertFromStringToPropertyValue(this.state.inputValue, record);\n (propertyValue as PrimitiveValue).displayValue = this.state.inputValue;\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (this._isMounted)\n this.setState(\n {\n inputValue: e.target.value,\n },\n async () => {\n if (\n this.props.shouldCommitOnChange &&\n this.props.onCommit &&\n this.props.propertyRecord\n ) {\n const newValue = await this.getPropertyValue();\n if (newValue)\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n }\n );\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = \"\";\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const value = record.value.value;\n initialValue = await TypeConverterManager.getConverter(\n record.property.typename,\n record.property.converter?.name\n ).convertPropertyToString(record.property, value);\n }\n\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n if (\n record &&\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n if (editorSizeParams) {\n if (editorSizeParams.size) size = editorSizeParams.size;\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon.valueOf()\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n if (this._isMounted)\n this.setState({\n inputValue: initialValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const className = classnames(\n \"components-cell-editor\",\n \"components-text-editor\",\n this.props.className\n );\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const inputProps: InputProps = {\n type: \"text\",\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly: this.props.propertyRecord?.isReadonly,\n disabled: this.props.propertyRecord?.isDisabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onBlur: this.props.onBlur,\n onChange: this._updateInputValue,\n autoFocus: this.props.setFocus && !this.props.propertyRecord?.isDisabled,\n \"aria-label\": UiComponents.translate(\"editor.text\"),\n };\n\n const icon = this.state.iconSpec ? (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <Icon iconSpec={this.state.iconSpec} />\n ) : undefined;\n return (\n <LockTextEditor\n {...inputProps}\n ref={this._inputElement}\n id={this.props.propertyRecord?.property.name}\n icon={icon}\n decoration={decoration}\n />\n );\n }\n}\n\ninterface LockTextEditorProps extends InputProps {\n icon?: React.ReactNode;\n decoration?: React.ReactNode;\n}\n\nconst LockTextEditor = React.forwardRef<HTMLInputElement, LockTextEditorProps>(\n function LockTextEditor(props, forwardedRef) {\n const { icon, decoration, ...rest } = props;\n if (decoration) {\n return (\n <InputWithDecorations size=\"small\">\n {icon && (\n <InputWithDecorations.Icon size=\"small\">\n {icon}\n </InputWithDecorations.Icon>\n )}\n <InputWithDecorations.Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-text-editor\"\n size=\"small\"\n />\n {decoration}\n </InputWithDecorations>\n );\n }\n\n if (icon) {\n return (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <IconInput\n {...rest}\n ref={forwardedRef}\n icon={icon}\n data-testid=\"components-text-editor\"\n />\n );\n }\n return (\n <Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-text-editor\"\n size=\"small\"\n />\n );\n }\n);\n"]}
|