@onerjs/shared-ui-components 8.25.1 → 8.25.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constToOptionsMaps.js +2 -2
- package/constToOptionsMaps.js.map +1 -1
- package/fluent/hoc/propertyLines/inputPropertyLine.d.ts +7 -3
- package/fluent/hoc/propertyLines/inputPropertyLine.js +6 -2
- package/fluent/hoc/propertyLines/inputPropertyLine.js.map +1 -1
- package/fluent/hoc/propertyLines/vectorPropertyLine.d.ts +4 -0
- package/fluent/hoc/propertyLines/vectorPropertyLine.js +3 -3
- package/fluent/hoc/propertyLines/vectorPropertyLine.js.map +1 -1
- package/fluent/primitives/accordion.js +27 -3
- package/fluent/primitives/accordion.js.map +1 -1
- package/fluent/primitives/collapse.d.ts +1 -0
- package/fluent/primitives/collapse.js +2 -1
- package/fluent/primitives/collapse.js.map +1 -1
- package/fluent/primitives/colorPicker.d.ts +2 -6
- package/fluent/primitives/colorPicker.js +41 -48
- package/fluent/primitives/colorPicker.js.map +1 -1
- package/fluent/primitives/infoLabel.d.ts +13 -0
- package/fluent/primitives/infoLabel.js +11 -0
- package/fluent/primitives/infoLabel.js.map +1 -0
- package/fluent/primitives/primitive.d.ts +5 -0
- package/fluent/primitives/primitive.js.map +1 -1
- package/fluent/primitives/spinButton.d.ts +9 -3
- package/fluent/primitives/spinButton.js +100 -16
- package/fluent/primitives/spinButton.js.map +1 -1
- package/fluent/primitives/switch.js +1 -1
- package/fluent/primitives/switch.js.map +1 -1
- package/fluent/primitives/syncedSlider.d.ts +2 -0
- package/fluent/primitives/syncedSlider.js +6 -10
- package/fluent/primitives/syncedSlider.js.map +1 -1
- package/fluent/primitives/textInput.d.ts +6 -0
- package/fluent/primitives/textInput.js +48 -0
- package/fluent/primitives/textInput.js.map +1 -0
- package/fluent/primitives/toggleButton.d.ts +1 -0
- package/fluent/primitives/toggleButton.js +2 -2
- package/fluent/primitives/toggleButton.js.map +1 -1
- package/lines/textInputLineComponent.js +3 -4
- package/lines/textInputLineComponent.js.map +1 -1
- package/package.json +1 -1
- package/fluent/primitives/input.d.ts +0 -10
- package/fluent/primitives/input.js +0 -41
- package/fluent/primitives/input.js.map +0 -1
package/constToOptionsMaps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Constants } from "@onerjs/core/Engines.js";
|
|
2
|
-
import { ParticleSystem } from "@onerjs/core/Particles.js";
|
|
1
|
+
import { Constants } from "@onerjs/core/Engines/constants.js";
|
|
2
|
+
import { ParticleSystem } from "@onerjs/core/Particles/particleSystem.js";
|
|
3
3
|
/**
|
|
4
4
|
* Used by both particleSystem and alphaBlendModes
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constToOptionsMaps.js","sourceRoot":"","sources":["../../../dev/sharedUiComponents/src/constToOptionsMaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"constToOptionsMaps.js","sourceRoot":"","sources":["../../../dev/sharedUiComponents/src/constToOptionsMaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,0CAA+B;AACnD,OAAO,EAAE,cAAc,EAAE,iDAAsC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE;IACxD,EAAE,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,CAAC,mBAAmB,EAAE;IACjE,EAAE,KAAK,EAAE,4BAA4B,EAAE,KAAK,EAAE,SAAS,CAAC,8BAA8B,EAAE;IACxF,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,CAAC,gBAAgB,EAAE;IAC3D,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,SAAS,CAAC,mBAAmB,EAAE;IAChE,EAAE,KAAK,EAAE,gBAAg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,SAAS,CAAC,SAAS,EAAE;IAC5C,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,cAAc,EAAE;IACtD,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,cAAc,EAAE;CACzD,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import { Constants } from \"core/Engines/constants\";\r\nimport { ParticleSystem } from \"core/Particles/particleSystem\";\r\n\r\n/**\r\n * Used by both particleSystem and alphaBlendModes\r\n */\r\nexport const CommonBlendModes = [\r\n { label: \"Maximized\", value: Constants.ALPHA_MAXIMIZED },\r\n { label: \"Pre-multiplied\", value: Constants.ALPHA_PREMULTIPLIED },\r\n { label: \"Pre-multiplied Porter Duff\", value: Constants.ALPHA_PREMULTIPLIED_PORTERDUFF },\r\n { label: \"Screen Mode\", value: Constants.ALPHA_SCREENMODE },\r\n { label: \"OneOne OneOne\", value: Constants.ALPHA_ONEONE_ONEONE },\r\n { label: \"Alpha to Color\", value: Constants.ALPHA_ALPHATOCOLOR },\r\n { label: \"Reverse One Minus\", value: Constants.ALPHA_REVERSEONEMINUS },\r\n { label: \"Source+Dest * (1 - SourceAlpha)\", value: Constants.ALPHA_SRC_DSTONEMINUSSRCALPHA },\r\n { label: \"OneOne OneZero\", value: Constants.ALPHA_ONEONE_ONEZERO },\r\n { label: \"Exclusion\", value: Constants.ALPHA_EXCLUSION },\r\n { label: \"Layer Accumulate\", value: Constants.ALPHA_LAYER_ACCUMULATE },\r\n];\r\n\r\n/**\r\n * Used to populated the blendMode dropdown in our various tools (Node Editor, Inspector, etc.)\r\n * The below ParticleSystem consts were defined before new Engine alpha blend modes were added, so we have to reference\r\n * the ParticleSystem.FOO consts explicitly (as the underlying const values are different - they get mapped to engine consts within baseParticleSystem.ts)\r\n */\r\nexport const BlendModeOptions = [\r\n { label: \"Add\", value: ParticleSystem.BLENDMODE_ADD },\r\n { label: \"Multiply\", value: ParticleSystem.BLENDMODE_MULTIPLY },\r\n { label: \"Multiply Add\", value: ParticleSystem.BLENDMODE_MULTIPLYADD },\r\n { label: \"One One\", value: ParticleSystem.BLENDMODE_ONEONE },\r\n { label: \"Standard\", value: ParticleSystem.BLENDMODE_STANDARD },\r\n { label: \"Subtract\", value: ParticleSystem.BLENDMODE_SUBTRACT },\r\n].concat(CommonBlendModes);\r\n\r\n/**\r\n * Used to populated the alphaMode dropdown in our various tools (Node Editor, Inspector, etc.)\r\n */\r\nexport const AlphaModeOptions = [\r\n { label: \"Combine\", value: Constants.ALPHA_COMBINE },\r\n { label: \"One One\", value: Constants.ALPHA_ONEONE },\r\n { label: \"Add\", value: Constants.ALPHA_ADD },\r\n { label: \"Subtract\", value: Constants.ALPHA_SUBTRACT },\r\n { label: \"Multiply\", value: Constants.ALPHA_MULTIPLY },\r\n].concat(CommonBlendModes);\r\n"]}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type { PropertyLineProps } from "./propertyLine.js";
|
|
2
2
|
import type { FunctionComponent } from "react";
|
|
3
|
-
import type {
|
|
3
|
+
import type { TextInputProps } from "../../primitives/textInput.js";
|
|
4
|
+
import type { SpinButtonProps } from "../../primitives/spinButton.js";
|
|
4
5
|
/**
|
|
5
6
|
* Wraps a text input in a property line
|
|
6
7
|
* @param props - PropertyLineProps and InputProps
|
|
7
8
|
* @returns property-line wrapped input component
|
|
8
9
|
*/
|
|
9
|
-
export declare const TextInputPropertyLine: FunctionComponent<
|
|
10
|
+
export declare const TextInputPropertyLine: FunctionComponent<TextInputProps & PropertyLineProps<string>>;
|
|
10
11
|
/**
|
|
11
12
|
* Wraps a number input in a property line
|
|
13
|
+
* To force integer values, use forceInt param (this is distinct from the 'step' param, which will still allow submitting an integer value. forceInt will not)
|
|
12
14
|
* @param props - PropertyLineProps and InputProps
|
|
13
15
|
* @returns property-line wrapped input component
|
|
14
16
|
*/
|
|
15
|
-
export declare const NumberInputPropertyLine: FunctionComponent<
|
|
17
|
+
export declare const NumberInputPropertyLine: FunctionComponent<SpinButtonProps & PropertyLineProps<number> & {
|
|
18
|
+
forceInt?: boolean;
|
|
19
|
+
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { PropertyLine } from "./propertyLine.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TextInput } from "../../primitives/textInput.js";
|
|
4
|
+
import { SpinButton } from "../../primitives/spinButton.js";
|
|
4
5
|
/**
|
|
5
6
|
* Wraps a text input in a property line
|
|
6
7
|
* @param props - PropertyLineProps and InputProps
|
|
@@ -9,8 +10,11 @@ import { NumberInput, TextInput } from "../../primitives/input.js";
|
|
|
9
10
|
export const TextInputPropertyLine = (props) => (_jsx(PropertyLine, { ...props, children: _jsx(TextInput, { ...props }) }));
|
|
10
11
|
/**
|
|
11
12
|
* Wraps a number input in a property line
|
|
13
|
+
* To force integer values, use forceInt param (this is distinct from the 'step' param, which will still allow submitting an integer value. forceInt will not)
|
|
12
14
|
* @param props - PropertyLineProps and InputProps
|
|
13
15
|
* @returns property-line wrapped input component
|
|
14
16
|
*/
|
|
15
|
-
export const NumberInputPropertyLine = (props) =>
|
|
17
|
+
export const NumberInputPropertyLine = (props) => {
|
|
18
|
+
return (_jsx(PropertyLine, { ...props, children: _jsx(SpinButton, { ...props }) }));
|
|
19
|
+
};
|
|
16
20
|
//# sourceMappingURL=inputPropertyLine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputPropertyLine.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/fluent/hoc/propertyLines/inputPropertyLine.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"inputPropertyLine.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/fluent/hoc/propertyLines/inputPropertyLine.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAkE,CAAC,KAAK,EAAE,EAAE,CAAC,CAC3G,KAAC,YAAY,OAAK,KAAK,YACnB,KAAC,SAAS,OAAK,KAAK,GAAI,GACb,CAClB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA4F,CAAC,KAAK,EAAE,EAAE;IACtI,OAAO,CACH,KAAC,YAAY,OAAK,KAAK,YACnB,KAAC,UAAU,OAAK,KAAK,GAAI,GACd,CAClB,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { PropertyLine } from \"./propertyLine\";\r\nimport type { PropertyLineProps } from \"./propertyLine\";\r\nimport type { FunctionComponent } from \"react\";\r\nimport type { TextInputProps } from \"../../primitives/textInput\";\r\nimport { TextInput } from \"../../primitives/textInput\";\r\nimport type { SpinButtonProps } from \"../../primitives/spinButton\";\r\nimport { SpinButton } from \"../../primitives/spinButton\";\r\n/**\r\n * Wraps a text input in a property line\r\n * @param props - PropertyLineProps and InputProps\r\n * @returns property-line wrapped input component\r\n */\r\nexport const TextInputPropertyLine: FunctionComponent<TextInputProps & PropertyLineProps<string>> = (props) => (\r\n <PropertyLine {...props}>\r\n <TextInput {...props} />\r\n </PropertyLine>\r\n);\r\n\r\n/**\r\n * Wraps a number input in a property line\r\n * To force integer values, use forceInt param (this is distinct from the 'step' param, which will still allow submitting an integer value. forceInt will not)\r\n * @param props - PropertyLineProps and InputProps\r\n * @returns property-line wrapped input component\r\n */\r\nexport const NumberInputPropertyLine: FunctionComponent<SpinButtonProps & PropertyLineProps<number> & { forceInt?: boolean }> = (props) => {\r\n return (\r\n <PropertyLine {...props}>\r\n <SpinButton {...props} />\r\n </PropertyLine>\r\n );\r\n};\r\n"]}
|
|
@@ -12,6 +12,10 @@ export type TensorPropertyLineProps<V extends Vector2 | Vector3 | Vector4 | Quat
|
|
|
12
12
|
* If passed, all sliders will use this for the max value
|
|
13
13
|
*/
|
|
14
14
|
max?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Will be displayed in the input UI to indicate the unit of measurement
|
|
17
|
+
*/
|
|
18
|
+
unit?: string;
|
|
15
19
|
/**
|
|
16
20
|
* If passed, the UX will use the conversion functions to display/update values
|
|
17
21
|
*/
|
|
@@ -25,13 +25,13 @@ const TensorPropertyLine = (props) => {
|
|
|
25
25
|
setVector(newVector);
|
|
26
26
|
props.onChange(newVector);
|
|
27
27
|
};
|
|
28
|
-
return (_jsx(PropertyLine, { ...props, expandedContent: _jsxs(_Fragment, { children: [_jsx(SyncedSliderPropertyLine, { label: "X", value: converted(vector.x), min: min, max: max, onChange: (val) => onChange(val, "x") }), _jsx(SyncedSliderPropertyLine, { label: "Y", value: converted(vector.y), min: min, max: max, onChange: (val) => onChange(val, "y") }), HasZ(vector) && _jsx(SyncedSliderPropertyLine, { label: "Z", value: converted(vector.z), min: min, max: max, onChange: (val) => onChange(val, "z") }), HasW(vector) && _jsx(SyncedSliderPropertyLine, { label: "W", value: converted(vector.w), min: min, max: max, onChange: (val) => onChange(val, "w") })] }), children: _jsx(Body1, { children: `X: ${formatted(props.value.x)} | Y: ${formatted(props.value.y)}${HasZ(props.value) ? ` | Z: ${formatted(props.value.z)}` : ""}${HasW(props.value) ? ` | W: ${formatted(props.value.w)}` : ""}` }) }));
|
|
28
|
+
return (_jsx(PropertyLine, { ...props, expandedContent: _jsxs(_Fragment, { children: [_jsx(SyncedSliderPropertyLine, { label: "X", value: converted(vector.x), min: min, max: max, onChange: (val) => onChange(val, "x"), unit: props.unit }), _jsx(SyncedSliderPropertyLine, { label: "Y", value: converted(vector.y), min: min, max: max, onChange: (val) => onChange(val, "y"), unit: props.unit }), HasZ(vector) && (_jsx(SyncedSliderPropertyLine, { label: "Z", value: converted(vector.z), min: min, max: max, onChange: (val) => onChange(val, "z"), unit: props.unit })), HasW(vector) && (_jsx(SyncedSliderPropertyLine, { label: "W", value: converted(vector.w), min: min, max: max, onChange: (val) => onChange(val, "w"), unit: props.unit }))] }), children: _jsx(Body1, { children: `X: ${formatted(props.value.x)} | Y: ${formatted(props.value.y)}${HasZ(props.value) ? ` | Z: ${formatted(props.value.z)}` : ""}${HasW(props.value) ? ` | W: ${formatted(props.value.w)}` : ""}` }) }));
|
|
29
29
|
};
|
|
30
30
|
const ToDegreesConverter = { from: Tools.ToDegrees, to: Tools.ToRadians };
|
|
31
31
|
export const RotationVectorPropertyLine = (props) => {
|
|
32
32
|
const min = props.useDegrees ? 0 : undefined;
|
|
33
33
|
const max = props.useDegrees ? 360 : undefined;
|
|
34
|
-
return _jsx(Vector3PropertyLine, { ...props, valueConverter: props.useDegrees ? ToDegreesConverter : undefined, min: min, max: max });
|
|
34
|
+
return _jsx(Vector3PropertyLine, { ...props, unit: props.useDegrees ? "deg" : "rad", valueConverter: props.useDegrees ? ToDegreesConverter : undefined, min: min, max: max });
|
|
35
35
|
};
|
|
36
36
|
const QuaternionPropertyLineInternal = TensorPropertyLine;
|
|
37
37
|
export const QuaternionPropertyLine = (props) => {
|
|
@@ -49,7 +49,7 @@ export const QuaternionPropertyLine = (props) => {
|
|
|
49
49
|
setQuat(quat);
|
|
50
50
|
props.onChange(quat);
|
|
51
51
|
};
|
|
52
|
-
return
|
|
52
|
+
return useDegrees ? (_jsx(Vector3PropertyLine, { ...restProps, nullable: false, ignoreNullable: false, value: quat.toEulerAngles(), valueConverter: ToDegreesConverter, min: min, max: max, onChange: onEulerChange, unit: "deg" })) : (_jsx(QuaternionPropertyLineInternal, { ...props, unit: "rad", nullable: false, value: quat, min: min, max: max, onChange: onQuatChange }));
|
|
53
53
|
};
|
|
54
54
|
export const Vector2PropertyLine = TensorPropertyLine;
|
|
55
55
|
export const Vector3PropertyLine = TensorPropertyLine;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v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EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,GAAI,CAC1H,CAAC;AACN,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAyE,CAAC;AAC7G,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAyE,CAAC;AAC7G,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAyE,CAAC","sourcesContent":["import { useState } from \"react\";\r\nimport type { FunctionComponent } from \"react\";\r\n\r\nimport { Body1 } from \"@fluentui/react-components\";\r\nimport { PropertyLine } from \"./propertyLine\";\r\nimport type { PrimitiveProps } from \"../../primitives/primitive\";\r\nimport type { PropertyLineProps } from \"./propertyLine\";\r\n\r\nimport { SyncedSliderPropertyLine } from \"./syncedSliderPropertyLine\";\r\nimport type { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Quaternion, Vector2, Vector4 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\nexport type TensorPropertyLineProps<V extends Vector2 | Vector3 | Vector4 | Quaternion> = PropertyLineProps<V> &\r\n PrimitiveProps<V> & {\r\n /**\r\n * If passed, all sliders will use this for the min value\r\n */\r\n min?: number;\r\n /**\r\n * If passed, all sliders will use this for the max value\r\n */\r\n max?: number;\r\n /**\r\n * If passed, the UX will use the conversion functions to display/update values\r\n */\r\n valueConverter?: {\r\n /**\r\n * Will call from(val) before displaying in the UX\r\n */\r\n from: (val: number) => number;\r\n /**\r\n * Will call to(val) before calling onChange\r\n */\r\n to: (val: number) => number;\r\n };\r\n };\r\n\r\nconst HasZ = (vector: Vector2 | Vector3 | Vector4 | Quaternion): vector is Vector3 => !(vector instanceof Vector2);\r\nconst HasW = (vector: Vector2 | Vector3 | Vector4 | Quaternion): vector is Vector4 => vector instanceof Vector4 || vector instanceof Quaternion;\r\n\r\n/**\r\n * Reusable component which renders a vector property line containing a label, vector value, and expandable XYZW values\r\n * The expanded section contains a slider/input box for each component of the vector (x, y, z, w)\r\n * @param props\r\n * @returns\r\n */\r\nconst TensorPropertyLine: FunctionComponent<TensorPropertyLineProps<Vector2 | Vector3 | Vector4 | Quaternion>> = (props) => {\r\n const converted = (val: number) => (props.valueConverter ? props.valueConverter.from(val) : val);\r\n const formatted = (val: number) => converted(val).toFixed(2);\r\n\r\n const [vector, setVector] = useState(props.value);\r\n const { min, max } = props;\r\n\r\n const onChange = (val: number, key: \"x\" | \"y\" | \"z\" | \"w\") => {\r\n const value = props.valueConverter ? props.valueConverter.to(val) : val;\r\n const newVector = vector.clone();\r\n (newVector as Vector4)[key] = value; // The syncedSlider for 'w' is only rendered when vector is a Vector4, so this is safe\r\n\r\n setVector(newVector);\r\n props.onChange(newVector);\r\n };\r\n\r\n return (\r\n <PropertyLine\r\n {...props}\r\n expandedContent={\r\n <>\r\n <SyncedSliderPropertyLine label=\"X\" value={converted(vector.x)} min={min} max={max} onChange={(val) => onChange(val, \"x\")} />\r\n <SyncedSliderPropertyLine label=\"Y\" value={converted(vector.y)} min={min} max={max} onChange={(val) => onChange(val, \"y\")} />\r\n {HasZ(vector) && <SyncedSliderPropertyLine label=\"Z\" value={converted(vector.z)} min={min} max={max} onChange={(val) => onChange(val, \"z\")} />}\r\n {HasW(vector) && <SyncedSliderPropertyLine label=\"W\" value={converted(vector.w)} min={min} max={max} onChange={(val) => onChange(val, \"w\")} />}\r\n </>\r\n }\r\n >\r\n <Body1>{`X: ${formatted(props.value.x)} | Y: ${formatted(props.value.y)}${HasZ(props.value) ? ` | Z: ${formatted(props.value.z)}` : \"\"}${HasW(props.value) ? ` | W: ${formatted(props.value.w)}` : \"\"}`}</Body1>\r\n </PropertyLine>\r\n );\r\n};\r\n\r\ntype RotationVectorPropertyLineProps = TensorPropertyLineProps<Vector3> & {\r\n /**\r\n * Display angles as degrees instead of radians\r\n */\r\n useDegrees?: boolean;\r\n};\r\n\r\nconst ToDegreesConverter = { from: Tools.ToDegrees, to: Tools.ToRadians };\r\nexport const RotationVectorPropertyLine: FunctionComponent<RotationVectorPropertyLineProps> = (props) => {\r\n const min = props.useDegrees ? 0 : undefined;\r\n const max = props.useDegrees ? 360 : undefined;\r\n return <Vector3PropertyLine {...props} valueConverter={props.useDegrees ? ToDegreesConverter : undefined} min={min} max={max} />;\r\n};\r\n\r\ntype QuaternionPropertyLineProps = TensorPropertyLineProps<Quaternion> & {\r\n /**\r\n * Display angles as degrees instead of radians\r\n */\r\n useDegrees?: boolean;\r\n};\r\nconst QuaternionPropertyLineInternal = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Quaternion>>;\r\nexport const QuaternionPropertyLine: FunctionComponent<QuaternionPropertyLineProps> = (props) => {\r\n const min = props.useDegrees ? 0 : undefined;\r\n const max = props.useDegrees ? 360 : undefined;\r\n const [quat, setQuat] = useState(props.value);\r\n\r\n // Extract only the properties that exist on QuaternionPropertyLineProps\r\n const { useDegrees, ...restProps } = props;\r\n\r\n const onQuatChange = (val: Quaternion) => {\r\n setQuat(val);\r\n props.onChange(val);\r\n };\r\n\r\n const onEulerChange = (val: Vector3) => {\r\n const quat = Quaternion.FromEulerAngles(val.x, val.y, val.z);\r\n setQuat(quat);\r\n props.onChange(quat);\r\n };\r\n\r\n return props.useDegrees ? (\r\n <Vector3PropertyLine\r\n {...restProps}\r\n nullable={false}\r\n ignoreNullable={false}\r\n value={quat.toEulerAngles()}\r\n valueConverter={ToDegreesConverter}\r\n min={min}\r\n max={max}\r\n onChange={onEulerChange}\r\n />\r\n ) : (\r\n <QuaternionPropertyLineInternal {...props} nullable={false} value={quat} min={min} max={max} onChange={onQuatChange} />\r\n );\r\n};\r\nexport const Vector2PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector2>>;\r\nexport const Vector3PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector3>>;\r\nexport const Vector4PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector4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B,OACZ,SAAS,EACb,QAAQ,EAAE,KAAK,EACf,cAAc,EAAE,KAAK,EACrB,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,EAC3B,cAAc,EAAE,kBAAkB,EAClC,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAC,KAAK,GACZ,CACL,CAAC,CAAC,CAAC,CACA,KAAC,8BAA8B,OAAK,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,GAAI,CACvI,CAAC;AACN,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAyE,CAAC;AAC7G,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAyE,CAAC;AAC7G,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAyE,CAAC","sourcesContent":["import { useState } from \"react\";\r\nimport type { FunctionComponent } from \"react\";\r\n\r\nimport { Body1 } from \"@fluentui/react-components\";\r\nimport { PropertyLine } from \"./propertyLine\";\r\nimport type { PrimitiveProps } from \"../../primitives/primitive\";\r\nimport type { PropertyLineProps } from \"./propertyLine\";\r\n\r\nimport { SyncedSliderPropertyLine } from \"./syncedSliderPropertyLine\";\r\nimport type { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Quaternion, Vector2, Vector4 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\nexport type TensorPropertyLineProps<V extends Vector2 | Vector3 | Vector4 | Quaternion> = PropertyLineProps<V> &\r\n PrimitiveProps<V> & {\r\n /**\r\n * If passed, all sliders will use this for the min value\r\n */\r\n min?: number;\r\n /**\r\n * If passed, all sliders will use this for the max value\r\n */\r\n max?: number;\r\n /**\r\n * Will be displayed in the input UI to indicate the unit of measurement\r\n */\r\n unit?: string;\r\n /**\r\n * If passed, the UX will use the conversion functions to display/update values\r\n */\r\n valueConverter?: {\r\n /**\r\n * Will call from(val) before displaying in the UX\r\n */\r\n from: (val: number) => number;\r\n /**\r\n * Will call to(val) before calling onChange\r\n */\r\n to: (val: number) => number;\r\n };\r\n };\r\n\r\nconst HasZ = (vector: Vector2 | Vector3 | Vector4 | Quaternion): vector is Vector3 => !(vector instanceof Vector2);\r\nconst HasW = (vector: Vector2 | Vector3 | Vector4 | Quaternion): vector is Vector4 => vector instanceof Vector4 || vector instanceof Quaternion;\r\n\r\n/**\r\n * Reusable component which renders a vector property line containing a label, vector value, and expandable XYZW values\r\n * The expanded section contains a slider/input box for each component of the vector (x, y, z, w)\r\n * @param props\r\n * @returns\r\n */\r\nconst TensorPropertyLine: FunctionComponent<TensorPropertyLineProps<Vector2 | Vector3 | Vector4 | Quaternion>> = (props) => {\r\n const converted = (val: number) => (props.valueConverter ? props.valueConverter.from(val) : val);\r\n const formatted = (val: number) => converted(val).toFixed(2);\r\n\r\n const [vector, setVector] = useState(props.value);\r\n const { min, max } = props;\r\n\r\n const onChange = (val: number, key: \"x\" | \"y\" | \"z\" | \"w\") => {\r\n const value = props.valueConverter ? props.valueConverter.to(val) : val;\r\n const newVector = vector.clone();\r\n (newVector as Vector4)[key] = value; // The syncedSlider for 'w' is only rendered when vector is a Vector4, so this is safe\r\n\r\n setVector(newVector);\r\n props.onChange(newVector);\r\n };\r\n\r\n return (\r\n <PropertyLine\r\n {...props}\r\n expandedContent={\r\n <>\r\n <SyncedSliderPropertyLine label=\"X\" value={converted(vector.x)} min={min} max={max} onChange={(val) => onChange(val, \"x\")} unit={props.unit} />\r\n <SyncedSliderPropertyLine label=\"Y\" value={converted(vector.y)} min={min} max={max} onChange={(val) => onChange(val, \"y\")} unit={props.unit} />\r\n {HasZ(vector) && (\r\n <SyncedSliderPropertyLine label=\"Z\" value={converted(vector.z)} min={min} max={max} onChange={(val) => onChange(val, \"z\")} unit={props.unit} />\r\n )}\r\n {HasW(vector) && (\r\n <SyncedSliderPropertyLine label=\"W\" value={converted(vector.w)} min={min} max={max} onChange={(val) => onChange(val, \"w\")} unit={props.unit} />\r\n )}\r\n </>\r\n }\r\n >\r\n <Body1>{`X: ${formatted(props.value.x)} | Y: ${formatted(props.value.y)}${HasZ(props.value) ? ` | Z: ${formatted(props.value.z)}` : \"\"}${HasW(props.value) ? ` | W: ${formatted(props.value.w)}` : \"\"}`}</Body1>\r\n </PropertyLine>\r\n );\r\n};\r\n\r\ntype RotationVectorPropertyLineProps = TensorPropertyLineProps<Vector3> & {\r\n /**\r\n * Display angles as degrees instead of radians\r\n */\r\n useDegrees?: boolean;\r\n};\r\n\r\nconst ToDegreesConverter = { from: Tools.ToDegrees, to: Tools.ToRadians };\r\nexport const RotationVectorPropertyLine: FunctionComponent<RotationVectorPropertyLineProps> = (props) => {\r\n const min = props.useDegrees ? 0 : undefined;\r\n const max = props.useDegrees ? 360 : undefined;\r\n return <Vector3PropertyLine {...props} unit={props.useDegrees ? \"deg\" : \"rad\"} valueConverter={props.useDegrees ? ToDegreesConverter : undefined} min={min} max={max} />;\r\n};\r\n\r\ntype QuaternionPropertyLineProps = TensorPropertyLineProps<Quaternion> & {\r\n /**\r\n * Display angles as degrees instead of radians\r\n */\r\n useDegrees?: boolean;\r\n};\r\nconst QuaternionPropertyLineInternal = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Quaternion>>;\r\nexport const QuaternionPropertyLine: FunctionComponent<QuaternionPropertyLineProps> = (props) => {\r\n const min = props.useDegrees ? 0 : undefined;\r\n const max = props.useDegrees ? 360 : undefined;\r\n const [quat, setQuat] = useState(props.value);\r\n\r\n // Extract only the properties that exist on QuaternionPropertyLineProps\r\n const { useDegrees, ...restProps } = props;\r\n\r\n const onQuatChange = (val: Quaternion) => {\r\n setQuat(val);\r\n props.onChange(val);\r\n };\r\n\r\n const onEulerChange = (val: Vector3) => {\r\n const quat = Quaternion.FromEulerAngles(val.x, val.y, val.z);\r\n setQuat(quat);\r\n props.onChange(quat);\r\n };\r\n\r\n return useDegrees ? (\r\n <Vector3PropertyLine\r\n {...restProps}\r\n nullable={false}\r\n ignoreNullable={false}\r\n value={quat.toEulerAngles()}\r\n valueConverter={ToDegreesConverter}\r\n min={min}\r\n max={max}\r\n onChange={onEulerChange}\r\n unit=\"deg\"\r\n />\r\n ) : (\r\n <QuaternionPropertyLineInternal {...props} unit={\"rad\"} nullable={false} value={quat} min={min} max={max} onChange={onQuatChange} />\r\n );\r\n};\r\nexport const Vector2PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector2>>;\r\nexport const Vector3PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector3>>;\r\nexport const Vector4PropertyLine = TensorPropertyLine as FunctionComponent<TensorPropertyLineProps<Vector4>>;\r\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Children, isValidElement, useMemo } from "react";
|
|
3
|
-
import {
|
|
2
|
+
import { Children, isValidElement, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { AccordionHeader, AccordionItem, AccordionPanel, Accordion as FluentAccordion, Subtitle1, makeStyles, tokens } from "@fluentui/react-components";
|
|
4
4
|
const useStyles = makeStyles({
|
|
5
5
|
accordion: {
|
|
6
6
|
overflowX: "hidden",
|
|
@@ -39,7 +39,31 @@ export const Accordion = (props) => {
|
|
|
39
39
|
return null;
|
|
40
40
|
})?.filter(Boolean) ?? []);
|
|
41
41
|
}, [children]);
|
|
42
|
-
|
|
42
|
+
// Tracks open items, and used to tell the Accordion which sections should be expanded.
|
|
43
|
+
const [openItems, setOpenItems] = useState(validChildren.filter((child) => !child.collapseByDefault).map((child) => child.title));
|
|
44
|
+
// Tracks closed items, which is needed so that when the children change, we only update the open/closed state
|
|
45
|
+
// (depending on the collapseByDefault prop) for items that have not been explicitly opened or closed.
|
|
46
|
+
const [closedItems, setClosedItems] = useState(validChildren.filter((child) => child.collapseByDefault).map((child) => child.title));
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
for (const defaultOpenItem of validChildren.filter((child) => !child.collapseByDefault).map((child) => child.title)) {
|
|
49
|
+
// If a child is not marked as collapseByDefault, then it should be opened by default, and
|
|
50
|
+
// it is only "default" if it hasn't already been explicitly added to the opened or closed list.
|
|
51
|
+
if (!closedItems.includes(defaultOpenItem) && !openItems.includes(defaultOpenItem)) {
|
|
52
|
+
setOpenItems((prev) => [...prev, defaultOpenItem]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, [validChildren]);
|
|
56
|
+
const onToggle = useCallback((event, data) => {
|
|
57
|
+
if (data.openItems.includes(data.value)) {
|
|
58
|
+
setOpenItems((prev) => [...prev, data.value]);
|
|
59
|
+
setClosedItems((prev) => prev.filter((item) => item !== data.value));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
setClosedItems((prev) => [...prev, data.value]);
|
|
63
|
+
setOpenItems((prev) => prev.filter((item) => item !== data.value));
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
return (_jsx(FluentAccordion, { className: classes.accordion, collapsible: true, multiple: true, onToggle: onToggle, openItems: openItems, ...rest, children: validChildren.map((child) => {
|
|
43
67
|
return (_jsxs(AccordionItem, { value: child.title, children: [_jsx(AccordionHeader, { expandIconPosition: "end", children: _jsx(Subtitle1, { children: child.title }) }), _jsx(AccordionPanel, { children: _jsx("div", { className: classes.panelDiv, children: child.content }) })] }, child.title));
|
|
44
68
|
}) }));
|
|
45
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accordion.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/accordion.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"accordion.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/accordion.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,Q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AAE,KAAK,CAAC,KAAK,GAAa,GACtB,EAClB,KAAC,cAAc,cACX,cAAK,SAAS,EAAE,OAAO,CAAC,QAAQ,YAAG,KAAK,CAAC,OAAO,GAAO,GAC1C,KAND,KAAK,CAAC,KAAK,CAOf,CACnB,CAAC;QACN,CAAC,CAAC,GACY,CACrB,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { AccordionToggleData, AccordionToggleEvent } from \"@fluentui/react-components\";\r\nimport type { FunctionComponent, PropsWithChildren } from \"react\";\r\n\r\nimport { Children, isValidElement, useCallback, useEffect, useMemo, useState } from \"react\";\r\n\r\nimport { AccordionHeader, AccordionItem, AccordionPanel, Accordion as FluentAccordion, Subtitle1, makeStyles, tokens } from \"@fluentui/react-components\";\r\n\r\nconst useStyles = makeStyles({\r\n accordion: {\r\n overflowX: \"hidden\",\r\n overflowY: \"auto\",\r\n paddingBottom: tokens.spacingVerticalM,\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n rowGap: tokens.spacingVerticalM,\r\n height: \"100%\",\r\n },\r\n panelDiv: {\r\n display: \"flex\",\r\n flexDirection: \"column\",\r\n overflow: \"hidden\",\r\n },\r\n});\r\n\r\nexport type AccordionSectionProps = {\r\n title: string;\r\n collapseByDefault?: boolean;\r\n};\r\n\r\nexport const AccordionSection: FunctionComponent<PropsWithChildren<AccordionSectionProps>> = (props) => {\r\n const classes = useStyles();\r\n\r\n return <div className={classes.panelDiv}>{props.children}</div>;\r\n};\r\n\r\nexport const Accordion: FunctionComponent<PropsWithChildren> = (props) => {\r\n const classes = useStyles();\r\n\r\n const { children, ...rest } = props;\r\n const validChildren = useMemo(() => {\r\n return (\r\n Children.map(children, (child) => {\r\n if (isValidElement(child)) {\r\n const childProps = child.props as Partial<AccordionSectionProps>;\r\n if (childProps.title) {\r\n return {\r\n title: childProps.title,\r\n collapseByDefault: childProps.collapseByDefault,\r\n content: child,\r\n };\r\n }\r\n }\r\n return null;\r\n })?.filter(Boolean) ?? []\r\n );\r\n }, [children]);\r\n\r\n // Tracks open items, and used to tell the Accordion which sections should be expanded.\r\n const [openItems, setOpenItems] = useState(validChildren.filter((child) => !child.collapseByDefault).map((child) => child.title));\r\n\r\n // Tracks closed items, which is needed so that when the children change, we only update the open/closed state\r\n // (depending on the collapseByDefault prop) for items that have not been explicitly opened or closed.\r\n const [closedItems, setClosedItems] = useState(validChildren.filter((child) => child.collapseByDefault).map((child) => child.title));\r\n\r\n useEffect(() => {\r\n for (const defaultOpenItem of validChildren.filter((child) => !child.collapseByDefault).map((child) => child.title)) {\r\n // If a child is not marked as collapseByDefault, then it should be opened by default, and\r\n // it is only \"default\" if it hasn't already been explicitly added to the opened or closed list.\r\n if (!closedItems.includes(defaultOpenItem) && !openItems.includes(defaultOpenItem)) {\r\n setOpenItems((prev) => [...prev, defaultOpenItem]);\r\n }\r\n }\r\n }, [validChildren]);\r\n\r\n const onToggle = useCallback((event: AccordionToggleEvent, data: AccordionToggleData<string>) => {\r\n if (data.openItems.includes(data.value)) {\r\n setOpenItems((prev) => [...prev, data.value]);\r\n setClosedItems((prev) => prev.filter((item) => item !== data.value));\r\n } else {\r\n setClosedItems((prev) => [...prev, data.value]);\r\n setOpenItems((prev) => prev.filter((item) => item !== data.value));\r\n }\r\n }, []);\r\n\r\n return (\r\n <FluentAccordion className={classes.accordion} collapsible multiple onToggle={onToggle} openItems={openItems} {...rest}>\r\n {validChildren.map((child) => {\r\n return (\r\n <AccordionItem key={child.title} value={child.title}>\r\n <AccordionHeader expandIconPosition=\"end\">\r\n <Subtitle1>{child.title}</Subtitle1>\r\n </AccordionHeader>\r\n <AccordionPanel>\r\n <div className={classes.panelDiv}>{child.content}</div>\r\n </AccordionPanel>\r\n </AccordionItem>\r\n );\r\n })}\r\n </FluentAccordion>\r\n );\r\n};\r\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FunctionComponent, PropsWithChildren } from "react";
|
|
2
2
|
type CollapseProps = {
|
|
3
3
|
visible: boolean;
|
|
4
|
+
orientation?: "horizontal" | "vertical";
|
|
4
5
|
};
|
|
5
6
|
/**
|
|
6
7
|
* Wraps the passed in children with a fluent collapse component, handling smooth animation when visible prop changes
|
|
@@ -4,6 +4,7 @@ import { Collapse as FluentCollapse } from "@fluentui/react-motion-components-pr
|
|
|
4
4
|
const useCollapseStyles = makeStyles({
|
|
5
5
|
collapseContent: {
|
|
6
6
|
overflow: "hidden",
|
|
7
|
+
display: "flex",
|
|
7
8
|
},
|
|
8
9
|
});
|
|
9
10
|
/**
|
|
@@ -14,6 +15,6 @@ const useCollapseStyles = makeStyles({
|
|
|
14
15
|
*/
|
|
15
16
|
export const Collapse = (props) => {
|
|
16
17
|
const classes = useCollapseStyles();
|
|
17
|
-
return (_jsx(FluentCollapse, { visible: props.visible, children: _jsx("div", { className: classes.collapseContent, children: props.children }) }));
|
|
18
|
+
return (_jsx(FluentCollapse, { visible: props.visible, orientation: props.orientation, children: _jsx("div", { className: classes.collapseContent, children: props.children }) }));
|
|
18
19
|
};
|
|
19
20
|
//# sourceMappingURL=collapse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collapse.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/collapse.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"collapse.js","sourceRoot":"","sources":["../../../../../dev/sharedUiComponents/src/fluent/primitives/collapse.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAQvF,MAAM,iBAAiB,GAAG,UAAU,CAAC;IACjC,eAAe,EAAE;QACb,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE,MAAM;KAClB;CACJ,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAwD,CAAC,KAAK,EAAE,EAAE;IACnF,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,OAAO,CACH,KAAC,cAAc,IAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,YAClE,cAAK,SAAS,EAAE,OAAO,CAAC,eAAe,YAAG,KAAK,CAAC,QAAQ,GAAO,GAClD,CACpB,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { makeStyles } from \"@fluentui/react-components\";\r\nimport { Collapse as FluentCollapse } from \"@fluentui/react-motion-components-preview\";\r\nimport type { FunctionComponent, PropsWithChildren } from \"react\";\r\n\r\ntype CollapseProps = {\r\n visible: boolean;\r\n orientation?: \"horizontal\" | \"vertical\";\r\n};\r\n\r\nconst useCollapseStyles = makeStyles({\r\n collapseContent: {\r\n overflow: \"hidden\",\r\n display: \"flex\",\r\n },\r\n});\r\n\r\n/**\r\n * Wraps the passed in children with a fluent collapse component, handling smooth animation when visible prop changes\r\n * NOTE: When passing in children, prefer react fragment over empty div to avoid bloating the react tree with an unnecessary div\r\n * @param props\r\n * @returns\r\n */\r\nexport const Collapse: FunctionComponent<PropsWithChildren<CollapseProps>> = (props) => {\r\n const classes = useCollapseStyles();\r\n return (\r\n <FluentCollapse visible={props.visible} orientation={props.orientation}>\r\n <div className={classes.collapseContent}>{props.children}</div>\r\n </FluentCollapse>\r\n );\r\n};\r\n"]}
|
|
@@ -5,9 +5,7 @@ export type ColorPickerProps<C extends Color3 | Color4> = {
|
|
|
5
5
|
isLinearMode?: boolean;
|
|
6
6
|
} & PrimitiveProps<C>;
|
|
7
7
|
export declare const ColorPickerPopup: FunctionComponent<ColorPickerProps<Color3 | Color4>>;
|
|
8
|
-
type HsvKey = "h" | "s" | "v";
|
|
9
8
|
export type InputHexProps = PrimitiveProps<Color3 | Color4> & {
|
|
10
|
-
label?: string;
|
|
11
9
|
linearHex?: boolean;
|
|
12
10
|
isLinearMode?: boolean;
|
|
13
11
|
};
|
|
@@ -20,11 +18,9 @@ export type InputHexProps = PrimitiveProps<Color3 | Color4> & {
|
|
|
20
18
|
* @returns
|
|
21
19
|
*/
|
|
22
20
|
export declare const InputHexField: FunctionComponent<InputHexProps>;
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
label: string;
|
|
21
|
+
type HsvKey = "h" | "s" | "v";
|
|
22
|
+
type InputHsvFieldProps = PrimitiveProps<Color3 | Color4> & {
|
|
26
23
|
hsvKey: HsvKey;
|
|
27
|
-
onChange: (color: Color3 | Color4) => void;
|
|
28
24
|
max: number;
|
|
29
25
|
scale?: number;
|
|
30
26
|
};
|
|
@@ -2,8 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
/* eslint-disable jsdoc/require-returns */
|
|
3
3
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
4
4
|
import { useState, useEffect, useCallback } from "react";
|
|
5
|
-
import {
|
|
5
|
+
import { ColorPicker as FluentColorPicker, ColorSlider, ColorArea, AlphaSlider, Link, makeStyles, Popover, PopoverSurface, PopoverTrigger, tokens, Body1Strong, ColorSwatch, } from "@fluentui/react-components";
|
|
6
6
|
import { Color3, Color4 } from "@onerjs/core/Maths/math.color.js";
|
|
7
|
+
import { SpinButton } from "./spinButton.js";
|
|
8
|
+
import { TextInput } from "./textInput.js";
|
|
7
9
|
const useColorPickerStyles = makeStyles({
|
|
8
10
|
colorPickerContainer: {
|
|
9
11
|
width: "325px",
|
|
@@ -36,7 +38,7 @@ const useColorPickerStyles = makeStyles({
|
|
|
36
38
|
width: "80px",
|
|
37
39
|
},
|
|
38
40
|
spinButton: {
|
|
39
|
-
|
|
41
|
+
width: "50px",
|
|
40
42
|
},
|
|
41
43
|
container: {
|
|
42
44
|
display: "flex",
|
|
@@ -66,8 +68,9 @@ export const ColorPickerPopup = (props) => {
|
|
|
66
68
|
align: "start",
|
|
67
69
|
overflowBoundary: document.body,
|
|
68
70
|
autoSize: true,
|
|
69
|
-
}, open: popoverOpen, trapFocus: true, onOpenChange: (_, data) => setPopoverOpen(data.open), children: [_jsx(PopoverTrigger, { disableButtonEnhancement: true, children: _jsx(ColorSwatch, { borderColor: tokens.colorNeutralShadowKeyDarker, size: "small", color: color.toHexString(), value: color.toHexString().slice(1) }) }), _jsx(PopoverSurface, { children: _jsxs("div", { className: classes.colorPickerContainer, children: [_jsxs(
|
|
71
|
+
}, open: popoverOpen, trapFocus: true, onOpenChange: (_, data) => setPopoverOpen(data.open), children: [_jsx(PopoverTrigger, { disableButtonEnhancement: true, children: _jsx(ColorSwatch, { borderColor: tokens.colorNeutralShadowKeyDarker, size: "small", color: color.toHexString(), value: color.toHexString().slice(1) }) }), _jsx(PopoverSurface, { children: _jsxs("div", { className: classes.colorPickerContainer, children: [_jsxs(FluentColorPicker, { color: rgbaToHsv(color), onColorChange: handleColorPickerChange, children: [_jsx(ColorArea, { inputX: { "aria-label": "Saturation" }, inputY: { "aria-label": "Brightness" } }), _jsx(ColorSlider, { "aria-label": "Hue" }), color instanceof Color4 && _jsx(AlphaSlider, { "aria-label": "Alpha" })] }), _jsxs("div", { className: classes.container, children: [_jsxs("div", { className: classes.row, children: [_jsx("div", { className: classes.previewColor, style: { backgroundColor: color.toHexString() } }), _jsx(InputHexField, { title: "Gamma Hex", value: color, isLinearMode: props.isLinearMode, onChange: handleChange }), _jsx(InputHexField, { title: "Linear Hex", linearHex: true, isLinearMode: props.isLinearMode, value: color, onChange: handleChange })] }), _jsxs("div", { className: classes.row, children: [_jsx(InputRgbField, { title: "Red", value: color, rgbKey: "r", onChange: handleChange }), _jsx(InputRgbField, { title: "Green", value: color, rgbKey: "g", onChange: handleChange }), _jsx(InputRgbField, { title: "Blue", value: color, rgbKey: "b", onChange: handleChange }), _jsx(InputAlphaField, { color: color, onChange: handleChange })] }), _jsxs("div", { className: classes.row, children: [_jsx(InputHsvField, { title: "Hue", value: color, hsvKey: "h", max: 360, onChange: handleChange }), _jsx(InputHsvField, { title: "Saturation", value: color, hsvKey: "s", max: 100, scale: 100, onChange: handleChange }), _jsx(InputHsvField, { title: "Value", value: color, hsvKey: "v", max: 100, scale: 100, onChange: handleChange })] })] })] }) })] }));
|
|
70
72
|
};
|
|
73
|
+
const HEX_REGEX = RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/);
|
|
71
74
|
/**
|
|
72
75
|
* Component which displays the passed in color's HEX value, either in linearSpace (if linearHex is true) or in gamma space
|
|
73
76
|
* When the hex color is changed by user, component calculates the new Color3/4 value and calls onChange
|
|
@@ -77,34 +80,34 @@ export const ColorPickerPopup = (props) => {
|
|
|
77
80
|
* @returns
|
|
78
81
|
*/
|
|
79
82
|
export const InputHexField = (props) => {
|
|
80
|
-
const id = useId("hex-input");
|
|
81
83
|
const styles = useColorPickerStyles();
|
|
82
|
-
const {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
const { title, value, onChange, linearHex, isLinearMode } = props;
|
|
85
|
+
return (_jsx("div", { className: styles.colorFieldWrapper, children: _jsx(TextInput, { disabled: linearHex ? !isLinearMode : false, className: styles.input, value: linearHex ? value.toLinearSpace().toHexString() : value.toHexString(), validator: (val) => val != "" && HEX_REGEX.test(val), onChange: (val) => (linearHex ? onChange(Color3.FromHexString(val).toGammaSpace()) : onChange(Color3.FromHexString(val))), infoLabel: title
|
|
86
|
+
? {
|
|
87
|
+
label: title,
|
|
88
|
+
// If not representing a linearHex, no info is needed.
|
|
89
|
+
info: !props.linearHex ? undefined : !isLinearMode ? ( // If representing a linear hex but we are in gammaMode, simple message explaining why linearHex is disabled
|
|
90
|
+
_jsx(_Fragment, { children: " This color picker is attached to an entity whose color is stored in gamma space, so we are showing linear hex in disabled view " })) : (
|
|
91
|
+
// If representing a linear hex and we are in linearMode, give information about how to use these hex values
|
|
92
|
+
_jsxs(_Fragment, { children: ["This color picker is attached to an entity whose color is stored in linear space (ex: PBR Material), and Babylon converts the color to gamma space before rendering on screen because the human eye is best at processing colors in gamma space. We thus also want to display the color picker in gamma space so that the color chosen here will match the color seen in your entity.", _jsx("br", {}), "If you want to copy/paste the HEX into your code, you can either use", _jsx(Body1Strong, { children: "Color3.FromHexString(LINEAR_HEX)" }), _jsx("br", {}), "or", _jsx("br", {}), _jsx(Body1Strong, { children: "Color3.FromHexString(GAMMA_HEX).toLinearSpace()" }), _jsx("br", {}), _jsx("br", {}), _jsx(Link, { href: "https://doc.babylonjs.com/preparingArtForBabylon/controllingColorSpace/", children: " Read more in our docs! " })] })),
|
|
93
|
+
}
|
|
94
|
+
: undefined }) }));
|
|
92
95
|
};
|
|
93
96
|
const InputRgbField = (props) => {
|
|
94
|
-
const {
|
|
95
|
-
const id = useId(`${label.toLowerCase()}-input`);
|
|
97
|
+
const { value, onChange, title, rgbKey } = props;
|
|
96
98
|
const classes = useColorPickerStyles();
|
|
97
|
-
const handleChange = useCallback((
|
|
98
|
-
const
|
|
99
|
-
if (val === null || Number.isNaN(val) || !NUMBER_REGEX.test(val.toString())) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const newColor = color.clone();
|
|
99
|
+
const handleChange = useCallback((val) => {
|
|
100
|
+
const newColor = value.clone();
|
|
103
101
|
newColor[rgbKey] = val / 255.0; // Convert to 0-1 range
|
|
104
102
|
onChange(newColor);
|
|
105
|
-
}, [
|
|
106
|
-
return (
|
|
103
|
+
}, [value, onChange, rgbKey]);
|
|
104
|
+
return (_jsx("div", { className: classes.colorFieldWrapper, children: _jsx(SpinButton, { title: title, infoLabel: title ? { label: title } : undefined, className: classes.spinButton, min: 0, max: 255, value: Math.round(value[rgbKey] * 255), forceInt: true, onChange: handleChange }) }));
|
|
107
105
|
};
|
|
106
|
+
function rgbaToHsv(color) {
|
|
107
|
+
const c = new Color3(color.r, color.g, color.b);
|
|
108
|
+
const hsv = c.toHSV();
|
|
109
|
+
return { h: hsv.r, s: hsv.g, v: hsv.b, a: color.a };
|
|
110
|
+
}
|
|
108
111
|
/**
|
|
109
112
|
* In the HSV (Hue, Saturation, Value) color model, Hue (H) ranges from 0 to 360 degrees, representing the color's position on the color wheel.
|
|
110
113
|
* Saturation (S) ranges from 0 to 100%, indicating the intensity or purity of the color, with 0 being shades of gray and 100 being a fully saturated color.
|
|
@@ -112,24 +115,19 @@ const InputRgbField = (props) => {
|
|
|
112
115
|
* @param props - The properties for the InputHsvField component.
|
|
113
116
|
*/
|
|
114
117
|
export const InputHsvField = (props) => {
|
|
115
|
-
const {
|
|
116
|
-
const id = useId(`${label.toLowerCase()}-input`);
|
|
118
|
+
const { value, title, hsvKey, max, onChange, scale = 1 } = props;
|
|
117
119
|
const classes = useColorPickerStyles();
|
|
118
|
-
const handleChange = useCallback((
|
|
119
|
-
const val = data.value ?? parseFloat(data.displayValue ?? "");
|
|
120
|
-
if (val === null || Number.isNaN(val) || !NUMBER_REGEX.test(val.toString())) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
120
|
+
const handleChange = useCallback((val) => {
|
|
123
121
|
// Convert current color to HSV, update the new hsv value, then call onChange prop
|
|
124
|
-
const hsv = rgbaToHsv(
|
|
122
|
+
const hsv = rgbaToHsv(value);
|
|
125
123
|
hsv[hsvKey] = val / scale;
|
|
126
124
|
let newColor = Color3.FromHSV(hsv.h, hsv.s, hsv.v);
|
|
127
|
-
if (
|
|
128
|
-
newColor = Color4.FromColor3(newColor,
|
|
125
|
+
if (value instanceof Color4) {
|
|
126
|
+
newColor = Color4.FromColor3(newColor, value.a ?? 1);
|
|
129
127
|
}
|
|
130
128
|
props.onChange(newColor);
|
|
131
|
-
}, [
|
|
132
|
-
return (
|
|
129
|
+
}, [value, onChange, hsvKey, scale]);
|
|
130
|
+
return (_jsx("div", { className: classes.colorFieldWrapper, children: _jsx(SpinButton, { infoLabel: title ? { label: title } : undefined, title: title, className: classes.spinButton, min: 0, max: max, value: Math.round(rgbaToHsv(value)[hsvKey] * scale), forceInt: true, onChange: handleChange }) }));
|
|
133
131
|
};
|
|
134
132
|
/**
|
|
135
133
|
* Displays the alpha value of a color, either in the disabled state (if color is Color3) or as a spin button (if color is Color4).
|
|
@@ -138,10 +136,8 @@ export const InputHsvField = (props) => {
|
|
|
138
136
|
*/
|
|
139
137
|
const InputAlphaField = (props) => {
|
|
140
138
|
const classes = useColorPickerStyles();
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const onChange = (_, data) => {
|
|
144
|
-
const value = data.value ?? parseFloat(data.displayValue ?? "");
|
|
139
|
+
const { color, onChange } = props;
|
|
140
|
+
const handleChange = useCallback((value) => {
|
|
145
141
|
if (Number.isNaN(value) || value < 0 || value > 1) {
|
|
146
142
|
return;
|
|
147
143
|
}
|
|
@@ -153,13 +149,10 @@ const InputAlphaField = (props) => {
|
|
|
153
149
|
else {
|
|
154
150
|
return Color4.FromColor3(color, value);
|
|
155
151
|
}
|
|
156
|
-
};
|
|
157
|
-
return (
|
|
152
|
+
}, [onChange]);
|
|
153
|
+
return (_jsx("div", { className: classes.colorFieldWrapper, children: _jsx(SpinButton, { disabled: color instanceof Color3, min: 0, max: 1, className: classes.spinButton, value: color instanceof Color3 ? 1 : color.a, step: 0.01, onChange: handleChange, infoLabel: {
|
|
154
|
+
label: "Alpha",
|
|
155
|
+
info: color instanceof Color3 ? (_jsx(_Fragment, { children: "Because this color picker is representing a Color3, we do not permit modifying alpha from the color picker. You can however modify the entity's alpha property directly, either in code via entity.alpha OR via inspector's transparency section." })) : undefined,
|
|
156
|
+
} }) }));
|
|
158
157
|
};
|
|
159
|
-
const NUMBER_REGEX = /^\d+$/;
|
|
160
|
-
function rgbaToHsv(color) {
|
|
161
|
-
const c = new Color3(color.r, color.g, color.b);
|
|
162
|
-
const hsv = c.toHSV();
|
|
163
|
-
return { h: hsv.r, s: hsv.g, v: hsv.b, a: color.a };
|
|
164
|
-
}
|
|
165
158
|
//# sourceMappingURL=colorPicker.js.map
|