@itwin/components-react 5.7.0 → 5.9.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log - @itwin/components-react
2
2
 
3
+ ## 5.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @itwin/core-react@5.9.0
8
+
9
+ ## 5.8.0
10
+
11
+ ### Patch Changes
12
+
13
+ - @itwin/core-react@5.8.0
14
+
3
15
  ## 5.7.0
4
16
 
5
17
  ### Minor Changes
@@ -16,10 +16,13 @@ interface CustomNumberEditorState {
16
16
  * @alpha
17
17
  */
18
18
  export declare class CustomNumberEditor extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState> implements TypeEditor {
19
+ #private;
19
20
  private _isMounted;
20
21
  private _formatParams;
21
22
  private _inputElement;
22
23
  private _lastValidValue;
24
+ private _lastInputValue;
25
+ private _lastValue;
23
26
  readonly state: Readonly<CustomNumberEditorState>;
24
27
  getPropertyValue(): Promise<PropertyValue | undefined>;
25
28
  get htmlElement(): HTMLElement | null;
@@ -1 +1 @@
1
- {"version":3,"file":"CustomNumberEditor.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AAEnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAOV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAU/B,OAAO,KAAK,EAEV,mBAAmB,EACnB,UAAU,EACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAKhE,UAAU,uBAAuB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,S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OAAO,CAEpD;CACF"}
@@ -5,6 +5,12 @@
5
5
  /** @packageDocumentation
6
6
  * @module PropertyEditors
7
7
  */
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _CustomNumberEditor_instances, _CustomNumberEditor_getPropertyValue;
8
14
  import "./CustomNumberEditor.scss";
9
15
  import classnames from "classnames";
10
16
  import * as React from "react";
@@ -21,6 +27,7 @@ import { PropertyEditorBase } from "./PropertyEditorManager.js";
21
27
  export class CustomNumberEditor extends React.PureComponent {
22
28
  constructor() {
23
29
  super(...arguments);
30
+ _CustomNumberEditor_instances.add(this);
24
31
  this._isMounted = false;
25
32
  this._inputElement = React.createRef();
26
33
  this.state = {
@@ -53,55 +60,20 @@ export class CustomNumberEditor extends React.PureComponent {
53
60
  };
54
61
  }
55
62
  async getPropertyValue() {
56
- const record = this.props.propertyRecord;
57
- let propertyValue;
58
- if (record.isReadonly) {
59
- return {
60
- valueFormat: PropertyValueFormat.Primitive,
61
- value: record.value.value,
62
- displayValue: record.value.displayValue,
63
- };
64
- }
65
- if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
66
- const parseResults = this._formatParams.parseFunction(this.state.inputValue);
67
- if (!parseResults.parseError && undefined !== parseResults.value) {
68
- const newDisplayValue = this._formatParams.formatFunction(parseResults.value);
69
- propertyValue = {
70
- valueFormat: PropertyValueFormat.Primitive,
71
- value: parseResults.value,
72
- displayValue: newDisplayValue,
73
- };
74
- this._lastValidValue = { ...propertyValue };
75
- // 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"
76
- if (newDisplayValue !== this.state.inputValue) {
77
- this.setState({ inputValue: newDisplayValue });
78
- }
79
- }
80
- else {
81
- if (this.htmlElement) {
82
- UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError
83
- ? parseResults.parseError
84
- : UiComponents.translate("errors.unable-to-parse-quantity"));
85
- this.htmlElement.focus();
86
- }
87
- else {
88
- UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError
89
- ? parseResults.parseError
90
- : UiComponents.translate("errors.unable-to-parse-quantity"));
91
- }
92
- const displayValue = record.value.displayValue && record.value.displayValue.length > 0
93
- ? record.value.displayValue
94
- : this._formatParams.formatFunction(record.value.value);
95
- propertyValue = this._lastValidValue
96
- ? { ...this._lastValidValue }
97
- : {
98
- valueFormat: PropertyValueFormat.Primitive,
99
- value: record.value.value,
100
- displayValue,
101
- };
102
- }
63
+ // This is called by the container to commit the value. Format the value.
64
+ this._lastInputValue = undefined;
65
+ this._lastValue = undefined;
66
+ const value = await __classPrivateFieldGet(this, _CustomNumberEditor_instances, "m", _CustomNumberEditor_getPropertyValue).call(this);
67
+ if (this.props.shouldCommitOnChange &&
68
+ this._formatParams &&
69
+ isPrimitiveValue(value) &&
70
+ typeof value.value === "number") {
71
+ const newDisplayValue = this._formatParams.formatFunction(value.value);
72
+ this.setState({
73
+ inputValue: newDisplayValue,
74
+ });
103
75
  }
104
- return propertyValue;
76
+ return value;
105
77
  }
106
78
  get htmlElement() {
107
79
  return this._inputElement.current;
@@ -126,18 +98,34 @@ export class CustomNumberEditor extends React.PureComponent {
126
98
  if (this._isMounted)
127
99
  this.setState({
128
100
  inputValue: userInput,
101
+ }, async () => {
102
+ if (!this.props.shouldCommitOnChange)
103
+ return;
104
+ if (!this.props.onCommit)
105
+ return;
106
+ if (!this.props.propertyRecord)
107
+ return;
108
+ const newValue = await __classPrivateFieldGet(this, _CustomNumberEditor_instances, "m", _CustomNumberEditor_getPropertyValue).call(this);
109
+ if (!newValue)
110
+ return;
111
+ this._lastInputValue = this.state.inputValue;
112
+ this._lastValue = newValue;
113
+ this.props.onCommit({
114
+ propertyRecord: this.props.propertyRecord,
115
+ newValue,
116
+ });
129
117
  });
130
118
  }
131
119
  componentDidMount() {
132
120
  this._isMounted = true;
133
- void this.setStateFromProps();
121
+ this.setStateFromProps();
134
122
  }
135
123
  componentWillUnmount() {
136
124
  this._isMounted = false;
137
125
  }
138
126
  componentDidUpdate(prevProps) {
139
127
  if (this.props.propertyRecord !== prevProps.propertyRecord) {
140
- void this.setStateFromProps();
128
+ this.setStateFromProps();
141
129
  }
142
130
  }
143
131
  _getInitialDisplayValue() {
@@ -159,7 +147,9 @@ export class CustomNumberEditor extends React.PureComponent {
159
147
  }
160
148
  return initialDisplayValue;
161
149
  }
162
- async setStateFromProps() {
150
+ setStateFromProps() {
151
+ if (!this._isMounted)
152
+ return;
163
153
  const record = this.props.propertyRecord;
164
154
  if (!record || !record.property) {
165
155
  Logger.logError(UiComponents.loggerCategory("CustomNumberEditor"), "PropertyRecord must be defined to use CustomNumberPropertyEditor");
@@ -204,13 +194,21 @@ export class CustomNumberEditor extends React.PureComponent {
204
194
  iconSpec = iconNodeParam.icon;
205
195
  }
206
196
  }
207
- if (this._isMounted)
208
- this.setState({
209
- inputValue: initialDisplayValue,
210
- size,
211
- maxLength,
212
- iconSpec,
213
- });
197
+ let inputValue = initialDisplayValue;
198
+ if (this.props.shouldCommitOnChange &&
199
+ this._lastInputValue &&
200
+ isPrimitiveValue(this._lastValue) &&
201
+ isPrimitiveValue(this.props.propertyRecord?.value) &&
202
+ this._lastValue.value === this.props.propertyRecord.value.value) {
203
+ // If the value matches the user-entered value - keep it unformatted.
204
+ inputValue = this._lastInputValue;
205
+ }
206
+ this.setState({
207
+ inputValue,
208
+ size,
209
+ maxLength,
210
+ iconSpec,
211
+ });
214
212
  }
215
213
  _resetToLastValidDisplayValue() {
216
214
  const initialDisplayValue = (this._lastValidValue &&
@@ -249,6 +247,61 @@ export class CustomNumberEditor extends React.PureComponent {
249
247
  return (React.createElement(LockNumberEditor, { ...inputProps, ref: this._inputElement, id: this.props.propertyRecord?.property.name, icon: icon, decoration: decoration }));
250
248
  }
251
249
  }
250
+ _CustomNumberEditor_instances = new WeakSet(), _CustomNumberEditor_getPropertyValue = async function _CustomNumberEditor_getPropertyValue() {
251
+ // This is called by the editor to get the current input value as a PropertyValue.
252
+ const record = this.props.propertyRecord;
253
+ let propertyValue;
254
+ if (record.isReadonly) {
255
+ return {
256
+ valueFormat: PropertyValueFormat.Primitive,
257
+ value: record.value.value,
258
+ displayValue: record.value.displayValue,
259
+ };
260
+ }
261
+ if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
262
+ const parseResults = this._formatParams.parseFunction(this.state.inputValue);
263
+ if (!parseResults.parseError && undefined !== parseResults.value) {
264
+ const newDisplayValue = this._formatParams.formatFunction(parseResults.value);
265
+ propertyValue = {
266
+ valueFormat: PropertyValueFormat.Primitive,
267
+ value: parseResults.value,
268
+ displayValue: newDisplayValue,
269
+ };
270
+ this._lastValidValue = { ...propertyValue };
271
+ // 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"
272
+ if (
273
+ // This should not happen in a getter, for now fix only if shouldCommitOnChange is true.
274
+ !this.props.shouldCommitOnChange &&
275
+ newDisplayValue !== this.state.inputValue) {
276
+ this.setState({ inputValue: newDisplayValue });
277
+ }
278
+ }
279
+ else {
280
+ if (this.htmlElement) {
281
+ UiAdmin.messagePresenter.displayInputFieldMessage(this.htmlElement, MessageSeverity.Error, parseResults.parseError
282
+ ? parseResults.parseError
283
+ : UiComponents.translate("errors.unable-to-parse-quantity"));
284
+ this.htmlElement.focus();
285
+ }
286
+ else {
287
+ UiAdmin.messagePresenter.displayMessage(MessageSeverity.Error, parseResults.parseError
288
+ ? parseResults.parseError
289
+ : UiComponents.translate("errors.unable-to-parse-quantity"));
290
+ }
291
+ const displayValue = record.value.displayValue && record.value.displayValue.length > 0
292
+ ? record.value.displayValue
293
+ : this._formatParams.formatFunction(record.value.value);
294
+ propertyValue = this._lastValidValue
295
+ ? { ...this._lastValidValue }
296
+ : {
297
+ valueFormat: PropertyValueFormat.Primitive,
298
+ value: record.value.value,
299
+ displayValue,
300
+ };
301
+ }
302
+ }
303
+ return propertyValue;
304
+ };
252
305
  /** Custom Property Editor registered for the "number" type name and the "number-custom" editor name.
253
306
  * It uses the [[CustomNumberEditor]] React component.
254
307
  * @alpha
@@ -276,4 +329,7 @@ const LockNumberEditor = React.forwardRef(function LockNumberEditor(props, forwa
276
329
  }
277
330
  return (React.createElement(Input, { ...rest, ref: forwardedRef, "data-testid": "components-customnumber-editor", size: "small" }));
278
331
  });
332
+ function isPrimitiveValue(value) {
333
+ return value?.valueFormat === PropertyValueFormat.Primitive;
334
+ }
279
335
  //# sourceMappingURL=CustomNumberEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAU7C,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,OAAO,GACR,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,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAYhE;;GAEG;AACH,MAAM,OAAO,kBACX,SAAQ,KAAK,CAAC,aAA2D;IAD3E;;QAIU,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C;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAOD,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAGvC,SAAS,gBAAgB,CAAC,KAAK,EAAE,YAAY;IAC7C,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,gCAAgC,EAC5C,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,gCAAgC,GAC5C,CACH,CAAC;IACJ,CAAC;IACD,OAAO,CACL,oBAAC,KAAK,OACA,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC,CAAC,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 \"./CustomNumberEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type {\n CustomFormattedNumberParams,\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n MessageSeverity,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n UiAdmin,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input, InputWithDecorations } from \"@itwin/itwinui-react\";\nimport { UiComponents } from \"../UiComponents.js\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport type { IconNodeEditorParams } from \"../../internal.js\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\ninterface CustomNumberEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: React.ReactNode;\n}\n\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\n * @alpha\n */\nexport class CustomNumberEditor\n extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _formatParams: CustomFormattedNumberParams | undefined;\n private _inputElement = React.createRef<HTMLInputElement>();\n private _lastValidValue: PropertyValue | undefined;\n\n public override readonly state: Readonly<CustomNumberEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord as PropertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record.isReadonly) {\n return {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: (record.value as PrimitiveValue).displayValue,\n };\n }\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const parseResults = (\n this._formatParams as CustomFormattedNumberParams\n ).parseFunction(this.state.inputValue);\n if (!parseResults.parseError && undefined !== parseResults.value) {\n const newDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(parseResults.value as number);\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: parseResults.value,\n displayValue: newDisplayValue,\n };\n this._lastValidValue = { ...propertyValue };\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\"\n if (newDisplayValue !== this.state.inputValue) {\n this.setState({ inputValue: newDisplayValue });\n }\n } else {\n if (this.htmlElement) {\n UiAdmin.messagePresenter.displayInputFieldMessage(\n this.htmlElement,\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : UiComponents.translate(\"errors.unable-to-parse-quantity\")\n );\n this.htmlElement.focus();\n } else {\n UiAdmin.messagePresenter.displayMessage(\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : UiComponents.translate(\"errors.unable-to-parse-quantity\")\n );\n }\n\n const displayValue =\n record.value.displayValue && record.value.displayValue.length > 0\n ? record.value.displayValue\n : (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(record.value.value as number);\n propertyValue = this._lastValidValue\n ? { ...this._lastValidValue }\n : {\n valueFormat: PropertyValueFormat.Primitive,\n value: record.value.value,\n displayValue,\n };\n }\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 shouldSetFocus(): boolean {\n if (!this.props.setFocus) return false;\n\n const record = this.props.propertyRecord as PropertyRecord;\n const disabled = record && !record.isDisabled ? false : true;\n const readonly = record && !record.isReadonly ? false : true;\n\n return !disabled && !readonly;\n }\n\n private _applyUpdatedValue(userInput: string) {\n const record = this.props.propertyRecord as PropertyRecord;\n const readonly = record && !record.isReadonly ? false : true;\n const disabled = record && !record.isDisabled ? false : true;\n\n if (readonly || disabled) return;\n\n if (this._isMounted)\n this.setState({\n inputValue: userInput,\n });\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n this._applyUpdatedValue(e.target.value);\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 public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private _getInitialDisplayValue(): string {\n const record = this.props.propertyRecord;\n let initialDisplayValue = \"\";\n let numberValue = 0;\n if (record) {\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\n const primitiveValue = record.value;\n numberValue =\n undefined !== primitiveValue.value\n ? (primitiveValue.value as number)\n : 0;\n if (primitiveValue.displayValue)\n initialDisplayValue = primitiveValue.displayValue;\n else\n initialDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(numberValue);\n }\n }\n\n return initialDisplayValue;\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n if (!record || !record.property) {\n Logger.logError(\n UiComponents.loggerCategory(\"CustomNumberEditor\"),\n \"PropertyRecord must be defined to use CustomNumberPropertyEditor\"\n );\n return;\n }\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n this._formatParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type ===\n PropertyEditorParamTypes.CustomFormattedNumber.valueOf()\n ) as CustomFormattedNumberParams;\n }\n\n if (!this._formatParams) {\n Logger.logError(\n UiComponents.loggerCategory(\"CustomNumberEditor\"),\n `CustomFormattedNumberParams must be defined for property ${record.property.name}`\n );\n return;\n }\n\n const initialDisplayValue = this._getInitialDisplayValue();\n this._lastValidValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: initialDisplayValue,\n };\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: React.ReactNode | undefined;\n\n if (\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 const iconNodeParam = record.property.editor.params.find(\n (param): param is IconNodeEditorParams =>\n param.type ===\n (\"appui-icon-node\" satisfies IconNodeEditorParams[\"type\"])\n );\n if (iconNodeParam) {\n iconSpec = iconNodeParam.icon;\n }\n }\n\n if (this._isMounted)\n this.setState({\n inputValue: initialDisplayValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n private _resetToLastValidDisplayValue() {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n this._getInitialDisplayValue();\n this.setState({ inputValue: initialDisplayValue });\n }\n\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === Key.Escape.valueOf()) {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n this._getInitialDisplayValue();\n if (initialDisplayValue !== this.state.inputValue) {\n e.preventDefault();\n e.stopPropagation();\n this._resetToLastValidDisplayValue();\n } else {\n if (this.props.onCancel) this.props.onCancel();\n }\n }\n\n if (e.key !== Key.Enter.valueOf()) {\n UiAdmin.messagePresenter.closeInputFieldMessage();\n }\n };\n\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select();\n };\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const record = this.props.propertyRecord as PropertyRecord;\n if (!record || !this._formatParams) return null;\n\n const readOnly = !record.isReadonly ? false : true;\n const disabled = !record.isDisabled ? false : true;\n\n const className = classnames(\n \"components-cell-editor\",\n \"components-customnumber-editor\",\n this.props.className\n );\n\n const inputProps: Omit<InputProps, \"size\"> = {\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly,\n disabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onChange: this._updateInputValue,\n onBlur: this.props.onBlur,\n onFocus: this._onFocus,\n autoFocus: this.shouldSetFocus(),\n onKeyDown: this._onKeyPress,\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\n return (\n <LockNumberEditor\n {...inputProps}\n ref={this._inputElement}\n id={this.props.propertyRecord?.property.name}\n icon={icon}\n decoration={decoration}\n />\n );\n }\n}\n\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\n * It uses the [[CustomNumberEditor]] React component.\n * @alpha\n */\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <CustomNumberEditor />;\n }\n public override get containerHandlesEscape(): boolean {\n return false;\n }\n}\n\ninterface LockNumberEditorProps extends InputProps {\n icon?: React.ReactNode;\n decoration?: React.ReactNode;\n}\n\nconst LockNumberEditor = React.forwardRef<\n HTMLInputElement,\n LockNumberEditorProps\n>(function LockNumberEditor(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-customnumber-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-customnumber-editor\"\n />\n );\n }\n return (\n <Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n />\n );\n});\n"]}
1
+ {"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;AAEH,OAAO,2BAA2B,CAAC;AACnC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAU7C,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,mBAAmB,EACnB,OAAO,GACR,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,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAYhE;;GAEG;AACH,MAAM,OAAO,kBACX,SAAQ,KAAK,CAAC,aAA2D;IAD3E;;;QAIU,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAOnC,UAAK,GAAsC;YAClE,UAAU,EAAE,EAAE;SACf,CAAC;QAgJM,sBAAiB,GAAG,CAAC,CAAsC,EAAE,EAAE;YACrE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC,CAAC;QA6IM,gBAAW,GAAG,CAAC,CAAwC,EAAE,EAAE;YACjE,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;gBACnC,MAAM,mBAAmB,GACvB,CAAC,IAAI,CAAC,eAAe;oBAClB,IAAI,CAAC,eAAkC,CAAC,YAA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;IAC7C,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,gCAAgC,EAC5C,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,gCAAgC,GAC5C,CACH,CAAC;IACJ,CAAC;IACD,OAAO,CACL,oBAAC,KAAK,OACA,IAAI,EACR,GAAG,EAAE,YAAY,iBACL,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,KAAqB;IAC7C,OAAO,KAAK,EAAE,WAAW,KAAK,mBAAmB,CAAC,SAAS,CAAC;AAC9D,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 \"./CustomNumberEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type {\n CustomFormattedNumberParams,\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n MessageSeverity,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n UiAdmin,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input, InputWithDecorations } from \"@itwin/itwinui-react\";\nimport { UiComponents } from \"../UiComponents.js\";\nimport type {\n InternalInputEditorProps,\n PropertyEditorProps,\n TypeEditor,\n} from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport type { IconNodeEditorParams } from \"../../internal.js\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\ninterface CustomNumberEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: React.ReactNode;\n}\n\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\n * @alpha\n */\nexport class CustomNumberEditor\n extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _formatParams: CustomFormattedNumberParams | undefined;\n private _inputElement = React.createRef<HTMLInputElement>();\n private _lastValidValue: PropertyValue | undefined;\n\n // Used to track the last user typed value.\n private _lastInputValue: string | undefined;\n private _lastValue: PropertyValue | undefined;\n\n public override readonly state: Readonly<CustomNumberEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n // This is called by the container to commit the value. Format the value.\n this._lastInputValue = undefined;\n this._lastValue = undefined;\n\n const value = await this.#getPropertyValue();\n\n if (\n this.props.shouldCommitOnChange &&\n this._formatParams &&\n isPrimitiveValue(value) &&\n typeof value.value === \"number\"\n ) {\n const newDisplayValue = this._formatParams.formatFunction(value.value);\n this.setState({\n inputValue: newDisplayValue,\n });\n }\n return value;\n }\n\n async #getPropertyValue(): Promise<PropertyValue | undefined> {\n // This is called by the editor to get the current input value as a PropertyValue.\n const record = this.props.propertyRecord as PropertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record.isReadonly) {\n return {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: (record.value as PrimitiveValue).displayValue,\n };\n }\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const parseResults = (\n this._formatParams as CustomFormattedNumberParams\n ).parseFunction(this.state.inputValue);\n if (!parseResults.parseError && undefined !== parseResults.value) {\n const newDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(parseResults.value as number);\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: parseResults.value,\n displayValue: newDisplayValue,\n };\n this._lastValidValue = { ...propertyValue };\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\"\n if (\n // This should not happen in a getter, for now fix only if shouldCommitOnChange is true.\n !this.props.shouldCommitOnChange &&\n newDisplayValue !== this.state.inputValue\n ) {\n this.setState({ inputValue: newDisplayValue });\n }\n } else {\n if (this.htmlElement) {\n UiAdmin.messagePresenter.displayInputFieldMessage(\n this.htmlElement,\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : UiComponents.translate(\"errors.unable-to-parse-quantity\")\n );\n this.htmlElement.focus();\n } else {\n UiAdmin.messagePresenter.displayMessage(\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : UiComponents.translate(\"errors.unable-to-parse-quantity\")\n );\n }\n\n const displayValue =\n record.value.displayValue && record.value.displayValue.length > 0\n ? record.value.displayValue\n : (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(record.value.value as number);\n propertyValue = this._lastValidValue\n ? { ...this._lastValidValue }\n : {\n valueFormat: PropertyValueFormat.Primitive,\n value: record.value.value,\n displayValue,\n };\n }\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 shouldSetFocus(): boolean {\n if (!this.props.setFocus) return false;\n\n const record = this.props.propertyRecord as PropertyRecord;\n const disabled = record && !record.isDisabled ? false : true;\n const readonly = record && !record.isReadonly ? false : true;\n\n return !disabled && !readonly;\n }\n\n private _applyUpdatedValue(userInput: string) {\n const record = this.props.propertyRecord as PropertyRecord;\n const readonly = record && !record.isReadonly ? false : true;\n const disabled = record && !record.isDisabled ? false : true;\n\n if (readonly || disabled) return;\n\n if (this._isMounted)\n this.setState(\n {\n inputValue: userInput,\n },\n async () => {\n if (!this.props.shouldCommitOnChange) return;\n if (!this.props.onCommit) return;\n if (!this.props.propertyRecord) return;\n\n const newValue = await this.#getPropertyValue();\n if (!newValue) return;\n\n this._lastInputValue = this.state.inputValue;\n this._lastValue = newValue;\n this.props.onCommit({\n propertyRecord: this.props.propertyRecord,\n newValue,\n });\n }\n );\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n this._applyUpdatedValue(e.target.value);\n };\n\n public override componentDidMount() {\n this._isMounted = true;\n this.setStateFromProps();\n }\n\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n this.setStateFromProps();\n }\n }\n\n private _getInitialDisplayValue(): string {\n const record = this.props.propertyRecord;\n let initialDisplayValue = \"\";\n let numberValue = 0;\n if (record) {\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\n const primitiveValue = record.value;\n numberValue =\n undefined !== primitiveValue.value\n ? (primitiveValue.value as number)\n : 0;\n if (primitiveValue.displayValue)\n initialDisplayValue = primitiveValue.displayValue;\n else\n initialDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(numberValue);\n }\n }\n\n return initialDisplayValue;\n }\n\n private setStateFromProps() {\n if (!this._isMounted) return;\n\n const record = this.props.propertyRecord;\n if (!record || !record.property) {\n Logger.logError(\n UiComponents.loggerCategory(\"CustomNumberEditor\"),\n \"PropertyRecord must be defined to use CustomNumberPropertyEditor\"\n );\n return;\n }\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n this._formatParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type ===\n PropertyEditorParamTypes.CustomFormattedNumber.valueOf()\n ) as CustomFormattedNumberParams;\n }\n\n if (!this._formatParams) {\n Logger.logError(\n UiComponents.loggerCategory(\"CustomNumberEditor\"),\n `CustomFormattedNumberParams must be defined for property ${record.property.name}`\n );\n return;\n }\n\n const initialDisplayValue = this._getInitialDisplayValue();\n this._lastValidValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: initialDisplayValue,\n };\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: React.ReactNode | undefined;\n\n if (\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 const iconNodeParam = record.property.editor.params.find(\n (param): param is IconNodeEditorParams =>\n param.type ===\n (\"appui-icon-node\" satisfies IconNodeEditorParams[\"type\"])\n );\n if (iconNodeParam) {\n iconSpec = iconNodeParam.icon;\n }\n }\n\n let inputValue = initialDisplayValue;\n if (\n this.props.shouldCommitOnChange &&\n this._lastInputValue &&\n isPrimitiveValue(this._lastValue) &&\n isPrimitiveValue(this.props.propertyRecord?.value) &&\n this._lastValue.value === this.props.propertyRecord.value.value\n ) {\n // If the value matches the user-entered value - keep it unformatted.\n inputValue = this._lastInputValue;\n }\n\n this.setState({\n inputValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n private _resetToLastValidDisplayValue() {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n this._getInitialDisplayValue();\n this.setState({ inputValue: initialDisplayValue });\n }\n\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === Key.Escape.valueOf()) {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n this._getInitialDisplayValue();\n if (initialDisplayValue !== this.state.inputValue) {\n e.preventDefault();\n e.stopPropagation();\n this._resetToLastValidDisplayValue();\n } else {\n if (this.props.onCancel) this.props.onCancel();\n }\n }\n\n if (e.key !== Key.Enter.valueOf()) {\n UiAdmin.messagePresenter.closeInputFieldMessage();\n }\n };\n\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select();\n };\n\n public override render(): React.ReactNode {\n const { decoration } = this.props as InternalInputEditorProps;\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const record = this.props.propertyRecord as PropertyRecord;\n if (!record || !this._formatParams) return null;\n\n const readOnly = !record.isReadonly ? false : true;\n const disabled = !record.isDisabled ? false : true;\n\n const className = classnames(\n \"components-cell-editor\",\n \"components-customnumber-editor\",\n this.props.className\n );\n\n const inputProps: Omit<InputProps, \"size\"> = {\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly,\n disabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onChange: this._updateInputValue,\n onBlur: this.props.onBlur,\n onFocus: this._onFocus,\n autoFocus: this.shouldSetFocus(),\n onKeyDown: this._onKeyPress,\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\n return (\n <LockNumberEditor\n {...inputProps}\n ref={this._inputElement}\n id={this.props.propertyRecord?.property.name}\n icon={icon}\n decoration={decoration}\n />\n );\n }\n}\n\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\n * It uses the [[CustomNumberEditor]] React component.\n * @alpha\n */\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <CustomNumberEditor />;\n }\n public override get containerHandlesEscape(): boolean {\n return false;\n }\n}\n\ninterface LockNumberEditorProps extends InputProps {\n icon?: React.ReactNode;\n decoration?: React.ReactNode;\n}\n\nconst LockNumberEditor = React.forwardRef<\n HTMLInputElement,\n LockNumberEditorProps\n>(function LockNumberEditor(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-customnumber-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-customnumber-editor\"\n />\n );\n }\n return (\n <Input\n {...rest}\n ref={forwardedRef}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n />\n );\n});\n\nfunction isPrimitiveValue(value?: PropertyValue): value is PrimitiveValue {\n return value?.valueFormat === PropertyValueFormat.Primitive;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/components-react",
3
- "version": "5.7.0",
3
+ "version": "5.9.0",
4
4
  "description": "A react component library of iTwin.js UI data-oriented components",
5
5
  "type": "module",
6
6
  "types": "./lib/components-react.d.ts",
@@ -40,7 +40,7 @@
40
40
  "@itwin/itwinui-react": "^3.15.0",
41
41
  "react": "^18.0.0",
42
42
  "react-dom": "^18.0.0",
43
- "@itwin/core-react": "5.7.0"
43
+ "@itwin/core-react": "5.9.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@itwin/appui-abstract": "rc",
@@ -49,7 +49,7 @@
49
49
  "@itwin/core-common": "rc",
50
50
  "@itwin/core-i18n": "rc",
51
51
  "@itwin/eslint-plugin": "5.1.0",
52
- "@itwin/itwinui-react": "^3.17.0",
52
+ "@itwin/itwinui-react": "^3.18.3",
53
53
  "@testing-library/dom": "^10.1.0",
54
54
  "@testing-library/react": "^15.0.7",
55
55
  "@testing-library/user-event": "^14.5.2",
@@ -76,7 +76,7 @@
76
76
  "typescript": "~5.6.2",
77
77
  "upath": "^2.0.1",
78
78
  "vitest": "^3.0.6",
79
- "@itwin/core-react": "5.7.0"
79
+ "@itwin/core-react": "5.9.0"
80
80
  },
81
81
  "dependencies": {
82
82
  "@itwin/itwinui-icons-react": "^2.8.0",