@itwin/components-react 5.6.0 → 5.8.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/lib/components-react/editors/CustomNumberEditor.d.ts +3 -1
  3. package/lib/components-react/editors/CustomNumberEditor.d.ts.map +1 -1
  4. package/lib/components-react/editors/CustomNumberEditor.js +133 -69
  5. package/lib/components-react/editors/CustomNumberEditor.js.map +1 -1
  6. package/lib/components-react/editors/EditorContainer.d.ts +6 -0
  7. package/lib/components-react/editors/EditorContainer.d.ts.map +1 -1
  8. package/lib/components-react/editors/EditorContainer.js.map +1 -1
  9. package/lib/components-react/editors/NumericInputEditor.d.ts.map +1 -1
  10. package/lib/components-react/editors/NumericInputEditor.js +22 -3
  11. package/lib/components-react/editors/NumericInputEditor.js.map +1 -1
  12. package/lib/components-react/editors/PropertyEditorManager.d.ts +4 -2
  13. package/lib/components-react/editors/PropertyEditorManager.d.ts.map +1 -1
  14. package/lib/components-react/editors/PropertyEditorManager.js +28 -18
  15. package/lib/components-react/editors/PropertyEditorManager.js.map +1 -1
  16. package/lib/components-react/editors/TextEditor.d.ts.map +1 -1
  17. package/lib/components-react/editors/TextEditor.js +22 -14
  18. package/lib/components-react/editors/TextEditor.js.map +1 -1
  19. package/lib/components-react/editors/registerEditors.d.ts.map +1 -1
  20. package/lib/components-react/editors/registerEditors.js +26 -26
  21. package/lib/components-react/editors/registerEditors.js.map +1 -1
  22. package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.d.ts +5 -3
  23. package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.d.ts.map +1 -1
  24. package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.js +7 -2
  25. package/lib/components-react/new-editors/editors-registry/EditorsRegistryProvider.js.map +1 -1
  26. package/lib/components-react/new-editors/interop/old-editors/CustomNumber.d.ts +10 -0
  27. package/lib/components-react/new-editors/interop/old-editors/CustomNumber.d.ts.map +1 -1
  28. package/lib/components-react/new-editors/interop/old-editors/CustomNumber.js +4 -2
  29. package/lib/components-react/new-editors/interop/old-editors/CustomNumber.js.map +1 -1
  30. package/lib/internal.d.ts +5 -1
  31. package/lib/internal.d.ts.map +1 -1
  32. package/lib/internal.js +4 -5
  33. package/lib/internal.js.map +1 -1
  34. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # Change Log - @itwin/components-react
2
2
 
3
+ ## 5.8.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @itwin/core-react@5.8.0
8
+
9
+ ## 5.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - fd58c9f: Updated the `editors` prop of `EditorsRegistryProvider` component. You can now either supply a list of editors or provide a function that customizes the current list of editors, allowing full control over the final set of editors.
14
+
15
+ ```tsx
16
+ // New editors are higher priority than existing ones.
17
+ <EditorsRegistryProvider editors={(editors) => [...newEditors, ...editors]} />
18
+
19
+ // New editors are lower priority than existing ones.
20
+ <EditorsRegistryProvider editors={(editors) => [...editors, ...newEditors]} />
21
+
22
+ // Filter the editors.
23
+ <EditorsRegistryProvider
24
+ editors={(editors) =>
25
+ editors.filter((e) =>
26
+ e.applies(
27
+ {
28
+ type: "bool",
29
+ },
30
+ undefined
31
+ )
32
+ )
33
+ }
34
+ />
35
+ ```
36
+
37
+ ### Patch Changes
38
+
39
+ - @itwin/core-react@5.7.0
40
+
3
41
  ## 5.6.0
4
42
 
5
43
  ### Patch Changes
@@ -6,7 +6,6 @@ import * as React from "react";
6
6
  import type { PropertyValue } from "@itwin/appui-abstract";
7
7
  import type { PropertyEditorProps, TypeEditor } from "./EditorContainer.js";
8
8
  import { PropertyEditorBase } from "./PropertyEditorManager.js";
9
- /** @internal */
10
9
  interface CustomNumberEditorState {
11
10
  inputValue: string;
12
11
  size?: number;
@@ -17,10 +16,13 @@ interface CustomNumberEditorState {
17
16
  * @alpha
18
17
  */
19
18
  export declare class CustomNumberEditor extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState> implements TypeEditor {
19
+ #private;
20
20
  private _isMounted;
21
21
  private _formatParams;
22
22
  private _inputElement;
23
23
  private _lastValidValue;
24
+ private _lastInputValue;
25
+ private _lastValue;
24
26
  readonly state: Readonly<CustomNumberEditorState>;
25
27
  getPropertyValue(): Promise<PropertyValue | undefined>;
26
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;AAa/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,gBAAgB;AAChB,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,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,kBACX,SAAQ,KAAK,CAAC,aAAa,CAAC,mBAAmB,EAAE,uBAAuB,CACxE,YAAW,UAAU;IAErB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,aAAa,CAAuC;IAC5D,OAAO,CAAC,eAAe,CAA4B;IAEnD,SAAyB,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAE/D;IAEW,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAoEnE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAA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AC,aAAa,CAAuC;IAC5D,OAAO,CAAC,eAAe,CAA4B;IAGnD,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,UAAU,CAA4B;IAE9C,SAAyB,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAE/D;IAEW,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IA8FnE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,iBAAiB,CAEvB;IAEc,iBAAiB;IAKjB,oBAAoB;IAIpB,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;IAMjE,OAAO,CAAC,uBAAuB;IAuB/B,OAAO,CAAC,iBAAiB;IA6FzB,OAAO,CAAC,6BAA6B;IAQrC,OAAO,CAAC,WAAW,CAkBjB;IAEF,OAAO,CAAC,QAAQ,CAEd;IAEc,MAAM,IAAI,KAAK,CAAC,SAAS;CA+C1C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;IACD,IAAoB,sBAAsB,IAAI,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";
@@ -12,7 +18,7 @@ import { Key } from "ts-key-enum";
12
18
  import { Logger } from "@itwin/core-bentley";
13
19
  import { MessageSeverity, PropertyEditorParamTypes, PropertyValueFormat, UiAdmin, } from "@itwin/appui-abstract";
14
20
  import { Icon, IconInput } from "@itwin/core-react";
15
- import { Input } from "@itwin/itwinui-react";
21
+ import { Input, InputWithDecorations } from "@itwin/itwinui-react";
16
22
  import { UiComponents } from "../UiComponents.js";
17
23
  import { PropertyEditorBase } from "./PropertyEditorManager.js";
18
24
  /** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.
@@ -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 &&
@@ -219,6 +217,7 @@ export class CustomNumberEditor extends React.PureComponent {
219
217
  this.setState({ inputValue: initialDisplayValue });
220
218
  }
221
219
  render() {
220
+ const { decoration } = this.props;
222
221
  const minSize = this.state.size ? this.state.size : 8;
223
222
  const minWidthStyle = {
224
223
  minWidth: `${minSize * 0.75}em`,
@@ -242,20 +241,67 @@ export class CustomNumberEditor extends React.PureComponent {
242
241
  autoFocus: this.shouldSetFocus(),
243
242
  onKeyDown: this._onKeyPress,
244
243
  };
245
- let reactNode;
246
- if (this.state.iconSpec) {
247
- // eslint-disable-next-line @typescript-eslint/no-deprecated
248
- const icon = React.createElement(Icon, { iconSpec: this.state.iconSpec });
249
- reactNode = (
250
- // eslint-disable-next-line @typescript-eslint/no-deprecated
251
- React.createElement(IconInput, { ...inputProps, ref: this._inputElement, icon: icon, "data-testid": "components-customnumber-editor" }));
244
+ const icon = this.state.iconSpec ? (
245
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
246
+ React.createElement(Icon, { iconSpec: this.state.iconSpec })) : undefined;
247
+ return (React.createElement(LockNumberEditor, { ...inputProps, ref: this._inputElement, id: this.props.propertyRecord?.property.name, icon: icon, decoration: decoration }));
248
+ }
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
+ }
252
278
  }
253
279
  else {
254
- reactNode = (React.createElement(Input, { ...inputProps, ref: this._inputElement, "data-testid": "components-customnumber-editor", size: "small", id: this.props.propertyRecord?.property.name }));
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
+ };
255
301
  }
256
- return reactNode;
257
302
  }
258
- }
303
+ return propertyValue;
304
+ };
259
305
  /** Custom Property Editor registered for the "number" type name and the "number-custom" editor name.
260
306
  * It uses the [[CustomNumberEditor]] React component.
261
307
  * @alpha
@@ -268,4 +314,22 @@ export class CustomNumberPropertyEditor extends PropertyEditorBase {
268
314
  return false;
269
315
  }
270
316
  }
317
+ const LockNumberEditor = React.forwardRef(function LockNumberEditor(props, forwardedRef) {
318
+ const { icon, decoration, ...rest } = props;
319
+ if (decoration) {
320
+ return (React.createElement(InputWithDecorations, { size: "small" },
321
+ icon && (React.createElement(InputWithDecorations.Icon, { size: "small" }, icon)),
322
+ React.createElement(InputWithDecorations.Input, { ...rest, ref: forwardedRef, "data-testid": "components-customnumber-editor", size: "small" }),
323
+ decoration));
324
+ }
325
+ if (icon) {
326
+ return (
327
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
328
+ React.createElement(IconInput, { ...rest, ref: forwardedRef, icon: icon, "data-testid": "components-customnumber-editor" }));
329
+ }
330
+ return (React.createElement(Input, { ...rest, ref: forwardedRef, "data-testid": "components-customnumber-editor", size: "small" }));
331
+ });
332
+ function isPrimitiveValue(value) {
333
+ return value?.valueFormat === PropertyValueFormat.Primitive;
334
+ }
271
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,MAAM,sBAAsB,CAAC;AAI7C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAWhE;;GAEG;AACH,MAAM,OAAO,kBACX,SAAQ,KAAK,CAAC,aAA2D;IAD3E;;QAIU,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAGnC,UAAK,GAAsC;YAClE,UAAU,EAAE,EAAE;SACf,CAAC;QAqGM,sBAAiB,GAAG,CAAC,CAAsC,EAAE,EAAE;YACrE,I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AAC;IACf,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\nimport \"./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 } from \"@itwin/itwinui-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\nimport { UiComponents } from \"../UiComponents.js\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer.js\";\nimport { PropertyEditorBase } from \"./PropertyEditorManager.js\";\nimport type { IconNodeEditorParams } from \"../../internal.js\";\n\n/** @internal */\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 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 let reactNode: React.ReactNode;\n if (this.state.iconSpec) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const icon = <Icon iconSpec={this.state.iconSpec} />;\n reactNode = (\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n <IconInput\n {...inputProps}\n ref={this._inputElement}\n icon={icon}\n data-testid=\"components-customnumber-editor\"\n />\n );\n } else {\n reactNode = (\n <Input\n {...inputProps}\n ref={this._inputElement}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n id={this.props.propertyRecord?.property.name}\n />\n );\n }\n\n return reactNode;\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"]}
1
+ {"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GA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L,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"]}
@@ -34,6 +34,12 @@ export interface PropertyEditorProps extends CommonProps {
34
34
  */
35
35
  shouldCommitOnChange?: boolean;
36
36
  }
37
+ /** Workaround to add internal props without major refactor, since editors uses both composition and inheritance.
38
+ * @internal
39
+ */
40
+ export interface InternalInputEditorProps {
41
+ decoration?: React.ReactNode;
42
+ }
37
43
  /** [[EditorContainer]] React component properties
38
44
  * @public
39
45
  * @deprecated in 4.17.0. Use `React.ComponentProps<typeof EditorContainer>`
@@ -1 +1 @@
1
- {"version":3,"file":"EditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,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AMD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,gBAAgB,EAAE,MAAM,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAC3D,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBA8L1D"}
1
+ {"version":3,"file":"EditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAGV,cAAc,EACd,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOrD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,sCAAsC;IACtC,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;GAEG;AAEH,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,kCAAkC;IAClC,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,yBAAyB;IACzB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC/C,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,uBAAuB;IACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAC3C,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B;AAED;;;GAGG;AAEH,MAAM,WAAW,oBAAqB,SAAQ,WAAW;IACvD,kCAAkC;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,QAAQ,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC9C,yBAAyB;IACzB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB,gBAAgB;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAMD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,gBAAgB,EAAE,MAAM,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAC3D,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AAEH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBA8L1D"}
@@ -1 +1 @@
1
- {"version":3,"file":"EditorContainer.js","sourceRoot":"","sources":["../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAOlC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AA2EnE;;GAEG;AACH,4DAA4D;AAC5D,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,MAAM,EACJ,gBAAgB,EAChB,KAAK,EACL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,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IACE,CAAC,CAAC,iBAAiB,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC;QAC5C,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC5C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,KAAM,EAAE,QAAQ,CAAC,KAAM,CAAC,CAAC;AAC7E,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 \"./EditorContainer.scss\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport type {\n Primitives,\n PrimitiveValue,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat, UiAdmin } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type {\n AsyncErrorMessage,\n PropertyEditorBase,\n} from \"./PropertyEditorManager.js\";\nimport { PropertyEditorManager } from \"./PropertyEditorManager.js\";\n\n/** Arguments for the Property Updated event callback\n * @public\n */\nexport interface PropertyUpdatedArgs {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** The new value for the property. */\n newValue: PropertyValue;\n}\n\n/** Properties for a property editor component\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport interface PropertyEditorProps extends CommonProps {\n /** The property being updated. */\n propertyRecord?: PropertyRecord;\n /** Handler for commit */\n onCommit?: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel?: () => void;\n /** Handler for blur */\n onBlur?: (event: React.FocusEvent) => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\n/** [[EditorContainer]] React component properties\n * @public\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof EditorContainer>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport interface EditorContainerProps extends CommonProps {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** Tooltip text */\n title?: string;\n /** Handler for commit */\n onCommit: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel: () => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n /** Handler for click */\n onClick?: () => void;\n\n /** @internal */\n ignoreEditorBlur?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\ninterface CloneProps extends PropertyEditorProps {\n ref: (ref: TypeEditor | null) => void;\n}\n\n/** Interface implemented by React based type editors\n * @public\n */\nexport interface TypeEditor {\n getPropertyValue: () => Promise<PropertyValue | undefined>;\n htmlElement: HTMLElement | null;\n hasFocus: boolean;\n}\n\n/** EditorContainer React component used by the Tree and PropertyGrid for cell editing.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function EditorContainer(props: EditorContainerProps) {\n const {\n ignoreEditorBlur,\n title,\n shouldCommitOnChange,\n propertyRecord,\n setFocus,\n onCommit,\n onCancel,\n onClick,\n ...rest\n } = props;\n\n const editorRef = React.useRef<TypeEditor | undefined>();\n const propertyEditorRef = React.useRef<PropertyEditorBase | undefined>();\n const committedByTab = React.useRef(false);\n\n const handleClick = (e: React.MouseEvent) => {\n onClick?.();\n e.stopPropagation();\n };\n const handleContextMenu = (e: React.MouseEvent) => e.stopPropagation();\n const handleContainerBlur = (e: React.FocusEvent) => e.stopPropagation();\n const handleEditorCommit = (args: PropertyUpdatedArgs) => void commit(args);\n\n const handleContainerCommit = async () => {\n const newValue = editorRef && (await editorRef.current?.getPropertyValue());\n if (newValue === undefined) return;\n void commit({\n propertyRecord,\n newValue,\n });\n };\n\n const onPressEscape = (e: React.KeyboardEvent) => {\n if (!propertyEditorRef.current?.containerHandlesEscape) return;\n e.stopPropagation();\n onCancel();\n };\n\n const onPressEnter = (e: React.KeyboardEvent) => {\n if (!propertyEditorRef.current?.containerHandlesEnter) return;\n if (editorRef?.current?.hasFocus) e.stopPropagation();\n void handleContainerCommit();\n };\n\n const onPressTab = (e: React.KeyboardEvent) => {\n if (!propertyEditorRef.current?.containerHandlesTab) return;\n e.stopPropagation();\n void handleContainerCommit();\n committedByTab.current = true;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case Key.Escape.valueOf():\n onPressEscape(e);\n break;\n case Key.Enter.valueOf():\n onPressEnter(e);\n break;\n case Key.Tab.valueOf():\n onPressTab(e);\n break;\n default:\n if (propertyEditorRef.current?.containerStopsKeydownPropagation)\n e.stopPropagation();\n }\n };\n\n const handleEditorBlur = () => {\n // Avoid double commit when tabbing.\n if (committedByTab.current) {\n committedByTab.current = false;\n return;\n }\n if (ignoreEditorBlur) return;\n if (!propertyEditorRef.current?.containerHandlesBlur) return;\n void handleContainerCommit();\n };\n\n const isNewValueValid = async (value: PropertyValue) => {\n if (!propertyEditorRef.current) return false;\n if (!propertyRecord) return false;\n\n const validateResult = await propertyEditorRef.current.validateValue(\n value,\n propertyRecord\n );\n\n if (validateResult.encounteredError) {\n displayOutputMessage(validateResult.errorMessage);\n return false;\n }\n\n return true;\n };\n\n const displayOutputMessage = (\n errorMessage: AsyncErrorMessage | undefined\n ) => {\n if (!errorMessage) return;\n if (!editorRef) return;\n\n const htmlElement = editorRef.current?.htmlElement;\n if (htmlElement)\n UiAdmin.messagePresenter.displayInputFieldMessage(\n htmlElement,\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage\n );\n else\n UiAdmin.messagePresenter.displayMessage(\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage,\n errorMessage.messageType\n );\n };\n\n const commit = async (args: PropertyUpdatedArgs) => {\n const oldValue = args.propertyRecord.value;\n const newValue = args.newValue;\n\n if (!shouldCommit(oldValue, newValue)) {\n return;\n }\n\n const isValid = await isNewValueValid(newValue);\n if (!isValid) return;\n\n if (propertyEditorRef.current && args.propertyRecord) {\n const commitResult = await propertyEditorRef.current.commitValue(\n newValue,\n args.propertyRecord\n );\n if (commitResult.encounteredError) {\n displayOutputMessage(commitResult.errorMessage);\n return;\n }\n }\n\n onCommit(args);\n };\n\n const editorProps: CloneProps = {\n ref: (ref) => {\n editorRef.current = ref ?? undefined;\n },\n onCommit: handleEditorCommit,\n onCancel,\n onBlur: handleEditorBlur,\n setFocus: setFocus !== undefined ? setFocus : true,\n propertyRecord,\n shouldCommitOnChange,\n ...rest,\n };\n\n const propDescription = propertyRecord.property;\n\n const editorName =\n propDescription.editor !== undefined\n ? propDescription.editor.name\n : undefined;\n\n propertyEditorRef.current = PropertyEditorManager.createEditor(\n propDescription.typename,\n editorName,\n propDescription.dataController\n );\n\n const clonedNode = React.isValidElement(propertyEditorRef.current.reactNode)\n ? React.cloneElement(propertyEditorRef.current.reactNode, editorProps)\n : undefined;\n\n return (\n <span\n className=\"components-editor-container\"\n onBlur={handleContainerBlur}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n title={title}\n data-testid=\"editor-container\"\n role=\"presentation\"\n >\n {clonedNode}\n </span>\n );\n}\n\nfunction arePrimitiveValuesEqual(\n oldValue: Primitives.Value,\n newValue: Primitives.Value\n): boolean {\n if (typeof oldValue !== typeof newValue) {\n return false;\n }\n // directly compare simple types\n if (typeof newValue !== \"object\" || newValue instanceof Date) {\n return newValue === oldValue;\n }\n // compare all members of arrays\n if (newValue instanceof Array) {\n if (!(oldValue instanceof Array)) {\n return false;\n }\n if (newValue.length !== oldValue.length) {\n return false;\n }\n for (let i = 0; i < newValue.length; i++) {\n if (oldValue[i] !== newValue[i]) {\n return false;\n }\n }\n return true;\n }\n // compare `Point2d` and `Point3d` types\n if (\"x\" in newValue) {\n if (typeof oldValue !== \"object\" || !(\"x\" in oldValue)) {\n return false;\n }\n if (\"z\" in newValue) {\n if (!(\"z\" in oldValue)) {\n return false;\n }\n return (\n newValue.x === oldValue.x &&\n newValue.y === oldValue.y &&\n newValue.z === oldValue.z\n );\n } else if (\"z\" in oldValue) {\n return false;\n }\n return newValue.x === oldValue.x && newValue.y === oldValue.y;\n }\n // compare instance keys\n if (\"className\" in newValue) {\n if (typeof oldValue !== \"object\" || !(\"className\" in oldValue)) {\n return false;\n }\n return (\n oldValue.className === newValue.className && oldValue.id === newValue.id\n );\n }\n return false;\n}\n\nfunction shouldCommit(oldValue: PropertyValue, newValue: PropertyValue) {\n if (\n oldValue.valueFormat !== newValue.valueFormat ||\n newValue.valueFormat !== PropertyValueFormat.Primitive\n ) {\n return true;\n }\n const oldPrimitiveValue = oldValue as PrimitiveValue;\n if (!oldPrimitiveValue.value && !newValue.value) {\n return false;\n }\n if (\n (!oldPrimitiveValue.value && newValue.value) ||\n (oldPrimitiveValue.value && !newValue.value)\n ) {\n return true;\n }\n return !arePrimitiveValuesEqual(oldPrimitiveValue.value!, newValue.value!);\n}\n"]}
1
+ {"version":3,"file":"EditorContainer.js","sourceRoot":"","sources":["../../../src/components-react/editors/EditorContainer.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,wBAAwB,CAAC;AAChC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAOlC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAMrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAkFnE;;GAEG;AACH,4DAA4D;AAC5D,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,MAAM,EACJ,gBAAgB,EAChB,KAAK,EACL,oBAAo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IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IACE,CAAC,CAAC,iBAAiB,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,CAAC;QAC5C,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC5C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,KAAM,EAAE,QAAQ,CAAC,KAAM,CAAC,CAAC;AAC7E,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 \"./EditorContainer.scss\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport type {\n Primitives,\n PrimitiveValue,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat, UiAdmin } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport type {\n AsyncErrorMessage,\n PropertyEditorBase,\n} from \"./PropertyEditorManager.js\";\nimport { PropertyEditorManager } from \"./PropertyEditorManager.js\";\n\n/** Arguments for the Property Updated event callback\n * @public\n */\nexport interface PropertyUpdatedArgs {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** The new value for the property. */\n newValue: PropertyValue;\n}\n\n/** Properties for a property editor component\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport interface PropertyEditorProps extends CommonProps {\n /** The property being updated. */\n propertyRecord?: PropertyRecord;\n /** Handler for commit */\n onCommit?: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel?: () => void;\n /** Handler for blur */\n onBlur?: (event: React.FocusEvent) => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\n/** Workaround to add internal props without major refactor, since editors uses both composition and inheritance.\n * @internal\n */\nexport interface InternalInputEditorProps {\n decoration?: React.ReactNode;\n}\n\n/** [[EditorContainer]] React component properties\n * @public\n * @deprecated in 4.17.0. Use `React.ComponentProps<typeof EditorContainer>`\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport interface EditorContainerProps extends CommonProps {\n /** The property being updated. */\n propertyRecord: PropertyRecord;\n /** Tooltip text */\n title?: string;\n /** Handler for commit */\n onCommit: (args: PropertyUpdatedArgs) => void;\n /** Handler for cancel */\n onCancel: () => void;\n /** Indicates whether the Property Editor should set focus */\n setFocus?: boolean;\n /** Handler for click */\n onClick?: () => void;\n\n /** @internal */\n ignoreEditorBlur?: boolean;\n /**\n * Indicates whether value change should call onCommit().\n * @internal\n */\n shouldCommitOnChange?: boolean;\n}\n\ninterface CloneProps extends PropertyEditorProps {\n ref: (ref: TypeEditor | null) => void;\n}\n\n/** Interface implemented by React based type editors\n * @public\n */\nexport interface TypeEditor {\n getPropertyValue: () => Promise<PropertyValue | undefined>;\n htmlElement: HTMLElement | null;\n hasFocus: boolean;\n}\n\n/** EditorContainer React component used by the Tree and PropertyGrid for cell editing.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport function EditorContainer(props: EditorContainerProps) {\n const {\n ignoreEditorBlur,\n title,\n shouldCommitOnChange,\n propertyRecord,\n setFocus,\n onCommit,\n onCancel,\n onClick,\n ...rest\n } = props;\n\n const editorRef = React.useRef<TypeEditor | undefined>();\n const propertyEditorRef = React.useRef<PropertyEditorBase | undefined>();\n const committedByTab = React.useRef(false);\n\n const handleClick = (e: React.MouseEvent) => {\n onClick?.();\n e.stopPropagation();\n };\n const handleContextMenu = (e: React.MouseEvent) => e.stopPropagation();\n const handleContainerBlur = (e: React.FocusEvent) => e.stopPropagation();\n const handleEditorCommit = (args: PropertyUpdatedArgs) => void commit(args);\n\n const handleContainerCommit = async () => {\n const newValue = editorRef && (await editorRef.current?.getPropertyValue());\n if (newValue === undefined) return;\n void commit({\n propertyRecord,\n newValue,\n });\n };\n\n const onPressEscape = (e: React.KeyboardEvent) => {\n if (!propertyEditorRef.current?.containerHandlesEscape) return;\n e.stopPropagation();\n onCancel();\n };\n\n const onPressEnter = (e: React.KeyboardEvent) => {\n if (!propertyEditorRef.current?.containerHandlesEnter) return;\n if (editorRef?.current?.hasFocus) e.stopPropagation();\n void handleContainerCommit();\n };\n\n const onPressTab = (e: React.KeyboardEvent) => {\n if (!propertyEditorRef.current?.containerHandlesTab) return;\n e.stopPropagation();\n void handleContainerCommit();\n committedByTab.current = true;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n switch (e.key) {\n case Key.Escape.valueOf():\n onPressEscape(e);\n break;\n case Key.Enter.valueOf():\n onPressEnter(e);\n break;\n case Key.Tab.valueOf():\n onPressTab(e);\n break;\n default:\n if (propertyEditorRef.current?.containerStopsKeydownPropagation)\n e.stopPropagation();\n }\n };\n\n const handleEditorBlur = () => {\n // Avoid double commit when tabbing.\n if (committedByTab.current) {\n committedByTab.current = false;\n return;\n }\n if (ignoreEditorBlur) return;\n if (!propertyEditorRef.current?.containerHandlesBlur) return;\n void handleContainerCommit();\n };\n\n const isNewValueValid = async (value: PropertyValue) => {\n if (!propertyEditorRef.current) return false;\n if (!propertyRecord) return false;\n\n const validateResult = await propertyEditorRef.current.validateValue(\n value,\n propertyRecord\n );\n\n if (validateResult.encounteredError) {\n displayOutputMessage(validateResult.errorMessage);\n return false;\n }\n\n return true;\n };\n\n const displayOutputMessage = (\n errorMessage: AsyncErrorMessage | undefined\n ) => {\n if (!errorMessage) return;\n if (!editorRef) return;\n\n const htmlElement = editorRef.current?.htmlElement;\n if (htmlElement)\n UiAdmin.messagePresenter.displayInputFieldMessage(\n htmlElement,\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage\n );\n else\n UiAdmin.messagePresenter.displayMessage(\n errorMessage.severity,\n errorMessage.briefMessage,\n errorMessage.detailedMessage,\n errorMessage.messageType\n );\n };\n\n const commit = async (args: PropertyUpdatedArgs) => {\n const oldValue = args.propertyRecord.value;\n const newValue = args.newValue;\n\n if (!shouldCommit(oldValue, newValue)) {\n return;\n }\n\n const isValid = await isNewValueValid(newValue);\n if (!isValid) return;\n\n if (propertyEditorRef.current && args.propertyRecord) {\n const commitResult = await propertyEditorRef.current.commitValue(\n newValue,\n args.propertyRecord\n );\n if (commitResult.encounteredError) {\n displayOutputMessage(commitResult.errorMessage);\n return;\n }\n }\n\n onCommit(args);\n };\n\n const editorProps: CloneProps = {\n ref: (ref) => {\n editorRef.current = ref ?? undefined;\n },\n onCommit: handleEditorCommit,\n onCancel,\n onBlur: handleEditorBlur,\n setFocus: setFocus !== undefined ? setFocus : true,\n propertyRecord,\n shouldCommitOnChange,\n ...rest,\n };\n\n const propDescription = propertyRecord.property;\n\n const editorName =\n propDescription.editor !== undefined\n ? propDescription.editor.name\n : undefined;\n\n propertyEditorRef.current = PropertyEditorManager.createEditor(\n propDescription.typename,\n editorName,\n propDescription.dataController\n );\n\n const clonedNode = React.isValidElement(propertyEditorRef.current.reactNode)\n ? React.cloneElement(propertyEditorRef.current.reactNode, editorProps)\n : undefined;\n\n return (\n <span\n className=\"components-editor-container\"\n onBlur={handleContainerBlur}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n title={title}\n data-testid=\"editor-container\"\n role=\"presentation\"\n >\n {clonedNode}\n </span>\n );\n}\n\nfunction arePrimitiveValuesEqual(\n oldValue: Primitives.Value,\n newValue: Primitives.Value\n): boolean {\n if (typeof oldValue !== typeof newValue) {\n return false;\n }\n // directly compare simple types\n if (typeof newValue !== \"object\" || newValue instanceof Date) {\n return newValue === oldValue;\n }\n // compare all members of arrays\n if (newValue instanceof Array) {\n if (!(oldValue instanceof Array)) {\n return false;\n }\n if (newValue.length !== oldValue.length) {\n return false;\n }\n for (let i = 0; i < newValue.length; i++) {\n if (oldValue[i] !== newValue[i]) {\n return false;\n }\n }\n return true;\n }\n // compare `Point2d` and `Point3d` types\n if (\"x\" in newValue) {\n if (typeof oldValue !== \"object\" || !(\"x\" in oldValue)) {\n return false;\n }\n if (\"z\" in newValue) {\n if (!(\"z\" in oldValue)) {\n return false;\n }\n return (\n newValue.x === oldValue.x &&\n newValue.y === oldValue.y &&\n newValue.z === oldValue.z\n );\n } else if (\"z\" in oldValue) {\n return false;\n }\n return newValue.x === oldValue.x && newValue.y === oldValue.y;\n }\n // compare instance keys\n if (\"className\" in newValue) {\n if (typeof oldValue !== \"object\" || !(\"className\" in oldValue)) {\n return false;\n }\n return (\n oldValue.className === newValue.className && oldValue.id === newValue.id\n );\n }\n return false;\n}\n\nfunction shouldCommit(oldValue: PropertyValue, newValue: PropertyValue) {\n if (\n oldValue.valueFormat !== newValue.valueFormat ||\n newValue.valueFormat !== PropertyValueFormat.Primitive\n ) {\n return true;\n }\n const oldPrimitiveValue = oldValue as PrimitiveValue;\n if (!oldPrimitiveValue.value && !newValue.value) {\n return false;\n }\n if (\n (!oldPrimitiveValue.value && newValue.value) ||\n (oldPrimitiveValue.value && !newValue.value)\n ) {\n return true;\n }\n return !arePrimitiveValuesEqual(oldPrimitiveValue.value!, newValue.value!);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInputEditor.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/NumericInputEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AAEnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAM/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,gBAAgB;AAChB,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,kBACX,SAAQ,KAAK,CAAC,aAAa,CAAC,mBAAmB,EAAE,uBAAuB,CACxE,YAAW,UAAU;IAErB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAwD;IACtE,QAAQ,UAAS;IAExB,SAAyB,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAG/D;IAEW,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAenE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,OAAO,CAAC,aAAa,CAUnB;IAEF,OAAO,CAAC,YAAY,CAelB;IAEc,iBAAiB;IAKjB,oBAAoB;IAIpC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;YAMnD,iBAAiB;IA4Df,MAAM,IAAI,KAAK,CAAC,SAAS;CAgC1C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,kBAAkB;IAChE,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;IACD,IAAoB,qBAAqB,IAAI,OAAO,CAGnD;CACF"}
1
+ {"version":3,"file":"NumericInputEditor.d.ts","sourceRoot":"","sources":["../../../src/components-react/editors/NumericInputEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,2BAA2B,CAAC;AAEnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,O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