@itwin/components-react 3.0.0-dev.160 → 3.0.0-dev.167
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/lib/cjs/components-react/editors/CustomNumberEditor.d.ts +2 -1
- package/lib/cjs/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/CustomNumberEditor.js +18 -7
- package/lib/cjs/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.d.ts +2 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.js +18 -7
- package/lib/esm/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/package.json +11 -11
|
@@ -20,6 +20,7 @@ export declare class CustomNumberEditor extends React.PureComponent<PropertyEdit
|
|
|
20
20
|
private _isMounted;
|
|
21
21
|
private _formatParams;
|
|
22
22
|
private _inputElement;
|
|
23
|
+
private _lastValidValue;
|
|
23
24
|
/** @internal */
|
|
24
25
|
readonly state: Readonly<CustomNumberEditorState>;
|
|
25
26
|
getPropertyValue(): Promise<PropertyValue | undefined>;
|
|
@@ -36,7 +37,7 @@ export declare class CustomNumberEditor extends React.PureComponent<PropertyEdit
|
|
|
36
37
|
componentDidUpdate(prevProps: PropertyEditorProps): void;
|
|
37
38
|
private _getInitialDisplayValue;
|
|
38
39
|
private setStateFromProps;
|
|
39
|
-
private
|
|
40
|
+
private _resetToLastValidDisplayValue;
|
|
40
41
|
private _onKeyPress;
|
|
41
42
|
private _onFocus;
|
|
42
43
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumberEditor.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,2BAA2B,CAAC;AAEnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAA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OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,eAAe,CAA4B;IAEnD,gBAAgB;IAChB,SAAyB,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAE/D;IAEW,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAiDnE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,iBAAiB,CAEvB;IAEF,gBAAgB;IACA,iBAAiB;IAKjC,gBAAgB;IACA,oBAAoB;IAIpC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;IAMjE,OAAO,CAAC,uBAAuB;YAqBjB,iBAAiB;IAuD/B,OAAO,CAAC,6BAA6B;IAKrC,OAAO,CAAC,WAAW,CAmBjB;IAGF,OAAO,CAAC,QAAQ,CAEd;IAEF,gBAAgB;IACA,MAAM,IAAI,KAAK,CAAC,SAAS;CAqD1C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;IACD,IAAoB,sBAAsB,IAAI,OAAO,CAEpD;CACF"}
|
|
@@ -56,13 +56,14 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
56
56
|
this._applyUpdatedValue(e.target.value);
|
|
57
57
|
};
|
|
58
58
|
this._onKeyPress = (e) => {
|
|
59
|
+
var _a;
|
|
59
60
|
// istanbul ignore else
|
|
60
61
|
if (e.key === appui_abstract_1.SpecialKey.Escape) {
|
|
61
|
-
const initialDisplayValue = this._getInitialDisplayValue();
|
|
62
|
+
const initialDisplayValue = (_a = (this._lastValidValue && this._lastValidValue.displayValue)) !== null && _a !== void 0 ? _a : this._getInitialDisplayValue();
|
|
62
63
|
if (initialDisplayValue !== this.state.inputValue) {
|
|
63
64
|
e.preventDefault();
|
|
64
65
|
e.stopPropagation();
|
|
65
|
-
this.
|
|
66
|
+
this._resetToLastValidDisplayValue();
|
|
66
67
|
}
|
|
67
68
|
else {
|
|
68
69
|
// istanbul ignore else
|
|
@@ -100,6 +101,7 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
100
101
|
value: parseResults.value,
|
|
101
102
|
displayValue: newDisplayValue,
|
|
102
103
|
};
|
|
104
|
+
this._lastValidValue = { ...propertyValue };
|
|
103
105
|
// make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6"
|
|
104
106
|
// istanbul ignore else
|
|
105
107
|
if (newDisplayValue !== this.state.inputValue) {
|
|
@@ -108,12 +110,15 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
108
110
|
}
|
|
109
111
|
else {
|
|
110
112
|
// istanbul ignore else
|
|
111
|
-
if (this.htmlElement)
|
|
113
|
+
if (this.htmlElement) {
|
|
112
114
|
appui_abstract_1.UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, appui_abstract_1.MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents_1.UiComponents.translate("errors.unable-to-parse-quantity"));
|
|
113
|
-
|
|
115
|
+
this.htmlElement.focus();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
114
118
|
appui_abstract_1.UiAdmin.messagePresenter.displayMessage(appui_abstract_1.MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents_1.UiComponents.translate("errors.unable-to-parse-quantity"));
|
|
119
|
+
}
|
|
115
120
|
const displayValue = (record.value.displayValue && record.value.displayValue.length > 0) ? record.value.displayValue : /* istanbul ignore next */ this._formatParams.formatFunction(record.value.value);
|
|
116
|
-
propertyValue = {
|
|
121
|
+
propertyValue = this._lastValidValue ? { ...this._lastValidValue } : {
|
|
117
122
|
valueFormat: appui_abstract_1.PropertyValueFormat.Primitive,
|
|
118
123
|
value: record.value.value,
|
|
119
124
|
displayValue,
|
|
@@ -202,6 +207,11 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
202
207
|
return;
|
|
203
208
|
}
|
|
204
209
|
const initialDisplayValue = this._getInitialDisplayValue();
|
|
210
|
+
this._lastValidValue = {
|
|
211
|
+
valueFormat: appui_abstract_1.PropertyValueFormat.Primitive,
|
|
212
|
+
value: record.value.value,
|
|
213
|
+
displayValue: initialDisplayValue,
|
|
214
|
+
};
|
|
205
215
|
let size;
|
|
206
216
|
let maxLength;
|
|
207
217
|
let iconSpec;
|
|
@@ -226,8 +236,9 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
226
236
|
if (this._isMounted)
|
|
227
237
|
this.setState({ inputValue: initialDisplayValue, size, maxLength, iconSpec });
|
|
228
238
|
}
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
_resetToLastValidDisplayValue() {
|
|
240
|
+
var _a;
|
|
241
|
+
const initialDisplayValue = (_a = (this._lastValidValue && this._lastValidValue.displayValue)) !== null && _a !== void 0 ? _a : this._getInitialDisplayValue();
|
|
231
242
|
this.setState({ inputValue: initialDisplayValue });
|
|
232
243
|
}
|
|
233
244
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oCAAoC;AAEpC,qCAAmC;AACnC,4DAAoC;AACpC,6CAA+B;AAC/B,sDAA6C;AAC7C,0DAG+B;AAC/B,kDAAoD;AACpD,wDAAyD;AAEzD,kDAA+C;AAE/C,mEAAoF;AAUpF;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK,CAAC,aAA2D;IAAzG;;QACU,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAE5D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F,IAAI,SAA0B,CAAC;QAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,MAAM,IAAI,GAAG,oBAAC,iBAAI,IAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAI,CAAC;YACrD,SAAS,GAAG,CACV,oBAAC,sBAAS,OACJ,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,EACvB,IAAI,EAAE,IAAI,iBACE,gCAAgC,GAC5C,CACH,CAAC;SACH;aAAM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,qBAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5QD,gDA4QC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,0CAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAPD,gEAOC;AACD,6CAAqB,CAAC,cAAc,CAAC,kCAAiB,CAAC,MAAM,EAAE,0BAA0B,EAAE,oCAAmB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module PropertyEditors\r\n */\r\n\r\n// cSpell:ignore customnumber testid\r\n\r\nimport \"./CustomNumberEditor.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n CustomFormattedNumberParams, IconEditorParams, InputEditorSizeParams, MessageSeverity, PrimitiveValue, PropertyEditorParams, PropertyEditorParamTypes,\r\n PropertyRecord, PropertyValue, PropertyValueFormat, SpecialKey, StandardEditorNames, StandardTypeNames, UiAdmin,\r\n} from \"@itwin/appui-abstract\";\r\nimport { Icon, IconInput } from \"@itwin/core-react\";\r\nimport { Input, InputProps } from \"@itwin/itwinui-react\";\r\n\r\nimport { UiComponents } from \"../UiComponents\";\r\nimport { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\r\nimport { PropertyEditorBase, PropertyEditorManager } from \"./PropertyEditorManager\";\r\n\r\n/** @internal */\r\ninterface CustomNumberEditorState {\r\n inputValue: string;\r\n size?: number;\r\n maxLength?: number;\r\n iconSpec?: string;\r\n}\r\n\r\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\r\n * @alpha\r\n */\r\nexport class CustomNumberEditor extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState> implements TypeEditor {\r\n private _isMounted = false;\r\n private _formatParams: CustomFormattedNumberParams | undefined;\r\n private _inputElement = React.createRef<HTMLInputElement>();\r\n\r\n /** @internal */\r\n public override readonly state: Readonly<CustomNumberEditorState> = {\r\n inputValue: \"\",\r\n };\r\n\r\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n let propertyValue: PropertyValue | undefined;\r\n\r\n if (record.isReadonly) {\r\n return {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: (record.value as PrimitiveValue).value,\r\n displayValue: (record.value as PrimitiveValue).displayValue,\r\n };\r\n }\r\n\r\n // istanbul ignore else\r\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const parseResults = (this._formatParams as CustomFormattedNumberParams).parseFunction(this.state.inputValue);\r\n if (!parseResults.parseError && undefined !== parseResults.value) {\r\n const newDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(parseResults.value as number);\r\n propertyValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: parseResults.value,\r\n displayValue: newDisplayValue,\r\n };\r\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\r\n // istanbul ignore else\r\n if (newDisplayValue !== this.state.inputValue) {\r\n this.setState({ inputValue: newDisplayValue });\r\n }\r\n } else {\r\n // istanbul ignore else\r\n if (this.htmlElement)\r\n UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n else\r\n UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n\r\n const displayValue = (record.value.displayValue && record.value.displayValue.length > 0) ? record.value.displayValue : /* istanbul ignore next */ (this._formatParams as CustomFormattedNumberParams).formatFunction(record.value.value as number);\r\n propertyValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: record.value.value,\r\n displayValue,\r\n };\r\n }\r\n }\r\n return propertyValue;\r\n }\r\n\r\n public get htmlElement(): HTMLElement | null {\r\n return this._inputElement.current;\r\n }\r\n\r\n public get hasFocus(): boolean {\r\n return document.activeElement === this._inputElement.current;\r\n }\r\n\r\n private shouldSetFocus(): boolean {\r\n if (!this.props.setFocus)\r\n return false;\r\n\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n\r\n return (!disabled && !readonly);\r\n }\r\n\r\n private _applyUpdatedValue(userInput: string) {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n\r\n if (readonly || disabled)\r\n return;\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({\r\n inputValue: userInput,\r\n });\r\n }\r\n\r\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\r\n this._applyUpdatedValue(e.target.value);\r\n };\r\n\r\n /** @internal */\r\n public override componentDidMount() {\r\n this._isMounted = true;\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n /** @internal */\r\n public override componentWillUnmount() {\r\n this._isMounted = false;\r\n }\r\n\r\n /** @internal */\r\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\r\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n private _getInitialDisplayValue(): string {\r\n const record = this.props.propertyRecord;\r\n let initialDisplayValue = \"\";\r\n let numberValue = 0;\r\n // istanbul ignore else\r\n if (record) {\r\n // istanbul ignore else\r\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const primitiveValue = record.value;\r\n numberValue = (undefined !== primitiveValue.value) ? primitiveValue.value as number : /* istanbul ignore next */ 0;\r\n // istanbul ignore else\r\n if (primitiveValue.displayValue)\r\n initialDisplayValue = primitiveValue.displayValue;\r\n else\r\n initialDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(numberValue);\r\n }\r\n }\r\n\r\n return initialDisplayValue;\r\n }\r\n\r\n private async setStateFromProps() {\r\n const record = this.props.propertyRecord;\r\n // istanbul ignore next\r\n if (!record || !record.property) {\r\n Logger.logError(UiComponents.loggerCategory(this), \"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n // eslint-disable-next-line no-console\r\n // console.log(\"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n return;\r\n }\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n this._formatParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.CustomFormattedNumber) as CustomFormattedNumberParams;\r\n }\r\n\r\n if (!this._formatParams) {\r\n Logger.logError(UiComponents.loggerCategory(this), `CustomFormattedNumberParams must be defined for property ${record.property.name}`);\r\n // eslint-disable-next-line no-console\r\n // console.log(`CustomFormattedNumberParams must be defined for property ${record!.property!.name}`);\r\n return;\r\n }\r\n\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n let size: number | undefined;\r\n let maxLength: number | undefined;\r\n let iconSpec: string | undefined;\r\n\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n const editorSizeParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.InputEditorSize) as InputEditorSizeParams;\r\n // istanbul ignore else\r\n if (editorSizeParams) {\r\n // istanbul ignore else\r\n if (editorSizeParams.size)\r\n size = editorSizeParams.size;\r\n // istanbul ignore else\r\n if (editorSizeParams.maxLength)\r\n maxLength = editorSizeParams.maxLength;\r\n }\r\n\r\n const iconParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.Icon) as IconEditorParams;\r\n if (iconParams) {\r\n iconSpec = iconParams.definition.iconSpec;\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({ inputValue: initialDisplayValue, size, maxLength, iconSpec });\r\n }\r\n\r\n private _resetToOriginalValue() {\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n\r\n this.setState({ inputValue: initialDisplayValue });\r\n }\r\n\r\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\r\n // istanbul ignore else\r\n if (e.key === SpecialKey.Escape) {\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n if (initialDisplayValue !== this.state.inputValue) {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n this._resetToOriginalValue();\r\n } else {\r\n // istanbul ignore else\r\n if (this.props.onCancel)\r\n this.props.onCancel();\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (e.key !== SpecialKey.Enter) {\r\n UiAdmin.messagePresenter.closeInputFieldMessage();\r\n }\r\n };\r\n\r\n // istanbul ignore next\r\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\r\n e.target.select();\r\n };\r\n\r\n /** @internal */\r\n public override render(): React.ReactNode {\r\n const minSize = this.state.size ? this.state.size : 8;\r\n const minWidthStyle: React.CSSProperties = {\r\n minWidth: `${minSize * 0.75}em`,\r\n };\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n if (!record || !this._formatParams)\r\n return null;\r\n\r\n const readOnly = !record.isReadonly ? false : true;\r\n const disabled = !record.isDisabled ? false : true;\r\n\r\n const className = classnames(\"components-cell-editor\", \"components-customnumber-editor\", this.props.className);\r\n\r\n const inputProps: Omit<InputProps, \"size\"> = { // eslint-disable-line deprecation/deprecation\r\n className,\r\n style: this.props.style ? this.props.style : minWidthStyle,\r\n readOnly,\r\n disabled,\r\n maxLength: this.state.maxLength,\r\n value: this.state.inputValue,\r\n onChange: this._updateInputValue,\r\n onBlur: this.props.onBlur,\r\n onFocus: this._onFocus,\r\n setFocus: this.shouldSetFocus(),\r\n onKeyDown: this._onKeyPress,\r\n };\r\n\r\n let reactNode: React.ReactNode;\r\n if (this.state.iconSpec) {\r\n const icon = <Icon iconSpec={this.state.iconSpec} />;\r\n reactNode = (\r\n <IconInput\r\n {...inputProps}\r\n ref={this._inputElement}\r\n icon={icon}\r\n data-testid=\"components-customnumber-editor\"\r\n />\r\n );\r\n } else {\r\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\r\n reactNode = (\r\n <Input\r\n {...inputProps}\r\n ref={this._inputElement}\r\n data-testid=\"components-customnumber-editor\"\r\n size=\"small\"\r\n />\r\n );\r\n }\r\n\r\n return reactNode;\r\n }\r\n}\r\n\r\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\r\n * It uses the [[CustomNumberEditor]] React component.\r\n * @alpha\r\n */\r\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\r\n public get reactNode(): React.ReactNode {\r\n return <CustomNumberEditor />;\r\n }\r\n public override get containerHandlesEscape(): boolean {\r\n return false;\r\n }\r\n}\r\nPropertyEditorManager.registerEditor(StandardTypeNames.Number, CustomNumberPropertyEditor, StandardEditorNames.NumberCustom);\r\n"]}
|
|
1
|
+
{"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oCAAoC;AAEpC,qCAAmC;AACnC,4DAAoC;AACpC,6CAA+B;AAC/B,sDAA6C;AAC7C,0DAG+B;AAC/B,kDAAoD;AACpD,wDAAyD;AAEzD,kDAA+C;AAE/C,mEAAoF;AAUpF;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK,CAAC,aAA2D;IAAzG;;QACU,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAG5D,gBAAgB;QACS,UAAK,GAAsC;YAClE,UAAU,EAAE,EAAE;SACf,CAAC;QAqFM,sBAAiB,GAAG,CAAC,CAAsC,EAAE,EAAE;YACrE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC,CAAC;QAqGM,gBAAW,GAAG,CAAC,CAAwC,EAAE,EAAE;;YACjE,uBAAuB;YACvB,IAAI,CAAC,CAAC,GAAG,KAAK,2BAAU,CAAC,MAAM,EAAE;gBAC/B,MAAM,mBAAmB,GAAG,MAAA,CAAC,IAAI,CAAC,eAAe,IAAK,IAAI,CAAC,eAAkC,CAAC,YAAY,CAAC,mCAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;gBAC9I,IAAI,mBAAmB,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;oBACjD,CAAC,CAAC,cAAc,EAAE,CAAC;oBACnB,CAAC,CAAC,eAAe,EAAE,CAAC;oBACpB,IAAI,CAAC,6BAA6B,EAAE,CAAC;iBACtC;qBAAM;oBACL,uBAAuB;oBACvB,IAAI,IAAI,CAAC,KAAK,CAAC,QA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AAC;YACrD,SAAS,GAAG,CACV,oBAAC,sBAAS,OACJ,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,EACvB,IAAI,EAAE,IAAI,iBACE,gCAAgC,GAC5C,CACH,CAAC;SACH;aAAM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,qBAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AArRD,gDAqRC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,0CAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAPD,gEAOC;AACD,6CAAqB,CAAC,cAAc,CAAC,kCAAiB,CAAC,MAAM,EAAE,0BAA0B,EAAE,oCAAmB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module PropertyEditors\r\n */\r\n\r\n// cSpell:ignore customnumber testid\r\n\r\nimport \"./CustomNumberEditor.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n CustomFormattedNumberParams, IconEditorParams, InputEditorSizeParams, MessageSeverity, PrimitiveValue, PropertyEditorParams, PropertyEditorParamTypes,\r\n PropertyRecord, PropertyValue, PropertyValueFormat, SpecialKey, StandardEditorNames, StandardTypeNames, UiAdmin,\r\n} from \"@itwin/appui-abstract\";\r\nimport { Icon, IconInput } from \"@itwin/core-react\";\r\nimport { Input, InputProps } from \"@itwin/itwinui-react\";\r\n\r\nimport { UiComponents } from \"../UiComponents\";\r\nimport { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\r\nimport { PropertyEditorBase, PropertyEditorManager } from \"./PropertyEditorManager\";\r\n\r\n/** @internal */\r\ninterface CustomNumberEditorState {\r\n inputValue: string;\r\n size?: number;\r\n maxLength?: number;\r\n iconSpec?: string;\r\n}\r\n\r\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\r\n * @alpha\r\n */\r\nexport class CustomNumberEditor extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState> implements TypeEditor {\r\n private _isMounted = false;\r\n private _formatParams: CustomFormattedNumberParams | undefined;\r\n private _inputElement = React.createRef<HTMLInputElement>();\r\n private _lastValidValue: PropertyValue | undefined;\r\n\r\n /** @internal */\r\n public override readonly state: Readonly<CustomNumberEditorState> = {\r\n inputValue: \"\",\r\n };\r\n\r\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n let propertyValue: PropertyValue | undefined;\r\n\r\n if (record.isReadonly) {\r\n return {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: (record.value as PrimitiveValue).value,\r\n displayValue: (record.value as PrimitiveValue).displayValue,\r\n };\r\n }\r\n\r\n // istanbul ignore else\r\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const parseResults = (this._formatParams as CustomFormattedNumberParams).parseFunction(this.state.inputValue);\r\n if (!parseResults.parseError && undefined !== parseResults.value) {\r\n const newDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(parseResults.value as number);\r\n propertyValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: parseResults.value,\r\n displayValue: newDisplayValue,\r\n };\r\n this._lastValidValue = { ...propertyValue };\r\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\r\n // istanbul ignore else\r\n if (newDisplayValue !== this.state.inputValue) {\r\n this.setState({ inputValue: newDisplayValue });\r\n }\r\n } else {\r\n // istanbul ignore else\r\n if (this.htmlElement) {\r\n UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n this.htmlElement.focus();\r\n } else {\r\n UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n }\r\n\r\n const displayValue = (record.value.displayValue && record.value.displayValue.length > 0) ? record.value.displayValue : /* istanbul ignore next */ (this._formatParams as CustomFormattedNumberParams).formatFunction(record.value.value as number);\r\n propertyValue = this._lastValidValue ? { ...this._lastValidValue } : {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: record.value.value,\r\n displayValue,\r\n };\r\n }\r\n }\r\n\r\n return propertyValue;\r\n }\r\n\r\n public get htmlElement(): HTMLElement | null {\r\n return this._inputElement.current;\r\n }\r\n\r\n public get hasFocus(): boolean {\r\n return document.activeElement === this._inputElement.current;\r\n }\r\n\r\n private shouldSetFocus(): boolean {\r\n if (!this.props.setFocus)\r\n return false;\r\n\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n\r\n return (!disabled && !readonly);\r\n }\r\n\r\n private _applyUpdatedValue(userInput: string) {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n\r\n if (readonly || disabled)\r\n return;\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({\r\n inputValue: userInput,\r\n });\r\n }\r\n\r\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\r\n this._applyUpdatedValue(e.target.value);\r\n };\r\n\r\n /** @internal */\r\n public override componentDidMount() {\r\n this._isMounted = true;\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n /** @internal */\r\n public override componentWillUnmount() {\r\n this._isMounted = false;\r\n }\r\n\r\n /** @internal */\r\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\r\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n private _getInitialDisplayValue(): string {\r\n const record = this.props.propertyRecord;\r\n let initialDisplayValue = \"\";\r\n let numberValue = 0;\r\n // istanbul ignore else\r\n if (record) {\r\n // istanbul ignore else\r\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const primitiveValue = record.value;\r\n numberValue = (undefined !== primitiveValue.value) ? primitiveValue.value as number : /* istanbul ignore next */ 0;\r\n // istanbul ignore else\r\n if (primitiveValue.displayValue)\r\n initialDisplayValue = primitiveValue.displayValue;\r\n else\r\n initialDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(numberValue);\r\n }\r\n }\r\n\r\n return initialDisplayValue;\r\n }\r\n\r\n private async setStateFromProps() {\r\n const record = this.props.propertyRecord;\r\n // istanbul ignore next\r\n if (!record || !record.property) {\r\n Logger.logError(UiComponents.loggerCategory(this), \"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n // eslint-disable-next-line no-console\r\n // console.log(\"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n return;\r\n }\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n this._formatParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.CustomFormattedNumber) as CustomFormattedNumberParams;\r\n }\r\n\r\n if (!this._formatParams) {\r\n Logger.logError(UiComponents.loggerCategory(this), `CustomFormattedNumberParams must be defined for property ${record.property.name}`);\r\n // eslint-disable-next-line no-console\r\n // console.log(`CustomFormattedNumberParams must be defined for property ${record!.property!.name}`);\r\n return;\r\n }\r\n\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n this._lastValidValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: (record.value as PrimitiveValue).value,\r\n displayValue: initialDisplayValue,\r\n };\r\n let size: number | undefined;\r\n let maxLength: number | undefined;\r\n let iconSpec: string | undefined;\r\n\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n const editorSizeParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.InputEditorSize) as InputEditorSizeParams;\r\n // istanbul ignore else\r\n if (editorSizeParams) {\r\n // istanbul ignore else\r\n if (editorSizeParams.size)\r\n size = editorSizeParams.size;\r\n // istanbul ignore else\r\n if (editorSizeParams.maxLength)\r\n maxLength = editorSizeParams.maxLength;\r\n }\r\n\r\n const iconParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.Icon) as IconEditorParams;\r\n if (iconParams) {\r\n iconSpec = iconParams.definition.iconSpec;\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({ inputValue: initialDisplayValue, size, maxLength, iconSpec });\r\n }\r\n\r\n private _resetToLastValidDisplayValue() {\r\n const initialDisplayValue = (this._lastValidValue && (this._lastValidValue as PrimitiveValue).displayValue) ?? this._getInitialDisplayValue();\r\n this.setState({ inputValue: initialDisplayValue });\r\n }\r\n\r\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\r\n // istanbul ignore else\r\n if (e.key === SpecialKey.Escape) {\r\n const initialDisplayValue = (this._lastValidValue && (this._lastValidValue as PrimitiveValue).displayValue) ?? this._getInitialDisplayValue();\r\n if (initialDisplayValue !== this.state.inputValue) {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n this._resetToLastValidDisplayValue();\r\n } else {\r\n // istanbul ignore else\r\n if (this.props.onCancel)\r\n this.props.onCancel();\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (e.key !== SpecialKey.Enter) {\r\n UiAdmin.messagePresenter.closeInputFieldMessage();\r\n }\r\n };\r\n\r\n // istanbul ignore next\r\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\r\n e.target.select();\r\n };\r\n\r\n /** @internal */\r\n public override render(): React.ReactNode {\r\n const minSize = this.state.size ? this.state.size : 8;\r\n const minWidthStyle: React.CSSProperties = {\r\n minWidth: `${minSize * 0.75}em`,\r\n };\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n if (!record || !this._formatParams)\r\n return null;\r\n\r\n const readOnly = !record.isReadonly ? false : true;\r\n const disabled = !record.isDisabled ? false : true;\r\n\r\n const className = classnames(\"components-cell-editor\", \"components-customnumber-editor\", this.props.className);\r\n\r\n const inputProps: Omit<InputProps, \"size\"> = { // eslint-disable-line deprecation/deprecation\r\n className,\r\n style: this.props.style ? this.props.style : minWidthStyle,\r\n readOnly,\r\n disabled,\r\n maxLength: this.state.maxLength,\r\n value: this.state.inputValue,\r\n onChange: this._updateInputValue,\r\n onBlur: this.props.onBlur,\r\n onFocus: this._onFocus,\r\n setFocus: this.shouldSetFocus(),\r\n onKeyDown: this._onKeyPress,\r\n };\r\n\r\n let reactNode: React.ReactNode;\r\n if (this.state.iconSpec) {\r\n const icon = <Icon iconSpec={this.state.iconSpec} />;\r\n reactNode = (\r\n <IconInput\r\n {...inputProps}\r\n ref={this._inputElement}\r\n icon={icon}\r\n data-testid=\"components-customnumber-editor\"\r\n />\r\n );\r\n } else {\r\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\r\n reactNode = (\r\n <Input\r\n {...inputProps}\r\n ref={this._inputElement}\r\n data-testid=\"components-customnumber-editor\"\r\n size=\"small\"\r\n />\r\n );\r\n }\r\n\r\n return reactNode;\r\n }\r\n}\r\n\r\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\r\n * It uses the [[CustomNumberEditor]] React component.\r\n * @alpha\r\n */\r\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\r\n public get reactNode(): React.ReactNode {\r\n return <CustomNumberEditor />;\r\n }\r\n public override get containerHandlesEscape(): boolean {\r\n return false;\r\n }\r\n}\r\nPropertyEditorManager.registerEditor(StandardTypeNames.Number, CustomNumberPropertyEditor, StandardEditorNames.NumberCustom);\r\n"]}
|
|
@@ -20,6 +20,7 @@ export declare class CustomNumberEditor extends React.PureComponent<PropertyEdit
|
|
|
20
20
|
private _isMounted;
|
|
21
21
|
private _formatParams;
|
|
22
22
|
private _inputElement;
|
|
23
|
+
private _lastValidValue;
|
|
23
24
|
/** @internal */
|
|
24
25
|
readonly state: Readonly<CustomNumberEditorState>;
|
|
25
26
|
getPropertyValue(): Promise<PropertyValue | undefined>;
|
|
@@ -36,7 +37,7 @@ export declare class CustomNumberEditor extends React.PureComponent<PropertyEdit
|
|
|
36
37
|
componentDidUpdate(prevProps: PropertyEditorProps): void;
|
|
37
38
|
private _getInitialDisplayValue;
|
|
38
39
|
private setStateFromProps;
|
|
39
|
-
private
|
|
40
|
+
private _resetToLastValidDisplayValue;
|
|
40
41
|
private _onKeyPress;
|
|
41
42
|
private _onFocus;
|
|
42
43
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumberEditor.d.ts","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,2BAA2B,CAAC;AAEnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAEW,aAAa,EAC9B,MAAM,uBAAuB,CAAC;AAK/B,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAyB,MAAM,yBAAyB,CAAC;AAEpF,gBAAgB;AAChB,UAAU,uBAAuB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAA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IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,iBAAiB,CAEvB;IAEF,gBAAgB;IACA,iBAAiB;IAKjC,gBAAgB;IACA,oBAAoB;IAIpC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;IAMjE,OAAO,CAAC,uBAAuB;YAqBjB,iBAAiB;IAuD/B,OAAO,CAAC,6BAA6B;IAKrC,OAAO,CAAC,WAAW,CAmBjB;IAGF,OAAO,CAAC,QAAQ,CAEd;IAEF,gBAAgB;IACA,MAAM,IAAI,KAAK,CAAC,SAAS;CAqD1C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;IACD,IAAoB,sBAAsB,IAAI,OAAO,CAEpD;CACF"}
|
|
@@ -31,13 +31,14 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
31
31
|
this._applyUpdatedValue(e.target.value);
|
|
32
32
|
};
|
|
33
33
|
this._onKeyPress = (e) => {
|
|
34
|
+
var _a;
|
|
34
35
|
// istanbul ignore else
|
|
35
36
|
if (e.key === SpecialKey.Escape) {
|
|
36
|
-
const initialDisplayValue = this._getInitialDisplayValue();
|
|
37
|
+
const initialDisplayValue = (_a = (this._lastValidValue && this._lastValidValue.displayValue)) !== null && _a !== void 0 ? _a : this._getInitialDisplayValue();
|
|
37
38
|
if (initialDisplayValue !== this.state.inputValue) {
|
|
38
39
|
e.preventDefault();
|
|
39
40
|
e.stopPropagation();
|
|
40
|
-
this.
|
|
41
|
+
this._resetToLastValidDisplayValue();
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
43
44
|
// istanbul ignore else
|
|
@@ -75,6 +76,7 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
75
76
|
value: parseResults.value,
|
|
76
77
|
displayValue: newDisplayValue,
|
|
77
78
|
};
|
|
79
|
+
this._lastValidValue = { ...propertyValue };
|
|
78
80
|
// make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6"
|
|
79
81
|
// istanbul ignore else
|
|
80
82
|
if (newDisplayValue !== this.state.inputValue) {
|
|
@@ -83,12 +85,15 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
83
85
|
}
|
|
84
86
|
else {
|
|
85
87
|
// istanbul ignore else
|
|
86
|
-
if (this.htmlElement)
|
|
88
|
+
if (this.htmlElement) {
|
|
87
89
|
UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate("errors.unable-to-parse-quantity"));
|
|
88
|
-
|
|
90
|
+
this.htmlElement.focus();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
89
93
|
UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate("errors.unable-to-parse-quantity"));
|
|
94
|
+
}
|
|
90
95
|
const displayValue = (record.value.displayValue && record.value.displayValue.length > 0) ? record.value.displayValue : /* istanbul ignore next */ this._formatParams.formatFunction(record.value.value);
|
|
91
|
-
propertyValue = {
|
|
96
|
+
propertyValue = this._lastValidValue ? { ...this._lastValidValue } : {
|
|
92
97
|
valueFormat: PropertyValueFormat.Primitive,
|
|
93
98
|
value: record.value.value,
|
|
94
99
|
displayValue,
|
|
@@ -177,6 +182,11 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
177
182
|
return;
|
|
178
183
|
}
|
|
179
184
|
const initialDisplayValue = this._getInitialDisplayValue();
|
|
185
|
+
this._lastValidValue = {
|
|
186
|
+
valueFormat: PropertyValueFormat.Primitive,
|
|
187
|
+
value: record.value.value,
|
|
188
|
+
displayValue: initialDisplayValue,
|
|
189
|
+
};
|
|
180
190
|
let size;
|
|
181
191
|
let maxLength;
|
|
182
192
|
let iconSpec;
|
|
@@ -201,8 +211,9 @@ export class CustomNumberEditor extends React.PureComponent {
|
|
|
201
211
|
if (this._isMounted)
|
|
202
212
|
this.setState({ inputValue: initialDisplayValue, size, maxLength, iconSpec });
|
|
203
213
|
}
|
|
204
|
-
|
|
205
|
-
|
|
214
|
+
_resetToLastValidDisplayValue() {
|
|
215
|
+
var _a;
|
|
216
|
+
const initialDisplayValue = (_a = (this._lastValidValue && this._lastValidValue.displayValue)) !== null && _a !== void 0 ? _a : this._getInitialDisplayValue();
|
|
206
217
|
this.setState({ inputValue: initialDisplayValue });
|
|
207
218
|
}
|
|
208
219
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,oCAAoC;AAEpC,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACiE,eAAe,EAAwC,wBAAwB,EACtH,mBAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,OAAO,GAChH,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAUpF;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,aAA2D;IAAzG;;QACU,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAE5D,gBAAgB;QACS,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AI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,MAAM,IAAI,GAAG,oBAAC,IAAI,IAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAI,CAAC;YACrD,SAAS,GAAG,CACV,oBAAC,SAAS,OACJ,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,EACvB,IAAI,EAAE,IAAI,iBACE,gCAAgC,GAC5C,CACH,CAAC;SACH;aAAM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,KAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AACD,qBAAqB,CAAC,cAAc,CAAC,iBAAiB,CAAC,MAAM,EAAE,0BAA0B,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module PropertyEditors\r\n */\r\n\r\n// cSpell:ignore customnumber testid\r\n\r\nimport \"./CustomNumberEditor.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n CustomFormattedNumberParams, IconEditorParams, InputEditorSizeParams, MessageSeverity, PrimitiveValue, PropertyEditorParams, PropertyEditorParamTypes,\r\n PropertyRecord, PropertyValue, PropertyValueFormat, SpecialKey, StandardEditorNames, StandardTypeNames, UiAdmin,\r\n} from \"@itwin/appui-abstract\";\r\nimport { Icon, IconInput } from \"@itwin/core-react\";\r\nimport { Input, InputProps } from \"@itwin/itwinui-react\";\r\n\r\nimport { UiComponents } from \"../UiComponents\";\r\nimport { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\r\nimport { PropertyEditorBase, PropertyEditorManager } from \"./PropertyEditorManager\";\r\n\r\n/** @internal */\r\ninterface CustomNumberEditorState {\r\n inputValue: string;\r\n size?: number;\r\n maxLength?: number;\r\n iconSpec?: string;\r\n}\r\n\r\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\r\n * @alpha\r\n */\r\nexport class CustomNumberEditor extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState> implements TypeEditor {\r\n private _isMounted = false;\r\n private _formatParams: CustomFormattedNumberParams | undefined;\r\n private _inputElement = React.createRef<HTMLInputElement>();\r\n\r\n /** @internal */\r\n public override readonly state: Readonly<CustomNumberEditorState> = {\r\n inputValue: \"\",\r\n };\r\n\r\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n let propertyValue: PropertyValue | undefined;\r\n\r\n if (record.isReadonly) {\r\n return {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: (record.value as PrimitiveValue).value,\r\n displayValue: (record.value as PrimitiveValue).displayValue,\r\n };\r\n }\r\n\r\n // istanbul ignore else\r\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const parseResults = (this._formatParams as CustomFormattedNumberParams).parseFunction(this.state.inputValue);\r\n if (!parseResults.parseError && undefined !== parseResults.value) {\r\n const newDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(parseResults.value as number);\r\n propertyValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: parseResults.value,\r\n displayValue: newDisplayValue,\r\n };\r\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\r\n // istanbul ignore else\r\n if (newDisplayValue !== this.state.inputValue) {\r\n this.setState({ inputValue: newDisplayValue });\r\n }\r\n } else {\r\n // istanbul ignore else\r\n if (this.htmlElement)\r\n UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n else\r\n UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n\r\n const displayValue = (record.value.displayValue && record.value.displayValue.length > 0) ? record.value.displayValue : /* istanbul ignore next */ (this._formatParams as CustomFormattedNumberParams).formatFunction(record.value.value as number);\r\n propertyValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: record.value.value,\r\n displayValue,\r\n };\r\n }\r\n }\r\n return propertyValue;\r\n }\r\n\r\n public get htmlElement(): HTMLElement | null {\r\n return this._inputElement.current;\r\n }\r\n\r\n public get hasFocus(): boolean {\r\n return document.activeElement === this._inputElement.current;\r\n }\r\n\r\n private shouldSetFocus(): boolean {\r\n if (!this.props.setFocus)\r\n return false;\r\n\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n\r\n return (!disabled && !readonly);\r\n }\r\n\r\n private _applyUpdatedValue(userInput: string) {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n\r\n if (readonly || disabled)\r\n return;\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({\r\n inputValue: userInput,\r\n });\r\n }\r\n\r\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\r\n this._applyUpdatedValue(e.target.value);\r\n };\r\n\r\n /** @internal */\r\n public override componentDidMount() {\r\n this._isMounted = true;\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n /** @internal */\r\n public override componentWillUnmount() {\r\n this._isMounted = false;\r\n }\r\n\r\n /** @internal */\r\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\r\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n private _getInitialDisplayValue(): string {\r\n const record = this.props.propertyRecord;\r\n let initialDisplayValue = \"\";\r\n let numberValue = 0;\r\n // istanbul ignore else\r\n if (record) {\r\n // istanbul ignore else\r\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const primitiveValue = record.value;\r\n numberValue = (undefined !== primitiveValue.value) ? primitiveValue.value as number : /* istanbul ignore next */ 0;\r\n // istanbul ignore else\r\n if (primitiveValue.displayValue)\r\n initialDisplayValue = primitiveValue.displayValue;\r\n else\r\n initialDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(numberValue);\r\n }\r\n }\r\n\r\n return initialDisplayValue;\r\n }\r\n\r\n private async setStateFromProps() {\r\n const record = this.props.propertyRecord;\r\n // istanbul ignore next\r\n if (!record || !record.property) {\r\n Logger.logError(UiComponents.loggerCategory(this), \"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n // eslint-disable-next-line no-console\r\n // console.log(\"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n return;\r\n }\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n this._formatParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.CustomFormattedNumber) as CustomFormattedNumberParams;\r\n }\r\n\r\n if (!this._formatParams) {\r\n Logger.logError(UiComponents.loggerCategory(this), `CustomFormattedNumberParams must be defined for property ${record.property.name}`);\r\n // eslint-disable-next-line no-console\r\n // console.log(`CustomFormattedNumberParams must be defined for property ${record!.property!.name}`);\r\n return;\r\n }\r\n\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n let size: number | undefined;\r\n let maxLength: number | undefined;\r\n let iconSpec: string | undefined;\r\n\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n const editorSizeParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.InputEditorSize) as InputEditorSizeParams;\r\n // istanbul ignore else\r\n if (editorSizeParams) {\r\n // istanbul ignore else\r\n if (editorSizeParams.size)\r\n size = editorSizeParams.size;\r\n // istanbul ignore else\r\n if (editorSizeParams.maxLength)\r\n maxLength = editorSizeParams.maxLength;\r\n }\r\n\r\n const iconParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.Icon) as IconEditorParams;\r\n if (iconParams) {\r\n iconSpec = iconParams.definition.iconSpec;\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({ inputValue: initialDisplayValue, size, maxLength, iconSpec });\r\n }\r\n\r\n private _resetToOriginalValue() {\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n\r\n this.setState({ inputValue: initialDisplayValue });\r\n }\r\n\r\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\r\n // istanbul ignore else\r\n if (e.key === SpecialKey.Escape) {\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n if (initialDisplayValue !== this.state.inputValue) {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n this._resetToOriginalValue();\r\n } else {\r\n // istanbul ignore else\r\n if (this.props.onCancel)\r\n this.props.onCancel();\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (e.key !== SpecialKey.Enter) {\r\n UiAdmin.messagePresenter.closeInputFieldMessage();\r\n }\r\n };\r\n\r\n // istanbul ignore next\r\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\r\n e.target.select();\r\n };\r\n\r\n /** @internal */\r\n public override render(): React.ReactNode {\r\n const minSize = this.state.size ? this.state.size : 8;\r\n const minWidthStyle: React.CSSProperties = {\r\n minWidth: `${minSize * 0.75}em`,\r\n };\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n if (!record || !this._formatParams)\r\n return null;\r\n\r\n const readOnly = !record.isReadonly ? false : true;\r\n const disabled = !record.isDisabled ? false : true;\r\n\r\n const className = classnames(\"components-cell-editor\", \"components-customnumber-editor\", this.props.className);\r\n\r\n const inputProps: Omit<InputProps, \"size\"> = { // eslint-disable-line deprecation/deprecation\r\n className,\r\n style: this.props.style ? this.props.style : minWidthStyle,\r\n readOnly,\r\n disabled,\r\n maxLength: this.state.maxLength,\r\n value: this.state.inputValue,\r\n onChange: this._updateInputValue,\r\n onBlur: this.props.onBlur,\r\n onFocus: this._onFocus,\r\n setFocus: this.shouldSetFocus(),\r\n onKeyDown: this._onKeyPress,\r\n };\r\n\r\n let reactNode: React.ReactNode;\r\n if (this.state.iconSpec) {\r\n const icon = <Icon iconSpec={this.state.iconSpec} />;\r\n reactNode = (\r\n <IconInput\r\n {...inputProps}\r\n ref={this._inputElement}\r\n icon={icon}\r\n data-testid=\"components-customnumber-editor\"\r\n />\r\n );\r\n } else {\r\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\r\n reactNode = (\r\n <Input\r\n {...inputProps}\r\n ref={this._inputElement}\r\n data-testid=\"components-customnumber-editor\"\r\n size=\"small\"\r\n />\r\n );\r\n }\r\n\r\n return reactNode;\r\n }\r\n}\r\n\r\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\r\n * It uses the [[CustomNumberEditor]] React component.\r\n * @alpha\r\n */\r\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\r\n public get reactNode(): React.ReactNode {\r\n return <CustomNumberEditor />;\r\n }\r\n public override get containerHandlesEscape(): boolean {\r\n return false;\r\n }\r\n}\r\nPropertyEditorManager.registerEditor(StandardTypeNames.Number, CustomNumberPropertyEditor, StandardEditorNames.NumberCustom);\r\n"]}
|
|
1
|
+
{"version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,CAAC,QAAQ;YACtB,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE;YAC/B,SAAS,EAAE,IAAI,CAAC,WAAW;SAC5B,CAAC;QAEF,IAAI,SAA0B,CAAC;QAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,MAAM,IAAI,GAAG,oBAAC,IAAI,IAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAI,CAAC;YACrD,SAAS,GAAG,CACV,oBAAC,SAAS,OACJ,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,EACvB,IAAI,EAAE,IAAI,iBACE,gCAAgC,GAC5C,CACH,CAAC;SACH;aAAM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,KAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AACD,qBAAqB,CAAC,cAAc,CAAC,iBAAiB,CAAC,MAAM,EAAE,0BAA0B,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module PropertyEditors\r\n */\r\n\r\n// cSpell:ignore customnumber testid\r\n\r\nimport \"./CustomNumberEditor.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n CustomFormattedNumberParams, IconEditorParams, InputEditorSizeParams, MessageSeverity, PrimitiveValue, PropertyEditorParams, PropertyEditorParamTypes,\r\n PropertyRecord, PropertyValue, PropertyValueFormat, SpecialKey, StandardEditorNames, StandardTypeNames, UiAdmin,\r\n} from \"@itwin/appui-abstract\";\r\nimport { Icon, IconInput } from \"@itwin/core-react\";\r\nimport { Input, InputProps } from \"@itwin/itwinui-react\";\r\n\r\nimport { UiComponents } from \"../UiComponents\";\r\nimport { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\r\nimport { PropertyEditorBase, PropertyEditorManager } from \"./PropertyEditorManager\";\r\n\r\n/** @internal */\r\ninterface CustomNumberEditorState {\r\n inputValue: string;\r\n size?: number;\r\n maxLength?: number;\r\n iconSpec?: string;\r\n}\r\n\r\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\r\n * @alpha\r\n */\r\nexport class CustomNumberEditor extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState> implements TypeEditor {\r\n private _isMounted = false;\r\n private _formatParams: CustomFormattedNumberParams | undefined;\r\n private _inputElement = React.createRef<HTMLInputElement>();\r\n private _lastValidValue: PropertyValue | undefined;\r\n\r\n /** @internal */\r\n public override readonly state: Readonly<CustomNumberEditorState> = {\r\n inputValue: \"\",\r\n };\r\n\r\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n let propertyValue: PropertyValue | undefined;\r\n\r\n if (record.isReadonly) {\r\n return {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: (record.value as PrimitiveValue).value,\r\n displayValue: (record.value as PrimitiveValue).displayValue,\r\n };\r\n }\r\n\r\n // istanbul ignore else\r\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const parseResults = (this._formatParams as CustomFormattedNumberParams).parseFunction(this.state.inputValue);\r\n if (!parseResults.parseError && undefined !== parseResults.value) {\r\n const newDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(parseResults.value as number);\r\n propertyValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: parseResults.value,\r\n displayValue: newDisplayValue,\r\n };\r\n this._lastValidValue = { ...propertyValue };\r\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\r\n // istanbul ignore else\r\n if (newDisplayValue !== this.state.inputValue) {\r\n this.setState({ inputValue: newDisplayValue });\r\n }\r\n } else {\r\n // istanbul ignore else\r\n if (this.htmlElement) {\r\n UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n this.htmlElement.focus();\r\n } else {\r\n UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError ? parseResults.parseError : /* istanbul ignore next */ UiComponents.translate(\"errors.unable-to-parse-quantity\"));\r\n }\r\n\r\n const displayValue = (record.value.displayValue && record.value.displayValue.length > 0) ? record.value.displayValue : /* istanbul ignore next */ (this._formatParams as CustomFormattedNumberParams).formatFunction(record.value.value as number);\r\n propertyValue = this._lastValidValue ? { ...this._lastValidValue } : {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: record.value.value,\r\n displayValue,\r\n };\r\n }\r\n }\r\n\r\n return propertyValue;\r\n }\r\n\r\n public get htmlElement(): HTMLElement | null {\r\n return this._inputElement.current;\r\n }\r\n\r\n public get hasFocus(): boolean {\r\n return document.activeElement === this._inputElement.current;\r\n }\r\n\r\n private shouldSetFocus(): boolean {\r\n if (!this.props.setFocus)\r\n return false;\r\n\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n\r\n return (!disabled && !readonly);\r\n }\r\n\r\n private _applyUpdatedValue(userInput: string) {\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n const readonly = (record && !record.isReadonly) ? false : true;\r\n const disabled = (record && !record.isDisabled) ? false : true;\r\n\r\n if (readonly || disabled)\r\n return;\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({\r\n inputValue: userInput,\r\n });\r\n }\r\n\r\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\r\n this._applyUpdatedValue(e.target.value);\r\n };\r\n\r\n /** @internal */\r\n public override componentDidMount() {\r\n this._isMounted = true;\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n\r\n /** @internal */\r\n public override componentWillUnmount() {\r\n this._isMounted = false;\r\n }\r\n\r\n /** @internal */\r\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\r\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\r\n this.setStateFromProps(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n private _getInitialDisplayValue(): string {\r\n const record = this.props.propertyRecord;\r\n let initialDisplayValue = \"\";\r\n let numberValue = 0;\r\n // istanbul ignore else\r\n if (record) {\r\n // istanbul ignore else\r\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\r\n const primitiveValue = record.value;\r\n numberValue = (undefined !== primitiveValue.value) ? primitiveValue.value as number : /* istanbul ignore next */ 0;\r\n // istanbul ignore else\r\n if (primitiveValue.displayValue)\r\n initialDisplayValue = primitiveValue.displayValue;\r\n else\r\n initialDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(numberValue);\r\n }\r\n }\r\n\r\n return initialDisplayValue;\r\n }\r\n\r\n private async setStateFromProps() {\r\n const record = this.props.propertyRecord;\r\n // istanbul ignore next\r\n if (!record || !record.property) {\r\n Logger.logError(UiComponents.loggerCategory(this), \"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n // eslint-disable-next-line no-console\r\n // console.log(\"PropertyRecord must be defined to use CustomNumberPropertyEditor\");\r\n return;\r\n }\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n this._formatParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.CustomFormattedNumber) as CustomFormattedNumberParams;\r\n }\r\n\r\n if (!this._formatParams) {\r\n Logger.logError(UiComponents.loggerCategory(this), `CustomFormattedNumberParams must be defined for property ${record.property.name}`);\r\n // eslint-disable-next-line no-console\r\n // console.log(`CustomFormattedNumberParams must be defined for property ${record!.property!.name}`);\r\n return;\r\n }\r\n\r\n const initialDisplayValue = this._getInitialDisplayValue();\r\n this._lastValidValue = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n value: (record.value as PrimitiveValue).value,\r\n displayValue: initialDisplayValue,\r\n };\r\n let size: number | undefined;\r\n let maxLength: number | undefined;\r\n let iconSpec: string | undefined;\r\n\r\n // istanbul ignore else\r\n if (record.property && record.property.editor && record.property.editor.params) {\r\n const editorSizeParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.InputEditorSize) as InputEditorSizeParams;\r\n // istanbul ignore else\r\n if (editorSizeParams) {\r\n // istanbul ignore else\r\n if (editorSizeParams.size)\r\n size = editorSizeParams.size;\r\n // istanbul ignore else\r\n if (editorSizeParams.maxLength)\r\n maxLength = editorSizeParams.maxLength;\r\n }\r\n\r\n const iconParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.Icon) as IconEditorParams;\r\n if (iconParams) {\r\n iconSpec = iconParams.definition.iconSpec;\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (this._isMounted)\r\n this.setState({ inputValue: initialDisplayValue, size, maxLength, iconSpec });\r\n }\r\n\r\n private _resetToLastValidDisplayValue() {\r\n const initialDisplayValue = (this._lastValidValue && (this._lastValidValue as PrimitiveValue).displayValue) ?? this._getInitialDisplayValue();\r\n this.setState({ inputValue: initialDisplayValue });\r\n }\r\n\r\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\r\n // istanbul ignore else\r\n if (e.key === SpecialKey.Escape) {\r\n const initialDisplayValue = (this._lastValidValue && (this._lastValidValue as PrimitiveValue).displayValue) ?? this._getInitialDisplayValue();\r\n if (initialDisplayValue !== this.state.inputValue) {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n this._resetToLastValidDisplayValue();\r\n } else {\r\n // istanbul ignore else\r\n if (this.props.onCancel)\r\n this.props.onCancel();\r\n }\r\n }\r\n\r\n // istanbul ignore else\r\n if (e.key !== SpecialKey.Enter) {\r\n UiAdmin.messagePresenter.closeInputFieldMessage();\r\n }\r\n };\r\n\r\n // istanbul ignore next\r\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\r\n e.target.select();\r\n };\r\n\r\n /** @internal */\r\n public override render(): React.ReactNode {\r\n const minSize = this.state.size ? this.state.size : 8;\r\n const minWidthStyle: React.CSSProperties = {\r\n minWidth: `${minSize * 0.75}em`,\r\n };\r\n const record = this.props.propertyRecord as PropertyRecord;\r\n if (!record || !this._formatParams)\r\n return null;\r\n\r\n const readOnly = !record.isReadonly ? false : true;\r\n const disabled = !record.isDisabled ? false : true;\r\n\r\n const className = classnames(\"components-cell-editor\", \"components-customnumber-editor\", this.props.className);\r\n\r\n const inputProps: Omit<InputProps, \"size\"> = { // eslint-disable-line deprecation/deprecation\r\n className,\r\n style: this.props.style ? this.props.style : minWidthStyle,\r\n readOnly,\r\n disabled,\r\n maxLength: this.state.maxLength,\r\n value: this.state.inputValue,\r\n onChange: this._updateInputValue,\r\n onBlur: this.props.onBlur,\r\n onFocus: this._onFocus,\r\n setFocus: this.shouldSetFocus(),\r\n onKeyDown: this._onKeyPress,\r\n };\r\n\r\n let reactNode: React.ReactNode;\r\n if (this.state.iconSpec) {\r\n const icon = <Icon iconSpec={this.state.iconSpec} />;\r\n reactNode = (\r\n <IconInput\r\n {...inputProps}\r\n ref={this._inputElement}\r\n icon={icon}\r\n data-testid=\"components-customnumber-editor\"\r\n />\r\n );\r\n } else {\r\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\r\n reactNode = (\r\n <Input\r\n {...inputProps}\r\n ref={this._inputElement}\r\n data-testid=\"components-customnumber-editor\"\r\n size=\"small\"\r\n />\r\n );\r\n }\r\n\r\n return reactNode;\r\n }\r\n}\r\n\r\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\r\n * It uses the [[CustomNumberEditor]] React component.\r\n * @alpha\r\n */\r\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\r\n public get reactNode(): React.ReactNode {\r\n return <CustomNumberEditor />;\r\n }\r\n public override get containerHandlesEscape(): boolean {\r\n return false;\r\n }\r\n}\r\nPropertyEditorManager.registerEditor(StandardTypeNames.Number, CustomNumberPropertyEditor, StandardEditorNames.NumberCustom);\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/components-react",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.167",
|
|
4
4
|
"description": "iTwin.js UI complex components",
|
|
5
5
|
"main": "lib/cjs/components-react.js",
|
|
6
6
|
"module": "lib/esm/components-react.js",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "http://www.bentley.com"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@itwin/appui-abstract": "^3.0.0-dev.
|
|
25
|
-
"@itwin/core-bentley": "^3.0.0-dev.
|
|
26
|
-
"@itwin/core-react": "^3.0.0-dev.
|
|
24
|
+
"@itwin/appui-abstract": "^3.0.0-dev.167",
|
|
25
|
+
"@itwin/core-bentley": "^3.0.0-dev.167",
|
|
26
|
+
"@itwin/core-react": "^3.0.0-dev.167",
|
|
27
27
|
"react": "^17.0.0",
|
|
28
28
|
"react-dom": "^17.0.0"
|
|
29
29
|
},
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@itwin/appui-abstract": "3.0.0-dev.
|
|
36
|
-
"@itwin/build-tools": "3.0.0-dev.
|
|
37
|
-
"@itwin/core-bentley": "3.0.0-dev.
|
|
38
|
-
"@itwin/core-common": "3.0.0-dev.
|
|
39
|
-
"@itwin/core-i18n": "3.0.0-dev.
|
|
40
|
-
"@itwin/core-react": "3.0.0-dev.
|
|
41
|
-
"@itwin/eslint-plugin": "3.0.0-dev.
|
|
35
|
+
"@itwin/appui-abstract": "3.0.0-dev.167",
|
|
36
|
+
"@itwin/build-tools": "3.0.0-dev.167",
|
|
37
|
+
"@itwin/core-bentley": "3.0.0-dev.167",
|
|
38
|
+
"@itwin/core-common": "3.0.0-dev.167",
|
|
39
|
+
"@itwin/core-i18n": "3.0.0-dev.167",
|
|
40
|
+
"@itwin/core-react": "3.0.0-dev.167",
|
|
41
|
+
"@itwin/eslint-plugin": "3.0.0-dev.167",
|
|
42
42
|
"@testing-library/react": "^12.0.0",
|
|
43
43
|
"@testing-library/react-hooks": "^7.0.2",
|
|
44
44
|
"@testing-library/user-event": "^13.2.1",
|