Skip to content

Commit d06a6a5

Browse files
committed
chore: Tracking down undefined value
1 parent ce93e2b commit d06a6a5

File tree

5 files changed

+58
-45
lines changed

5 files changed

+58
-45
lines changed

demo/src/sandboxes/leva-busy/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Controls() {
4848
const data = useControls({
4949
vector2d: [10, 10],
5050
vector3d: [10, 10, 10],
51-
vector3j: vector3j([20, 20, 20]),
51+
vector3j: vector3j({ value: { x: 20, y: 20, z: 20 }, lock: true }),
5252
curve: bezier([0.54, 0.05, 0.6, 0.98]),
5353
dimension: '4px',
5454
string: { value: 'something', optional: true, order: -2 },

packages/leva/src/components/Vector/vector-plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export function normalizeVector<Value extends VectorType, K extends string>(
145145
) {
146146
const { lock = false, ..._settings } = settings
147147
const format: Format = Array.isArray(value) ? 'array' : 'object'
148+
// FIXME: This is crashing: value is undefined
148149
const keys = format === 'object' ? Object.keys(value) : defaultKeys
149150
const _value = convert(value, 'object', keys)
150151

+12-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import { Joystick3d } from './UI/Joystick3d'
2-
// import type { Vector3jProps } from './vector3j-types'
2+
import type { Vector3jProps, Vector3dProps } from './vector3j-types'
33

44
// export function Vector3j() {
55
// const { label, displayValue, onUpdate, settings } = useInputContext<Vector3jProps>()
@@ -14,54 +14,26 @@
1414
// )
1515
// }
1616

17-
import React, { forwardRef } from 'react'
17+
import React from 'react'
1818
import { Components, useInputContext } from 'leva/plugin'
19-
import DatePicker, { CalendarContainer } from 'react-datepicker'
20-
import 'react-datepicker/dist/react-datepicker.css'
21-
import { DateCalendarContainerProps, DateInputProps, DateProps } from './vector3j-types'
22-
import { InputContainer, StyledInput, StyledWrapper } from './StyledVector3j'
19+
import { InputContainer } from './StyledVector3j'
2320

2421
const { Label, Row, Vector } = Components
2522

26-
const DateCalendarContainer = ({ children }: DateCalendarContainerProps) => {
27-
return (
28-
<CalendarContainer>
29-
<StyledWrapper>{children}</StyledWrapper>
30-
</CalendarContainer>
31-
)
32-
}
33-
34-
const DateInput = forwardRef<HTMLInputElement, Partial<DateInputProps>>(({ value, onClick, onChange }, ref) => {
35-
return <StyledInput ref={ref} value={value} onClick={onClick} onChange={onChange} />
36-
})
37-
3823
export function Vector3j() {
39-
const { label, value, onUpdate, settings } = useInputContext<DateProps>()
24+
const { label, displayValue, onUpdate, settings } = useInputContext<Vector3dProps>()
25+
26+
console.log('Vector3j', displayValue, settings)
4027

28+
/* FIXME: replace true with !!settings.joystick */
29+
/* FIXME: replace true with settings.joystick */
4130
return (
4231
<Row input>
4332
<Label>{label}</Label>
44-
<InputContainer>
45-
<DatePicker
46-
selected={value.date}
47-
onChange={onUpdate}
48-
dateFormat={settings.inputFormat}
49-
calendarContainer={DateCalendarContainer}
50-
customInput={<DateInput />}
51-
/>
52-
</InputContainer>
33+
{/* <InputContainer withJoystick={true}> */}
34+
{/* {true && <Joystick3d value={displayValue} settings={settings} onUpdate={onUpdate} />} */}
35+
<Vector value={displayValue} settings={settings} onUpdate={onUpdate} />
36+
{/* </InputContainer> */}
5337
</Row>
5438
)
5539
}
56-
57-
/* FIXME: replace true with !!settings.joystick */
58-
/* FIXME: replace true with settings.joystick */
59-
/*
60-
<Row input>
61-
<Label>{label}</Label>
62-
<InputContainer withJoystick={true}>
63-
{true && <Joystick3d value={displayValue} settings={settings} onUpdate={onUpdate} />}
64-
<Vector value={displayValue} settings={settings} onUpdate={onUpdate} />
65-
</InputContainer>
66-
</Row>
67-
*/

packages/plugin-vector3j/src/index.ts

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,54 @@
11
import { createPlugin } from 'leva/plugin'
22
// import { Vector3dSettings } from 'leva/plugin'
33
// import { getVectorPlugin } from 'leva/plugin'
4+
import { getVectorSchema, normalizeVector, sanitizeVector, formatVector } from 'leva/plugin'
5+
46
import { Vector3j } from './Vector3j'
57
import { sanitize, normalize, format } from './vector3j-plugin'
68

9+
import type { InputWithSettings } from 'leva/src/types'
10+
import type {
11+
VectorType,
12+
Format,
13+
InternalVectorSettings,
14+
VectorSettings,
15+
VectorTypeFromValueFormatAndKeys,
16+
} from 'leva/src/components/Vector/vector-types'
17+
718
// ???
819
// export * from './Vector3joy'
920

21+
// export const vector3j = createPlugin({
22+
// sanitize,
23+
// format,
24+
// normalize,
25+
// component: Vector3j,
26+
// // ...getVectorPlugin(['x', 'y', 'z']),
27+
// })
28+
29+
export function getVectorPlugin<K extends string>(defaultKeys: K[]) {
30+
return {
31+
schema: getVectorSchema(defaultKeys.length),
32+
normalize: <Value extends VectorType>({
33+
value,
34+
...settings
35+
}: InputWithSettings<Value, VectorSettings<Value, K>>) => {
36+
// FIXME: value is undefined???
37+
console.log('normalize:', value, settings)
38+
return normalizeVector(value, settings, defaultKeys)
39+
},
40+
format: (value: any, settings: InternalVectorSettings) => {
41+
console.log('format:', value, settings)
42+
return formatVector(value, settings)
43+
},
44+
sanitize: (value: any, settings: InternalVectorSettings, prevValue: any) => {
45+
console.log('sanitize', value, settings)
46+
return sanitizeVector(value, settings, prevValue)
47+
},
48+
}
49+
}
50+
1051
export const vector3j = createPlugin({
11-
sanitize,
12-
format,
13-
normalize,
1452
component: Vector3j,
15-
// ...getVectorPlugin(['x', 'y', 'z']),
53+
...getVectorPlugin(['x', 'y', 'z']),
1654
})

packages/plugin-vector3j/src/vector3j-types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ export type InternalVector3dSettings = InternalVectorSettings<string, [string, s
2626
joystick: boolean | 'invertY'
2727
}
2828
export type Vector3jProps = LevaInputProps<Vector3d, InternalVector3dSettings, VectorObj>
29+
30+
export type Vector3dProps = LevaInputProps<Vector3d, InternalVector3dSettings, VectorObj>

0 commit comments

Comments
 (0)