1
1
import { Flex , Grid } from "@webstudio-is/design-system" ;
2
- import {
3
- updateRotateOrSkewPropertyValue ,
4
- type TransformPanelProps ,
5
- } from "./transform-utils" ;
6
2
import {
7
3
XAxisRotateIcon ,
8
4
YAxisRotateIcon ,
9
5
ZAxisRotateIcon ,
10
6
} from "@webstudio-is/icons" ;
7
+ import type { StyleValue } from "@webstudio-is/css-engine" ;
8
+ import { propertySyntaxes } from "@webstudio-is/css-data" ;
11
9
import { CssValueInputContainer } from "../../shared/css-value-input" ;
12
- import {
13
- toValue ,
14
- UnitValue ,
15
- type FunctionValue ,
16
- type StyleValue ,
17
- } from "@webstudio-is/css-engine" ;
18
- import type { StyleUpdateOptions } from "../../shared/use-style-data" ;
19
- import { parseCssValue , propertySyntaxes } from "@webstudio-is/css-data" ;
20
- import { extractRotatePropertiesFromTransform } from "./transform-extractors" ;
21
10
import { PropertyInlineLabel } from "../../property-label" ;
11
+ import { useComputedStyleDecl } from "../../shared/model" ;
12
+ import { updateTransformFunction } from "./transform-utils" ;
22
13
23
- export const RotatePanelContent = ( props : TransformPanelProps ) => {
24
- const { propertyValue, setProperty, currentStyle } = props ;
25
- const { rotateX, rotateY, rotateZ } =
26
- extractRotatePropertiesFromTransform ( propertyValue ) ;
27
-
28
- const handlePropertyUpdate = (
29
- index : number ,
30
- prop : string ,
31
- value : StyleValue ,
32
- options ?: StyleUpdateOptions
33
- ) => {
34
- let newValue : UnitValue = { type : "unit" , value : 0 , unit : "deg" } ;
35
-
36
- if ( value . type === "unit" ) {
37
- newValue = value ;
14
+ export const RotatePanelContent = ( ) => {
15
+ const styleDecl = useComputedStyleDecl ( "transform" ) ;
16
+ const tuple =
17
+ styleDecl . cascadedValue . type === "tuple"
18
+ ? styleDecl . cascadedValue
19
+ : undefined ;
20
+ let rotateX : StyleValue = { type : "unit" , value : 0 , unit : "deg" } ;
21
+ let rotateY : StyleValue = { type : "unit" , value : 0 , unit : "deg" } ;
22
+ let rotateZ : StyleValue = { type : "unit" , value : 0 , unit : "deg" } ;
23
+ for ( const item of tuple ?. value ?? [ ] ) {
24
+ if (
25
+ item . type === "function" &&
26
+ item . args . type === "layers" &&
27
+ item . args . value [ 0 ] . type === "unit"
28
+ ) {
29
+ if ( item . name === "rotateX" ) {
30
+ rotateX = item . args . value [ 0 ] ;
31
+ }
32
+ if ( item . name === "rotateY" ) {
33
+ rotateY = item . args . value [ 0 ] ;
34
+ }
35
+ if ( item . name === "rotateZ" ) {
36
+ rotateZ = item . args . value [ 0 ] ;
37
+ }
38
38
}
39
-
40
- if ( value . type === "tuple" && value . value [ 0 ] . type === "unit" ) {
41
- newValue = value . value [ 0 ] ;
42
- }
43
-
44
- const newFunctionValue : FunctionValue = {
45
- type : "function" ,
46
- name : prop ,
47
- args : { type : "layers" , value : [ newValue ] } ,
48
- } ;
49
-
50
- const newPropertyValue = updateRotateOrSkewPropertyValue ( {
51
- panel : "rotate" ,
52
- index,
53
- currentStyle,
54
- value : newFunctionValue ,
55
- propertyValue,
56
- } ) ;
57
-
58
- const rotate = parseCssValue ( "transform" , toValue ( newPropertyValue ) ) ;
59
- if ( rotate . type === "invalid" ) {
60
- return ;
61
- }
62
-
63
- setProperty ( "transform" ) ( rotate , options ) ;
64
- } ;
39
+ }
65
40
66
41
return (
67
42
< Flex direction = "column" gap = { 2 } >
@@ -75,18 +50,13 @@ export const RotatePanelContent = (props: TransformPanelProps) => {
75
50
description = { propertySyntaxes . rotateX }
76
51
/>
77
52
< CssValueInputContainer
78
- key = "rotateX"
79
53
styleSource = "local"
80
54
property = "rotate"
81
- value = {
82
- rotateX ?. type === "function" && rotateX . args . type === "layers"
83
- ? rotateX . args . value [ 0 ]
84
- : { type : "unit" , value : 0 , unit : "deg" }
85
- }
55
+ value = { rotateX }
86
56
keywords = { [ ] }
87
- setValue = { ( value , options ) => {
88
- handlePropertyUpdate ( 0 , "rotateX" , value , options ) ;
89
- } }
57
+ setValue = { ( value , options ) =>
58
+ updateTransformFunction ( styleDecl , "rotateX" , value , options )
59
+ }
90
60
deleteProperty = { ( ) => { } }
91
61
/>
92
62
</ Grid >
@@ -100,18 +70,13 @@ export const RotatePanelContent = (props: TransformPanelProps) => {
100
70
description = { propertySyntaxes . rotateY }
101
71
/>
102
72
< CssValueInputContainer
103
- key = "rotateY"
104
73
styleSource = "local"
105
74
property = "rotate"
106
- value = {
107
- rotateY ?. type === "function" && rotateY . args . type === "layers"
108
- ? rotateY . args . value [ 0 ]
109
- : { type : "unit" , value : 0 , unit : "deg" }
110
- }
75
+ value = { rotateY }
111
76
keywords = { [ ] }
112
- setValue = { ( value , options ) => {
113
- handlePropertyUpdate ( 1 , "rotateY" , value , options ) ;
114
- } }
77
+ setValue = { ( value , options ) =>
78
+ updateTransformFunction ( styleDecl , "rotateY" , value , options )
79
+ }
115
80
deleteProperty = { ( ) => { } }
116
81
/>
117
82
</ Grid >
@@ -125,18 +90,13 @@ export const RotatePanelContent = (props: TransformPanelProps) => {
125
90
description = { propertySyntaxes . rotateZ }
126
91
/>
127
92
< CssValueInputContainer
128
- key = "rotateZ"
129
93
styleSource = "local"
130
94
property = "rotate"
131
- value = {
132
- rotateZ ?. type === "function" && rotateZ . args . type === "layers"
133
- ? rotateZ . args . value [ 0 ]
134
- : { type : "unit" , value : 0 , unit : "deg" }
135
- }
95
+ value = { rotateZ }
136
96
keywords = { [ ] }
137
- setValue = { ( value , options ) => {
138
- handlePropertyUpdate ( 2 , "rotateZ" , value , options ) ;
139
- } }
97
+ setValue = { ( value , options ) =>
98
+ updateTransformFunction ( styleDecl , "rotateZ" , value , options )
99
+ }
140
100
deleteProperty = { ( ) => { } }
141
101
/>
142
102
</ Grid >
0 commit comments