@babylonjs/shared-ui-components 7.50.0 → 7.51.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.
@@ -24,27 +24,29 @@ export interface ITextInputLineComponentProps {
|
|
24
24
|
max?: number;
|
25
25
|
placeholder?: string;
|
26
26
|
unit?: React.ReactNode;
|
27
|
-
validator?: (
|
27
|
+
validator?: (input: string) => boolean;
|
28
|
+
onValidateChangeFailed?: (invalidInput: string) => void;
|
28
29
|
multilines?: boolean;
|
29
30
|
throttlePropertyChangedNotification?: boolean;
|
30
31
|
throttlePropertyChangedNotificationDelay?: number;
|
31
32
|
disabled?: boolean;
|
32
33
|
}
|
33
|
-
|
34
|
-
|
34
|
+
interface ITextInputLineComponentState {
|
35
|
+
input: string;
|
35
36
|
dragging: boolean;
|
36
|
-
|
37
|
+
inputValid: boolean;
|
38
|
+
}
|
39
|
+
export declare class TextInputLineComponent extends React.Component<ITextInputLineComponentProps, ITextInputLineComponentState> {
|
37
40
|
private _localChange;
|
38
41
|
constructor(props: ITextInputLineComponentProps);
|
39
42
|
componentWillUnmount(): void;
|
40
|
-
shouldComponentUpdate(nextProps: ITextInputLineComponentProps, nextState:
|
41
|
-
value: string;
|
42
|
-
dragging: boolean;
|
43
|
-
}): boolean;
|
43
|
+
shouldComponentUpdate(nextProps: ITextInputLineComponentProps, nextState: ITextInputLineComponentState): boolean;
|
44
44
|
raiseOnPropertyChanged(newValue: string, previousValue: string): void;
|
45
45
|
getCurrentNumericValue(value: string): number;
|
46
|
-
|
46
|
+
updateInput(input: string): void;
|
47
|
+
updateValue(adjustedInput?: string, updateState?: boolean): void;
|
47
48
|
incrementValue(amount: number): void;
|
48
49
|
onKeyDown(event: React.KeyboardEvent): void;
|
49
50
|
render(): import("react/jsx-runtime").JSX.Element;
|
50
51
|
}
|
52
|
+
export {};
|
@@ -9,11 +9,13 @@ export class TextInputLineComponent extends React.Component {
|
|
9
9
|
this._localChange = false;
|
10
10
|
const emptyValue = this.props.numeric ? "0" : "";
|
11
11
|
this.state = {
|
12
|
-
|
12
|
+
input: (this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName]) || emptyValue,
|
13
13
|
dragging: false,
|
14
|
+
inputValid: true,
|
14
15
|
};
|
15
16
|
}
|
16
17
|
componentWillUnmount() {
|
18
|
+
this.updateValue(undefined, false);
|
17
19
|
if (this.props.lockObject) {
|
18
20
|
this.props.lockObject.lock = false;
|
19
21
|
}
|
@@ -23,11 +25,6 @@ export class TextInputLineComponent extends React.Component {
|
|
23
25
|
this._localChange = false;
|
24
26
|
return true;
|
25
27
|
}
|
26
|
-
const newValue = nextProps.value !== undefined ? nextProps.value : nextProps.target[nextProps.propertyName];
|
27
|
-
if (newValue !== nextState.value) {
|
28
|
-
nextState.value = newValue || "";
|
29
|
-
return true;
|
30
|
-
}
|
31
28
|
if (nextState.dragging != this.state.dragging || nextProps.unit !== this.props.unit) {
|
32
29
|
return true;
|
33
30
|
}
|
@@ -61,14 +58,24 @@ export class TextInputLineComponent extends React.Component {
|
|
61
58
|
}
|
62
59
|
return 0;
|
63
60
|
}
|
64
|
-
|
61
|
+
updateInput(input) {
|
65
62
|
if (this.props.disabled) {
|
66
63
|
return;
|
67
64
|
}
|
68
65
|
if (this.props.numbersOnly) {
|
69
|
-
if (/[^0-9.px%-]/g.test(
|
66
|
+
if (/[^0-9.px%-]/g.test(input)) {
|
70
67
|
return;
|
71
68
|
}
|
69
|
+
}
|
70
|
+
this._localChange = true;
|
71
|
+
this.setState({
|
72
|
+
input,
|
73
|
+
inputValid: this.props.validator ? this.props.validator(input) : true,
|
74
|
+
});
|
75
|
+
}
|
76
|
+
updateValue(adjustedInput, updateState = true) {
|
77
|
+
let value = adjustedInput ?? this.state.input;
|
78
|
+
if (this.props.numbersOnly) {
|
72
79
|
if (!value) {
|
73
80
|
value = "0";
|
74
81
|
}
|
@@ -90,14 +97,15 @@ export class TextInputLineComponent extends React.Component {
|
|
90
97
|
}
|
91
98
|
value = numericValue.toString();
|
92
99
|
}
|
93
|
-
this._localChange = true;
|
94
100
|
const store = this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName];
|
95
|
-
if (
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
if (updateState) {
|
102
|
+
this._localChange = true;
|
103
|
+
this.setState({ input: value });
|
104
|
+
}
|
105
|
+
if (this.props.validator && this.props.validator(value) == false && this.props.onValidateChangeFailed) {
|
106
|
+
this.props.onValidateChangeFailed(value);
|
107
|
+
return;
|
99
108
|
}
|
100
|
-
this.setState({ value: value });
|
101
109
|
if (this.props.propertyName && !this.props.delayInput) {
|
102
110
|
this.props.target[this.props.propertyName] = value;
|
103
111
|
}
|
@@ -121,50 +129,51 @@ export class TextInputLineComponent extends React.Component {
|
|
121
129
|
this.props.arrowsIncrement(amount);
|
122
130
|
return;
|
123
131
|
}
|
124
|
-
const currentValue = this.getCurrentNumericValue(this.state.
|
132
|
+
const currentValue = this.getCurrentNumericValue(this.state.input);
|
125
133
|
this.updateValue((currentValue + amount).toFixed(2));
|
126
134
|
}
|
127
135
|
onKeyDown(event) {
|
128
|
-
if (!this.props.disabled
|
129
|
-
if (event.key === "
|
130
|
-
this.
|
131
|
-
event.preventDefault();
|
136
|
+
if (!this.props.disabled) {
|
137
|
+
if (event.key === "Enter") {
|
138
|
+
this.updateValue();
|
132
139
|
}
|
133
|
-
if (
|
134
|
-
|
135
|
-
|
140
|
+
if (this.props.arrows) {
|
141
|
+
if (event.key === "ArrowUp") {
|
142
|
+
this.incrementValue(1);
|
143
|
+
event.preventDefault();
|
144
|
+
}
|
145
|
+
if (event.key === "ArrowDown") {
|
146
|
+
this.incrementValue(-1);
|
147
|
+
event.preventDefault();
|
148
|
+
}
|
136
149
|
}
|
137
150
|
}
|
138
151
|
}
|
139
152
|
render() {
|
140
|
-
const value = this.state.
|
141
|
-
const placeholder = this.state.
|
153
|
+
const value = this.state.input === conflictingValuesPlaceholder ? "" : this.state.input;
|
154
|
+
const placeholder = this.state.input === conflictingValuesPlaceholder ? conflictingValuesPlaceholder : this.props.placeholder || "";
|
142
155
|
const step = this.props.step || (this.props.roundValues ? 1 : 0.01);
|
143
156
|
const className = this.props.multilines ? "textInputArea" : this.props.unit !== undefined ? "textInputLine withUnits" : "textInputLine";
|
144
|
-
|
157
|
+
const style = { background: this.state.inputValid ? undefined : "lightpink" };
|
158
|
+
return (_jsxs("div", { className: className, children: [this.props.icon && _jsx("img", { src: this.props.icon, title: this.props.iconLabel, alt: this.props.iconLabel, color: "black", className: "icon" }), this.props.label !== undefined && (_jsx("div", { className: "label", title: this.props.label, children: this.props.label })), this.props.multilines && (_jsx(_Fragment, { children: _jsx("textarea", { className: this.props.disabled ? "disabled" : "", style: style, value: this.state.input, onFocus: () => {
|
145
159
|
if (this.props.lockObject) {
|
146
160
|
this.props.lockObject.lock = true;
|
147
161
|
}
|
148
|
-
}, onChange: (evt) => this.
|
149
|
-
|
150
|
-
return;
|
151
|
-
}
|
152
|
-
this.updateValue(this.state.value);
|
153
|
-
}, onBlur: (evt) => {
|
154
|
-
this.updateValue(evt.target.value, evt.target.value);
|
162
|
+
}, onChange: (evt) => this.updateInput(evt.target.value), onBlur: (evt) => {
|
163
|
+
this.updateValue();
|
155
164
|
if (this.props.lockObject) {
|
156
165
|
this.props.lockObject.lock = false;
|
157
166
|
}
|
158
|
-
}, disabled: this.props.disabled }) })), !this.props.multilines && (_jsxs("div", { className: `value${this.props.noUnderline === true ? " noUnderline" : ""}${this.props.arrows ? " hasArrows" : ""}${this.state.dragging ? " dragging" : ""}`, children: [_jsx("input", { className: this.props.disabled ? "disabled" : "", value: value, onBlur: (evt) => {
|
167
|
+
}, disabled: this.props.disabled }) })), !this.props.multilines && (_jsxs("div", { className: `value${this.props.noUnderline === true ? " noUnderline" : ""}${this.props.arrows ? " hasArrows" : ""}${this.state.dragging ? " dragging" : ""}`, children: [_jsx("input", { className: this.props.disabled ? "disabled" : "", style: style, value: value, onBlur: (evt) => {
|
159
168
|
if (this.props.lockObject) {
|
160
169
|
this.props.lockObject.lock = false;
|
161
170
|
}
|
162
|
-
this.updateValue(
|
171
|
+
this.updateValue();
|
163
172
|
}, onFocus: () => {
|
164
173
|
if (this.props.lockObject) {
|
165
174
|
this.props.lockObject.lock = true;
|
166
175
|
}
|
167
|
-
}, onChange: (evt) => this.
|
176
|
+
}, onChange: (evt) => this.updateInput(evt.target.value), onKeyDown: (evt) => this.onKeyDown(evt), placeholder: placeholder, type: this.props.numeric ? "number" : "text", step: step, disabled: this.props.disabled }), this.props.arrows && (_jsx(InputArrowsComponent, { incrementValue: (amount) => this.incrementValue(amount), setDragging: (dragging) => this.setState({ dragging }) }))] })), this.props.unit] }));
|
168
177
|
}
|
169
178
|
}
|
170
179
|
//# sourceMappingURL=textInputLineComponent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"textInputLineComponent.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/lines/textInputLineComponent.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA+B9D,IAAI,eAAe,GAAG,CAAC,CAAC,CAAC;AAEzB,MAAM,OAAO,sBAAuB,SAAQ,KAAK,CAAC,SAA6E;IAG3H,YAAY,KAAmC;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC;QAHT,iBAAY,GAAG,KAAK,CAAC;QAKzB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAEjD,IAAI,CAAC,KAAK,GAAG;YACT,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,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AAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EACrD,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAC5C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAC/B,EACD,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAClB,KAAC,oBAAoB,IAAC,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAI,CAC5I,IACC,CACT,EACA,IAAI,CAAC,KAAK,CAAC,IAAI,IACd,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import * as React from \"react\";\r\nimport type { Observable } from \"core/Misc/observable\";\r\nimport type { PropertyChangedEvent } from \"../propertyChangedEvent\";\r\nimport type { LockObject } from \"../tabs/propertyGrids/lockObject\";\r\nimport { conflictingValuesPlaceholder } from \"./targetsProxy\";\r\nimport { InputArrowsComponent } from \"./inputArrowsComponent\";\r\n\r\nexport interface ITextInputLineComponentProps {\r\n label?: string;\r\n lockObject?: LockObject;\r\n target?: any;\r\n propertyName?: string;\r\n value?: string;\r\n onChange?: (value: string) => void;\r\n onPropertyChangedObservable?: Observable<PropertyChangedEvent>;\r\n icon?: string;\r\n iconLabel?: string;\r\n noUnderline?: boolean;\r\n numbersOnly?: boolean;\r\n delayInput?: boolean;\r\n arrows?: boolean;\r\n arrowsIncrement?: (amount: number) => void;\r\n step?: number;\r\n numeric?: boolean;\r\n roundValues?: boolean;\r\n min?: number;\r\n max?: number;\r\n placeholder?: string;\r\n unit?: React.ReactNode;\r\n validator?: (value: string) => boolean;\r\n multilines?: boolean;\r\n throttlePropertyChangedNotification?: boolean;\r\n throttlePropertyChangedNotificationDelay?: number;\r\n disabled?: boolean;\r\n}\r\n\r\nlet throttleTimerId = -1;\r\n\r\nexport class TextInputLineComponent extends React.Component<ITextInputLineComponentProps, { value: string; dragging: boolean }> {\r\n private _localChange = false;\r\n\r\n constructor(props: ITextInputLineComponentProps) {\r\n super(props);\r\n\r\n const emptyValue = this.props.numeric ? \"0\" : \"\";\r\n\r\n this.state = {\r\n value: (this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!]) || emptyValue,\r\n dragging: false,\r\n };\r\n }\r\n\r\n override componentWillUnmount() {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = false;\r\n }\r\n }\r\n\r\n override shouldComponentUpdate(nextProps: ITextInputLineComponentProps, nextState: { value: string; dragging: boolean }) {\r\n if (this._localChange) {\r\n this._localChange = false;\r\n return true;\r\n }\r\n\r\n const newValue = nextProps.value !== undefined ? nextProps.value : nextProps.target[nextProps.propertyName!];\r\n if (newValue !== nextState.value) {\r\n nextState.value = newValue || \"\";\r\n return true;\r\n }\r\n\r\n if (nextState.dragging != this.state.dragging || nextProps.unit !== this.props.unit) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n raiseOnPropertyChanged(newValue: string, previousValue: string) {\r\n if (this.props.onChange) {\r\n this.props.onChange(newValue);\r\n return;\r\n }\r\n\r\n if (!this.props.onPropertyChangedObservable) {\r\n return;\r\n }\r\n\r\n this.props.onPropertyChangedObservable.notifyObservers({\r\n object: this.props.target,\r\n property: this.props.propertyName!,\r\n value: newValue,\r\n initialValue: previousValue,\r\n });\r\n }\r\n\r\n getCurrentNumericValue(value: string) {\r\n const numeric = parseFloat(value);\r\n if (!isNaN(numeric)) {\r\n return numeric;\r\n }\r\n if (this.props.placeholder !== undefined) {\r\n const placeholderNumeric = parseFloat(this.props.placeholder);\r\n if (!isNaN(placeholderNumeric)) {\r\n return placeholderNumeric;\r\n }\r\n }\r\n return 0;\r\n }\r\n\r\n updateValue(value: string, valueToValidate?: string) {\r\n if (this.props.disabled) {\r\n return;\r\n }\r\n if (this.props.numbersOnly) {\r\n if (/[^0-9.px%-]/g.test(value)) {\r\n return;\r\n }\r\n if (!value) {\r\n value = \"0\";\r\n }\r\n\r\n //Removing starting zero if there is a number of a minus after it.\r\n if (value.search(/0+[0-9-]/g) === 0) {\r\n value = value.substring(1);\r\n }\r\n }\r\n\r\n if (this.props.numeric) {\r\n let numericValue = this.getCurrentNumericValue(value);\r\n if (this.props.roundValues) {\r\n numericValue = Math.round(numericValue);\r\n }\r\n if (this.props.min !== undefined) {\r\n numericValue = Math.max(this.props.min, numericValue);\r\n }\r\n if (this.props.max !== undefined) {\r\n numericValue = Math.min(this.props.max, numericValue);\r\n }\r\n value = numericValue.toString();\r\n }\r\n\r\n this._localChange = true;\r\n const store = this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!];\r\n\r\n if (this.props.validator && valueToValidate) {\r\n if (this.props.validator(valueToValidate) == false) {\r\n value = store;\r\n }\r\n }\r\n\r\n this.setState({ value: value });\r\n\r\n if (this.props.propertyName && !this.props.delayInput) {\r\n this.props.target[this.props.propertyName] = value;\r\n }\r\n\r\n if (this.props.throttlePropertyChangedNotification) {\r\n if (throttleTimerId >= 0) {\r\n window.clearTimeout(throttleTimerId);\r\n }\r\n throttleTimerId = window.setTimeout(() => {\r\n this.raiseOnPropertyChanged(value, store);\r\n }, this.props.throttlePropertyChangedNotificationDelay ?? 200);\r\n } else {\r\n this.raiseOnPropertyChanged(value, store);\r\n }\r\n }\r\n\r\n incrementValue(amount: number) {\r\n if (this.props.step) {\r\n amount *= this.props.step;\r\n }\r\n if (this.props.arrowsIncrement) {\r\n this.props.arrowsIncrement(amount);\r\n return;\r\n }\r\n const currentValue = this.getCurrentNumericValue(this.state.value);\r\n this.updateValue((currentValue + amount).toFixed(2));\r\n }\r\n\r\n onKeyDown(event: React.KeyboardEvent) {\r\n if (!this.props.disabled && this.props.arrows) {\r\n if (event.key === \"ArrowUp\") {\r\n this.incrementValue(1);\r\n event.preventDefault();\r\n }\r\n if (event.key === \"ArrowDown\") {\r\n this.incrementValue(-1);\r\n event.preventDefault();\r\n }\r\n }\r\n }\r\n\r\n override render() {\r\n const value = this.state.value === conflictingValuesPlaceholder ? \"\" : this.state.value;\r\n const placeholder = this.state.value === conflictingValuesPlaceholder ? conflictingValuesPlaceholder : this.props.placeholder || \"\";\r\n const step = this.props.step || (this.props.roundValues ? 1 : 0.01);\r\n const className = this.props.multilines ? \"textInputArea\" : this.props.unit !== undefined ? \"textInputLine withUnits\" : \"textInputLine\";\r\n return (\r\n <div className={className}>\r\n {this.props.icon && <img src={this.props.icon} title={this.props.iconLabel} alt={this.props.iconLabel} color=\"black\" className=\"icon\" />}\r\n {this.props.label !== undefined && (\r\n <div className=\"label\" title={this.props.label}>\r\n {this.props.label}\r\n </div>\r\n )}\r\n {this.props.multilines && (\r\n <>\r\n <textarea\r\n className={this.props.disabled ? \"disabled\" : \"\"}\r\n value={this.state.value}\r\n onFocus={() => {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = true;\r\n }\r\n }}\r\n onChange={(evt) => this.updateValue(evt.target.value)}\r\n onKeyDown={(evt) => {\r\n if (evt.keyCode !== 13) {\r\n return;\r\n }\r\n this.updateValue(this.state.value);\r\n }}\r\n onBlur={(evt) => {\r\n this.updateValue(evt.target.value, evt.target.value);\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = false;\r\n }\r\n }}\r\n disabled={this.props.disabled}\r\n />\r\n </>\r\n )}\r\n {!this.props.multilines && (\r\n <div\r\n className={`value${this.props.noUnderline === true ? \" noUnderline\" : \"\"}${this.props.arrows ? \" hasArrows\" : \"\"}${this.state.dragging ? \" dragging\" : \"\"}`}\r\n >\r\n <input\r\n className={this.props.disabled ? \"disabled\" : \"\"}\r\n value={value}\r\n onBlur={(evt) => {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = false;\r\n }\r\n this.updateValue((this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!]) || \"\", evt.target.value);\r\n }}\r\n onFocus={() => {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = true;\r\n }\r\n }}\r\n onChange={(evt) => this.updateValue(evt.target.value)}\r\n onKeyDown={(evt) => this.onKeyDown(evt)}\r\n placeholder={placeholder}\r\n type={this.props.numeric ? \"number\" : \"text\"}\r\n step={step}\r\n disabled={this.props.disabled}\r\n />\r\n {this.props.arrows && (\r\n <InputArrowsComponent incrementValue={(amount) => this.incrementValue(amount)} setDragging={(dragging) => this.setState({ dragging })} />\r\n )}\r\n </div>\r\n )}\r\n {this.props.unit}\r\n </div>\r\n );\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"textInputLineComponent.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/lines/textInputLineComponent.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAsC9D,IAAI,eAAe,GAAG,CAAC,CAAC,CAAC;AAEzB,MAAM,OAAO,sBAAuB,SAAQ,KAAK,CAAC,SAAqE;IAGnH,YAAY,KAAmC;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC;QAHT,iBAAY,GAAG,KAAK,CAAC;QAKzB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAEjD,IAAI,CAAC,KAAK,GAAG;YACT,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC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AAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EACrD,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAC5C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAC/B,EACD,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAClB,KAAC,oBAAoB,IAAC,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAI,CAC5I,IACC,CACT,EACA,IAAI,CAAC,KAAK,CAAC,IAAI,IACd,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import * as React from \"react\";\r\nimport type { Observable } from \"core/Misc/observable\";\r\nimport type { PropertyChangedEvent } from \"../propertyChangedEvent\";\r\nimport type { LockObject } from \"../tabs/propertyGrids/lockObject\";\r\nimport { conflictingValuesPlaceholder } from \"./targetsProxy\";\r\nimport { InputArrowsComponent } from \"./inputArrowsComponent\";\r\n\r\nexport interface ITextInputLineComponentProps {\r\n label?: string;\r\n lockObject?: LockObject;\r\n target?: any;\r\n propertyName?: string;\r\n value?: string;\r\n onChange?: (value: string) => void;\r\n onPropertyChangedObservable?: Observable<PropertyChangedEvent>;\r\n icon?: string;\r\n iconLabel?: string;\r\n noUnderline?: boolean;\r\n numbersOnly?: boolean;\r\n delayInput?: boolean;\r\n arrows?: boolean;\r\n arrowsIncrement?: (amount: number) => void;\r\n step?: number;\r\n numeric?: boolean;\r\n roundValues?: boolean;\r\n min?: number;\r\n max?: number;\r\n placeholder?: string;\r\n unit?: React.ReactNode;\r\n validator?: (input: string) => boolean;\r\n onValidateChangeFailed?: (invalidInput: string) => void;\r\n multilines?: boolean;\r\n throttlePropertyChangedNotification?: boolean;\r\n throttlePropertyChangedNotificationDelay?: number;\r\n disabled?: boolean;\r\n}\r\n\r\ninterface ITextInputLineComponentState {\r\n input: string;\r\n dragging: boolean;\r\n inputValid: boolean;\r\n}\r\n\r\nlet throttleTimerId = -1;\r\n\r\nexport class TextInputLineComponent extends React.Component<ITextInputLineComponentProps, ITextInputLineComponentState> {\r\n private _localChange = false;\r\n\r\n constructor(props: ITextInputLineComponentProps) {\r\n super(props);\r\n\r\n const emptyValue = this.props.numeric ? \"0\" : \"\";\r\n\r\n this.state = {\r\n input: (this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!]) || emptyValue,\r\n dragging: false,\r\n inputValid: true,\r\n };\r\n }\r\n\r\n override componentWillUnmount() {\r\n this.updateValue(undefined, false);\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = false;\r\n }\r\n }\r\n\r\n override shouldComponentUpdate(nextProps: ITextInputLineComponentProps, nextState: ITextInputLineComponentState) {\r\n if (this._localChange) {\r\n this._localChange = false;\r\n return true;\r\n }\r\n\r\n if (nextState.dragging != this.state.dragging || nextProps.unit !== this.props.unit) {\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n raiseOnPropertyChanged(newValue: string, previousValue: string) {\r\n if (this.props.onChange) {\r\n this.props.onChange(newValue);\r\n return;\r\n }\r\n\r\n if (!this.props.onPropertyChangedObservable) {\r\n return;\r\n }\r\n\r\n this.props.onPropertyChangedObservable.notifyObservers({\r\n object: this.props.target,\r\n property: this.props.propertyName!,\r\n value: newValue,\r\n initialValue: previousValue,\r\n });\r\n }\r\n\r\n getCurrentNumericValue(value: string) {\r\n const numeric = parseFloat(value);\r\n if (!isNaN(numeric)) {\r\n return numeric;\r\n }\r\n if (this.props.placeholder !== undefined) {\r\n const placeholderNumeric = parseFloat(this.props.placeholder);\r\n if (!isNaN(placeholderNumeric)) {\r\n return placeholderNumeric;\r\n }\r\n }\r\n return 0;\r\n }\r\n\r\n updateInput(input: string) {\r\n if (this.props.disabled) {\r\n return;\r\n }\r\n if (this.props.numbersOnly) {\r\n if (/[^0-9.px%-]/g.test(input)) {\r\n return;\r\n }\r\n }\r\n\r\n this._localChange = true;\r\n this.setState({\r\n input,\r\n inputValid: this.props.validator ? this.props.validator(input) : true,\r\n });\r\n }\r\n\r\n updateValue(adjustedInput?: string, updateState: boolean = true) {\r\n let value = adjustedInput ?? this.state.input;\r\n\r\n if (this.props.numbersOnly) {\r\n if (!value) {\r\n value = \"0\";\r\n }\r\n\r\n //Removing starting zero if there is a number of a minus after it.\r\n if (value.search(/0+[0-9-]/g) === 0) {\r\n value = value.substring(1);\r\n }\r\n }\r\n\r\n if (this.props.numeric) {\r\n let numericValue = this.getCurrentNumericValue(value);\r\n if (this.props.roundValues) {\r\n numericValue = Math.round(numericValue);\r\n }\r\n if (this.props.min !== undefined) {\r\n numericValue = Math.max(this.props.min, numericValue);\r\n }\r\n if (this.props.max !== undefined) {\r\n numericValue = Math.min(this.props.max, numericValue);\r\n }\r\n value = numericValue.toString();\r\n }\r\n\r\n const store = this.props.value !== undefined ? this.props.value : this.props.target[this.props.propertyName!];\r\n\r\n if (updateState) {\r\n this._localChange = true;\r\n this.setState({ input: value });\r\n }\r\n\r\n if (this.props.validator && this.props.validator(value) == false && this.props.onValidateChangeFailed) {\r\n this.props.onValidateChangeFailed(value);\r\n return;\r\n }\r\n\r\n if (this.props.propertyName && !this.props.delayInput) {\r\n this.props.target[this.props.propertyName] = value;\r\n }\r\n\r\n if (this.props.throttlePropertyChangedNotification) {\r\n if (throttleTimerId >= 0) {\r\n window.clearTimeout(throttleTimerId);\r\n }\r\n throttleTimerId = window.setTimeout(() => {\r\n this.raiseOnPropertyChanged(value, store);\r\n }, this.props.throttlePropertyChangedNotificationDelay ?? 200);\r\n } else {\r\n this.raiseOnPropertyChanged(value, store);\r\n }\r\n }\r\n\r\n incrementValue(amount: number) {\r\n if (this.props.step) {\r\n amount *= this.props.step;\r\n }\r\n if (this.props.arrowsIncrement) {\r\n this.props.arrowsIncrement(amount);\r\n return;\r\n }\r\n const currentValue = this.getCurrentNumericValue(this.state.input);\r\n this.updateValue((currentValue + amount).toFixed(2));\r\n }\r\n\r\n onKeyDown(event: React.KeyboardEvent) {\r\n if (!this.props.disabled) {\r\n if (event.key === \"Enter\") {\r\n this.updateValue();\r\n }\r\n if (this.props.arrows) {\r\n if (event.key === \"ArrowUp\") {\r\n this.incrementValue(1);\r\n event.preventDefault();\r\n }\r\n if (event.key === \"ArrowDown\") {\r\n this.incrementValue(-1);\r\n event.preventDefault();\r\n }\r\n }\r\n }\r\n }\r\n\r\n override render() {\r\n const value = this.state.input === conflictingValuesPlaceholder ? \"\" : this.state.input;\r\n const placeholder = this.state.input === conflictingValuesPlaceholder ? conflictingValuesPlaceholder : this.props.placeholder || \"\";\r\n const step = this.props.step || (this.props.roundValues ? 1 : 0.01);\r\n const className = this.props.multilines ? \"textInputArea\" : this.props.unit !== undefined ? \"textInputLine withUnits\" : \"textInputLine\";\r\n const style = { background: this.state.inputValid ? undefined : \"lightpink\" };\r\n return (\r\n <div className={className}>\r\n {this.props.icon && <img src={this.props.icon} title={this.props.iconLabel} alt={this.props.iconLabel} color=\"black\" className=\"icon\" />}\r\n {this.props.label !== undefined && (\r\n <div className=\"label\" title={this.props.label}>\r\n {this.props.label}\r\n </div>\r\n )}\r\n {this.props.multilines && (\r\n <>\r\n <textarea\r\n className={this.props.disabled ? \"disabled\" : \"\"}\r\n style={style}\r\n value={this.state.input}\r\n onFocus={() => {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = true;\r\n }\r\n }}\r\n onChange={(evt) => this.updateInput(evt.target.value)}\r\n onBlur={(evt) => {\r\n this.updateValue();\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = false;\r\n }\r\n }}\r\n disabled={this.props.disabled}\r\n />\r\n </>\r\n )}\r\n {!this.props.multilines && (\r\n <div\r\n className={`value${this.props.noUnderline === true ? \" noUnderline\" : \"\"}${this.props.arrows ? \" hasArrows\" : \"\"}${this.state.dragging ? \" dragging\" : \"\"}`}\r\n >\r\n <input\r\n className={this.props.disabled ? \"disabled\" : \"\"}\r\n style={style}\r\n value={value}\r\n onBlur={(evt) => {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = false;\r\n }\r\n this.updateValue();\r\n }}\r\n onFocus={() => {\r\n if (this.props.lockObject) {\r\n this.props.lockObject.lock = true;\r\n }\r\n }}\r\n onChange={(evt) => this.updateInput(evt.target.value)}\r\n onKeyDown={(evt) => this.onKeyDown(evt)}\r\n placeholder={placeholder}\r\n type={this.props.numeric ? \"number\" : \"text\"}\r\n step={step}\r\n disabled={this.props.disabled}\r\n />\r\n {this.props.arrows && (\r\n <InputArrowsComponent incrementValue={(amount) => this.incrementValue(amount)} setDragging={(dragging) => this.setState({ dragging })} />\r\n )}\r\n </div>\r\n )}\r\n {this.props.unit}\r\n </div>\r\n );\r\n }\r\n}\r\n"]}
|