diff --git a/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/border.tsx b/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/border.tsx index f6a3736a7..e64635b4b 100644 --- a/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/border.tsx +++ b/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/border.tsx @@ -20,7 +20,7 @@ export const Border = () => { const { boxState, handleBoxChange, handleUnitChange, handleIndividualChange } = useBoxControl('border'); const editorEngine = useEditorEngine(); - const [borderColor, setBorderColor] = useState(Color.from(editorEngine.style.getValue('borderColor') ?? '#080808').toHex()); + const [borderColor, setBorderColor] = useState(Color.from(editorEngine.style.selectedStyle?.styles.borderColor ?? '#080808').toHex()); useEffect(() => { setBorderColor(Color.from(editorEngine.style.getValue('borderColor') ?? '#080808').toHex()); @@ -32,7 +32,7 @@ export const Border = () => { }; const borderStyle = { - borderWidth: boxState.border.num ? `1px`: '0px', + borderWidth: boxState.border.num ? `1px` : '0px', borderStyle: 'solid', }; @@ -46,10 +46,10 @@ export const Border = () => { {boxState.border.value} -
+
diff --git a/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/margin.tsx b/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/margin.tsx index 0f843e76a..6c08645e4 100644 --- a/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/margin.tsx +++ b/apps/web/client/src/app/project/[id]/_components/editor-bar/dropdowns/margin.tsx @@ -2,77 +2,77 @@ import { Button } from "@onlook/ui/button"; import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuTrigger, + DropdownMenu, + DropdownMenuContent, + DropdownMenuTrigger, } from "@onlook/ui/dropdown-menu"; import { Icons } from "@onlook/ui/icons"; import { useState } from "react"; +import { useBoxControl } from "../hooks/use-box-control"; import { InputRange } from "../inputs/input-range"; import { SpacingInputs } from "../inputs/spacing-inputs"; -import { useBoxControl } from "../hooks/use-box-control"; export const Margin = () => { - const [activeTab, setActiveTab] = useState("individual"); - const { boxState, handleBoxChange, handleUnitChange, handleIndividualChange } = useBoxControl('margin'); + const [activeTab, setActiveTab] = useState("individual"); + const { boxState, handleBoxChange, handleUnitChange, handleIndividualChange, setIsUpdating } = useBoxControl('margin'); - return ( - - - - - -
- - -
- {activeTab === "all" ? ( - handleBoxChange('margin', value.toString())} - unit={boxState.margin.unit} - onUnitChange={(unit) => handleUnitChange('margin', unit)} - /> - ) : ( - - )} -
-
- ); + return ( + + + + + +
+ + +
+ {activeTab === "all" ? ( + handleBoxChange('margin', value.toString())} + unit={boxState.margin.unit} + onUnitChange={(unit) => handleUnitChange('margin', unit)} + onUnitChangeStart={() => setIsUpdating(true)} + onUnitChangeEnd={() => setIsUpdating(false)} + /> + ) : ( + + )} +
+
+ ); }; diff --git a/apps/web/client/src/app/project/[id]/_components/editor-bar/hooks/use-box-control.ts b/apps/web/client/src/app/project/[id]/_components/editor-bar/hooks/use-box-control.ts index 411e7f8ff..68a7b3261 100644 --- a/apps/web/client/src/app/project/[id]/_components/editor-bar/hooks/use-box-control.ts +++ b/apps/web/client/src/app/project/[id]/_components/editor-bar/hooks/use-box-control.ts @@ -51,6 +51,7 @@ const createDefaultState = (type: BoxType): BoxStateMap => { export const useBoxControl = (type: BoxType) => { const editorEngine = useEditorEngine(); + const [isUpdating, setIsUpdating] = useState(false); const getInitialState = (): BoxStateMap => { const defaultState = createDefaultState(type); @@ -92,6 +93,8 @@ export const useBoxControl = (type: BoxType) => { const [boxState, setBoxState] = useState(getInitialState()); useEffect(() => { + console.log('isUpdating', isUpdating); + if (isUpdating) return; setBoxState(getInitialState()); }, [editorEngine.style.selectedStyle]); @@ -154,6 +157,8 @@ export const useBoxControl = (type: BoxType) => { boxState, handleBoxChange, handleUnitChange, - handleIndividualChange + handleIndividualChange, + isUpdating, + setIsUpdating }; }; \ No newline at end of file diff --git a/apps/web/client/src/app/project/[id]/_components/editor-bar/inputs/input-range.tsx b/apps/web/client/src/app/project/[id]/_components/editor-bar/inputs/input-range.tsx index ed87ac136..3a0eb0a96 100644 --- a/apps/web/client/src/app/project/[id]/_components/editor-bar/inputs/input-range.tsx +++ b/apps/web/client/src/app/project/[id]/_components/editor-bar/inputs/input-range.tsx @@ -10,9 +10,11 @@ interface InputRangeProps { unit?: string; onChange?: (value: number) => void; onUnitChange?: (unit: string) => void; + onUnitChangeStart?: () => void; + onUnitChangeEnd?: () => void; } -export const InputRange = ({ value, icon, unit = "px", onChange, onUnitChange }: InputRangeProps) => { +export const InputRange = ({ value, icon, unit = "px", onChange, onUnitChange, onUnitChangeStart, onUnitChangeEnd }: InputRangeProps) => { const Icon = icon ? Icons[icon] : Icons.Padding; const [inputValue, setInputValue] = useState(String(value)); const rangeRef = useRef(null); @@ -41,6 +43,7 @@ export const InputRange = ({ value, icon, unit = "px", onChange, onUnitChange }: const handleMouseDown = (e: React.MouseEvent) => { if (rangeRef.current) { + onUnitChangeStart?.(); setIsDragging(true); document.addEventListener('mousemove', handleMouseMove); document.addEventListener('mouseup', handleMouseUp); @@ -57,6 +60,7 @@ export const InputRange = ({ value, icon, unit = "px", onChange, onUnitChange }: }; const handleMouseUp = () => { + onUnitChangeEnd?.(); setIsDragging(false); document.removeEventListener('mousemove', handleMouseMove); document.removeEventListener('mouseup', handleMouseUp); diff --git a/apps/web/client/src/components/store/editor/engine/style/index.ts b/apps/web/client/src/components/store/editor/engine/style/index.ts index d29ca898f..8c5c8b097 100644 --- a/apps/web/client/src/components/store/editor/engine/style/index.ts +++ b/apps/web/client/src/components/store/editor/engine/style/index.ts @@ -9,7 +9,9 @@ import { makeAutoObservable, reaction } from 'mobx'; import type { EditorEngine } from '..'; export interface SelectedStyle { - styles: Record; + styles: { + margin: string; + } parentRect: DOMRect; rect: DOMRect; } diff --git a/apps/web/preload/script/api/elements/style.ts b/apps/web/preload/script/api/elements/style.ts index 71415d273..fbeb22b8c 100644 --- a/apps/web/preload/script/api/elements/style.ts +++ b/apps/web/preload/script/api/elements/style.ts @@ -1,10 +1,8 @@ +import type { DomElementStyles } from '@onlook/models'; import { jsonClone } from '@onlook/utility'; import { getHtmlElement } from '../../helpers'; -export function getStyles(element: HTMLElement): { - defined: Record; - computed: Record; -} { +export function getStyles(element: HTMLElement): DomElementStyles { const computed = getElComputedStyle(element); const inline = getInlineStyles(element); const stylesheet = getStylesheetStyles(element);