-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathObjectVisualElement.ts
More file actions
69 lines (57 loc) · 1.75 KB
/
ObjectVisualElement.ts
File metadata and controls
69 lines (57 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { MotionValueState } from "motion-dom"
import { createBox } from "../../projection/geometry/models"
import { ResolvedValues } from "../types"
import { VisualElement } from "../VisualElement"
interface ObjectRenderState {
output: ResolvedValues
}
function isObjectKey(key: string, object: Object): key is keyof Object {
return key in object
}
export class ObjectVisualElement extends VisualElement<
Object,
ObjectRenderState
> {
type = "object"
createMotionValueState(): MotionValueState {
return new MotionValueState({
// Don't apply value types (e.g., "px") to plain objects
useDefaultValueType: false,
onValueChange: (key, value) => {
// Sync to latestValues and schedule render
this.latestValues[key] = value
this.scheduleRender()
},
})
}
readValueFromInstance(instance: Object, key: string) {
if (isObjectKey(key, instance)) {
const value = instance[key]
if (typeof value === "string" || typeof value === "number") {
return value
}
}
return undefined
}
getBaseTargetFromProps() {
return undefined
}
removeValueFromRenderState(
key: string,
renderState: ObjectRenderState
): void {
delete renderState.output[key]
}
measureInstanceViewportBox() {
return createBox()
}
build(renderState: ObjectRenderState, latestValues: ResolvedValues) {
Object.assign(renderState.output, latestValues)
}
renderInstance(instance: Object, { output }: ObjectRenderState) {
Object.assign(instance, output)
}
sortInstanceNodePosition() {
return 0
}
}