|
@@ -3,29 +3,40 @@ import * as React from "react";
|
|
import { Observable } from "babylonjs/Misc/observable";
|
|
import { Observable } from "babylonjs/Misc/observable";
|
|
import { PropertyChangedEvent } from "../../propertyChangedEvent";
|
|
import { PropertyChangedEvent } from "../../propertyChangedEvent";
|
|
|
|
|
|
|
|
+export const Null_Value = Number.MAX_SAFE_INTEGER;
|
|
|
|
+
|
|
class ListLineOption {
|
|
class ListLineOption {
|
|
public label: string;
|
|
public label: string;
|
|
public value: number;
|
|
public value: number;
|
|
}
|
|
}
|
|
|
|
|
|
interface IOptionsLineComponentProps {
|
|
interface IOptionsLineComponentProps {
|
|
- label: string,
|
|
|
|
- target: any,
|
|
|
|
- propertyName: string,
|
|
|
|
- options: ListLineOption[],
|
|
|
|
- noDirectUpdate?: boolean,
|
|
|
|
- onSelect?: (value: number) => void,
|
|
|
|
- extractValue?: () => number,
|
|
|
|
- onPropertyChangedObservable?: Observable<PropertyChangedEvent>
|
|
|
|
|
|
+ label: string;
|
|
|
|
+ target: any;
|
|
|
|
+ propertyName: string;
|
|
|
|
+ options: ListLineOption[];
|
|
|
|
+ noDirectUpdate?: boolean;
|
|
|
|
+ onSelect?: (value: number) => void;
|
|
|
|
+ extractValue?: () => number;
|
|
|
|
+ onPropertyChangedObservable?: Observable<PropertyChangedEvent>;
|
|
|
|
+ allowNullValue?: boolean;
|
|
}
|
|
}
|
|
|
|
|
|
export class OptionsLineComponent extends React.Component<IOptionsLineComponentProps, { value: number }> {
|
|
export class OptionsLineComponent extends React.Component<IOptionsLineComponentProps, { value: number }> {
|
|
private _localChange = false;
|
|
private _localChange = false;
|
|
|
|
|
|
|
|
+ private remapValueIn(value: number | null): number {
|
|
|
|
+ return this.props.allowNullValue && value === null ? Null_Value : value!;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private remapValueOut(value: number): number | null {
|
|
|
|
+ return this.props.allowNullValue && value === Null_Value ? null : value;
|
|
|
|
+ }
|
|
|
|
+
|
|
constructor(props: IOptionsLineComponentProps) {
|
|
constructor(props: IOptionsLineComponentProps) {
|
|
super(props);
|
|
super(props);
|
|
|
|
|
|
- this.state = { value: this.props.extractValue ? this.props.extractValue() : props.target[props.propertyName] };
|
|
|
|
|
|
+ this.state = { value: this.remapValueIn(this.props.extractValue ? this.props.extractValue() : props.target[props.propertyName]) };
|
|
}
|
|
}
|
|
|
|
|
|
shouldComponentUpdate(nextProps: IOptionsLineComponentProps, nextState: { value: number }) {
|
|
shouldComponentUpdate(nextProps: IOptionsLineComponentProps, nextState: { value: number }) {
|
|
@@ -34,7 +45,7 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- const newValue = nextProps.extractValue ? nextProps.extractValue() : nextProps.target[nextProps.propertyName];
|
|
|
|
|
|
+ let newValue = this.remapValueIn(nextProps.extractValue ? nextProps.extractValue() : nextProps.target[nextProps.propertyName]);
|
|
if (newValue != null && newValue !== nextState.value) {
|
|
if (newValue != null && newValue !== nextState.value) {
|
|
nextState.value = newValue;
|
|
nextState.value = newValue;
|
|
return true;
|
|
return true;
|
|
@@ -51,7 +62,8 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
object: this.props.target,
|
|
object: this.props.target,
|
|
property: this.props.propertyName,
|
|
property: this.props.propertyName,
|
|
value: newValue,
|
|
value: newValue,
|
|
- initialValue: previousValue
|
|
|
|
|
|
+ initialValue: previousValue,
|
|
|
|
+ allowNullValue: this.props.allowNullValue,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -59,21 +71,20 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
const value = parseInt(valueString);
|
|
const value = parseInt(valueString);
|
|
this._localChange = true;
|
|
this._localChange = true;
|
|
|
|
|
|
- const store = this.props.extractValue ? this.props.extractValue() : this.props.target[this.props.propertyName]
|
|
|
|
|
|
+ const store = this.props.extractValue ? this.props.extractValue() : this.props.target[this.props.propertyName];
|
|
|
|
|
|
if (!this.props.noDirectUpdate) {
|
|
if (!this.props.noDirectUpdate) {
|
|
- this.props.target[this.props.propertyName] = value;
|
|
|
|
|
|
+ this.props.target[this.props.propertyName] = this.remapValueOut(value);
|
|
}
|
|
}
|
|
this.setState({ value: value });
|
|
this.setState({ value: value });
|
|
-
|
|
|
|
|
|
+
|
|
if (this.props.onSelect) {
|
|
if (this.props.onSelect) {
|
|
this.props.onSelect(value);
|
|
this.props.onSelect(value);
|
|
}
|
|
}
|
|
|
|
|
|
- const newValue = this.props.extractValue ? this.props.extractValue() : this.props.target[this.props.propertyName]
|
|
|
|
|
|
+ const newValue = this.props.extractValue ? this.props.extractValue() : this.props.target[this.props.propertyName];
|
|
|
|
|
|
this.raiseOnPropertyChanged(newValue, store);
|
|
this.raiseOnPropertyChanged(newValue, store);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
render() {
|
|
render() {
|
|
@@ -84,12 +95,12 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div className="options">
|
|
<div className="options">
|
|
- <select onChange={evt => this.updateValue(evt.target.value)} value={this.state.value ?? ""}>
|
|
|
|
|
|
+ <select onChange={(evt) => this.updateValue(evt.target.value)} value={this.state.value ?? ""}>
|
|
{
|
|
{
|
|
- this.props.options.map(option => {
|
|
|
|
|
|
+ this.props.options.map((option) => {
|
|
return (
|
|
return (
|
|
<option key={option.label} value={option.value}>{option.label}</option>
|
|
<option key={option.label} value={option.value}>{option.label}</option>
|
|
- )
|
|
|
|
|
|
+ );
|
|
})
|
|
})
|
|
}
|
|
}
|
|
</select>
|
|
</select>
|