|
@@ -3,6 +3,8 @@ import * as React from "react";
|
|
|
import { Observable } from "babylonjs/Misc/observable";
|
|
|
import { PropertyChangedEvent } from "../../propertyChangedEvent";
|
|
|
|
|
|
+export const Null_Value = Number.MAX_SAFE_INTEGER;
|
|
|
+
|
|
|
class ListLineOption {
|
|
|
public label: string;
|
|
|
public value: number;
|
|
@@ -16,15 +18,25 @@ interface IOptionsLineComponentProps {
|
|
|
noDirectUpdate?: boolean;
|
|
|
onSelect?: (value: number) => void;
|
|
|
extractValue?: () => number;
|
|
|
+ onPropertyChangedObservable?: Observable<PropertyChangedEvent>;
|
|
|
+ allowNullValue?: boolean;
|
|
|
}
|
|
|
|
|
|
export class OptionsLineComponent extends React.Component<IOptionsLineComponentProps, { value: number }> {
|
|
|
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) {
|
|
|
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 }) {
|
|
@@ -33,7 +45,7 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
|
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) {
|
|
|
nextState.value = newValue;
|
|
|
return true;
|
|
@@ -50,7 +62,8 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
|
object: this.props.target,
|
|
|
property: this.props.propertyName,
|
|
|
value: newValue,
|
|
|
- initialValue: previousValue
|
|
|
+ initialValue: previousValue,
|
|
|
+ allowNullValue: this.props.allowNullValue,
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -61,7 +74,7 @@ export class OptionsLineComponent extends React.Component<IOptionsLineComponentP
|
|
|
const store = this.props.extractValue ? this.props.extractValue() : this.props.target[this.props.propertyName];
|
|
|
|
|
|
if (!this.props.noDirectUpdate) {
|
|
|
- this.props.target[this.props.propertyName] = value;
|
|
|
+ this.props.target[this.props.propertyName] = this.remapValueOut(value);
|
|
|
}
|
|
|
this.setState({ value: value });
|
|
|
|