@@ -11,15 +11,13 @@ import { BlockStack, InlineStack } from "@/components/ui/layout";
1111import { Textarea } from "@/components/ui/textarea" ;
1212import { Paragraph , Text } from "@/components/ui/typography" ;
1313import { cn } from "@/lib/utils" ;
14- import { useComponentSpec } from "@/providers/ComponentSpecProvider" ;
1514import { FONT_SIZE_MD , FONT_SIZE_SM } from "@/utils/constants" ;
16- import { updateSubgraphSpec } from "@/utils/subgraphUtils" ;
1715
1816import { StackingControls } from "../../FlowControls/StackingControls" ;
19- import { updateFlexNodeInComponentSpec } from "./interface" ;
2017import LockToggle from "./LockToggle" ;
2118import { TextSizeSelector } from "./TextSizeSelector" ;
2219import type { FlexNodeData } from "./types" ;
20+ import { useFlexNodeUpdate } from "./useFlexNodeUpdate" ;
2321import { DEFAULT_BORDER_COLOR } from "./utils" ;
2422
2523interface FlexNodeEditorProps {
@@ -108,12 +106,7 @@ const ContentEditor = ({
108106 flexNode : FlexNodeData ;
109107 readOnly : boolean ;
110108} ) => {
111- const {
112- componentSpec,
113- currentSubgraphSpec,
114- currentSubgraphPath,
115- setComponentSpec,
116- } = useComponentSpec ( ) ;
109+ const { updateProperties } = useFlexNodeUpdate ( flexNode ) ;
117110
118111 const { properties } = flexNode ;
119112
@@ -129,67 +122,15 @@ const ContentEditor = ({
129122 } ;
130123
131124 const handleTitleFontSizeChange = ( newSize : number ) => {
132- const updatedSubgraphSpec = updateFlexNodeInComponentSpec (
133- currentSubgraphSpec ,
134- {
135- ...flexNode ,
136- properties : {
137- ...properties ,
138- titleFontSize : newSize ,
139- } ,
140- } ,
141- ) ;
142-
143- const newRootSpec = updateSubgraphSpec (
144- componentSpec ,
145- currentSubgraphPath ,
146- updatedSubgraphSpec ,
147- ) ;
148-
149- setComponentSpec ( newRootSpec ) ;
125+ updateProperties ( { titleFontSize : newSize } ) ;
150126 } ;
151127
152128 const handleContentFontSizeChange = ( newSize : number ) => {
153- const updatedSubgraphSpec = updateFlexNodeInComponentSpec (
154- currentSubgraphSpec ,
155- {
156- ...flexNode ,
157- properties : {
158- ...properties ,
159- contentFontSize : newSize ,
160- } ,
161- } ,
162- ) ;
163-
164- const newRootSpec = updateSubgraphSpec (
165- componentSpec ,
166- currentSubgraphPath ,
167- updatedSubgraphSpec ,
168- ) ;
169-
170- setComponentSpec ( newRootSpec ) ;
129+ updateProperties ( { contentFontSize : newSize } ) ;
171130 } ;
172131
173132 const saveChanges = ( ) => {
174- const updatedSubgraphSpec = updateFlexNodeInComponentSpec (
175- currentSubgraphSpec ,
176- {
177- ...flexNode ,
178- properties : {
179- ...properties ,
180- title,
181- content,
182- } ,
183- } ,
184- ) ;
185-
186- const newRootSpec = updateSubgraphSpec (
187- componentSpec ,
188- currentSubgraphPath ,
189- updatedSubgraphSpec ,
190- ) ;
191-
192- setComponentSpec ( newRootSpec ) ;
133+ updateProperties ( { title, content } ) ;
193134 } ;
194135
195136 useEffect ( ( ) => {
@@ -288,12 +229,7 @@ const ColorEditor = ({
288229 flexNode : FlexNodeData ;
289230 readOnly : boolean ;
290231} ) => {
291- const {
292- componentSpec,
293- currentSubgraphSpec,
294- currentSubgraphPath,
295- setComponentSpec,
296- } = useComponentSpec ( ) ;
232+ const { updateProperties } = useFlexNodeUpdate ( flexNode ) ;
297233
298234 const { properties } = flexNode ;
299235
@@ -320,25 +256,10 @@ const ColorEditor = ({
320256 newBackgroundColor : string ,
321257 newBorderColor : string | undefined ,
322258 ) => {
323- const updatedSubgraphSpec = updateFlexNodeInComponentSpec (
324- currentSubgraphSpec ,
325- {
326- ...flexNode ,
327- properties : {
328- ...properties ,
329- color : newBackgroundColor ,
330- borderColor : newBorderColor ,
331- } ,
332- } ,
333- ) ;
334-
335- const newRootSpec = updateSubgraphSpec (
336- componentSpec ,
337- currentSubgraphPath ,
338- updatedSubgraphSpec ,
339- ) ;
340-
341- setComponentSpec ( newRootSpec ) ;
259+ updateProperties ( {
260+ color : newBackgroundColor ,
261+ borderColor : newBorderColor ,
262+ } ) ;
342263 } ;
343264
344265 useEffect ( ( ) => {
@@ -409,29 +330,10 @@ const ColorEditor = ({
409330} ;
410331
411332const ZIndexEditor = ( { flexNode } : { flexNode : FlexNodeData } ) => {
412- const {
413- componentSpec,
414- currentSubgraphSpec,
415- currentSubgraphPath,
416- setComponentSpec,
417- } = useComponentSpec ( ) ;
333+ const { updateFlexNode } = useFlexNodeUpdate ( flexNode ) ;
418334
419335 const handleStackingControlChange = ( newZIndex : number ) => {
420- const updatedSubgraphSpec = updateFlexNodeInComponentSpec (
421- currentSubgraphSpec ,
422- {
423- ...flexNode ,
424- zIndex : newZIndex ,
425- } ,
426- ) ;
427-
428- const newRootSpec = updateSubgraphSpec (
429- componentSpec ,
430- currentSubgraphPath ,
431- updatedSubgraphSpec ,
432- ) ;
433-
434- setComponentSpec ( newRootSpec ) ;
336+ updateFlexNode ( { zIndex : newZIndex } ) ;
435337 } ;
436338
437339 return (
0 commit comments