From 3173aeed646a752a055df06b364e627e1878f091 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sat, 8 Feb 2025 11:30:44 +0000 Subject: [PATCH 01/18] recent section --- .../sections/advanced/advanced.tsx | 67 +++++++++++++------ 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx index 14b67fe0e876..64eff72143d1 100644 --- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx @@ -28,6 +28,7 @@ import { SectionTitle, SectionTitleButton, SectionTitleLabel, + Separator, Text, theme, Tooltip, @@ -91,6 +92,7 @@ const AdvancedStyleSection = (props: { label={label} isOpen={isOpen} onOpenChange={setIsOpen} + fullWidth trigger={ { const visibilityChangeEventSupported = useClientSupports( () => "oncontentvisibilityautostatechange" in document.body @@ -514,8 +516,13 @@ const AdvancedProperty = memo( export const Section = () => { const [isAdding, setIsAdding] = useState(false); const advancedProperties = useStore($advancedProperties); - const newlyAddedProperty = useRef(undefined); + const recentProperties = useRef([]); + // In case the property was deleted, it will be removed from advanced, so we need to remove it from recent too. + recentProperties.current = recentProperties.current.filter((property) => + advancedProperties.includes(property) + ); + console.log(recentProperties); return ( { onAdd={() => setIsAdding(true)} > {isAdding && ( - { - newlyAddedProperty.current = property; - setIsAdding(false); - setProperty(property)( - { type: "guaranteedInvalid" }, - { listed: true } - ); - }} - onClose={() => setIsAdding(false)} - /> - )} - - {advancedProperties.map((property) => ( - + { + recentProperties.current.push(property); + setIsAdding(false); + setProperty(property)( + { type: "guaranteedInvalid" }, + { listed: true } + ); + }} + onClose={() => setIsAdding(false)} /> - ))} + + )} + {recentProperties.current.length > 0 && ( + <> + + {recentProperties.current.map((property, index, properties) => ( + + ))} + + + + )} + + {advancedProperties + .filter( + (property) => recentProperties.current.includes(property) === false + ) + .map((property) => ( + + ))} ); From 3c7147394a465e645c9716f3e2960fbb09db1dfb Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sat, 8 Feb 2025 11:36:59 +0000 Subject: [PATCH 02/18] show add property input after recent properties --- .../sections/advanced/advanced.tsx | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx index 64eff72143d1..5140307923c8 100644 --- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx @@ -522,15 +522,22 @@ export const Section = () => { recentProperties.current = recentProperties.current.filter((property) => advancedProperties.includes(property) ); - console.log(recentProperties); + return ( setIsAdding(true)} > - {isAdding && ( - + + {recentProperties.current.map((property, index, properties) => ( + + ))} + {isAdding && ( { @@ -543,22 +550,9 @@ export const Section = () => { }} onClose={() => setIsAdding(false)} /> - - )} - {recentProperties.current.length > 0 && ( - <> - - {recentProperties.current.map((property, index, properties) => ( - - ))} - - - - )} + )} + + {recentProperties.current.length > 0 && } {advancedProperties .filter( From d54f44b1d9d4483c6bd12dda4b121aa960860686 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sat, 8 Feb 2025 12:25:51 +0000 Subject: [PATCH 03/18] close input on esc, show it on enter --- .../sections/advanced/advanced.tsx | 42 ++++++++++++++++--- .../css-value-input-container.tsx | 12 ++++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx index 5140307923c8..3b68b7ad8f58 100644 --- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx @@ -6,6 +6,7 @@ import { useMemo, useRef, useState, + type ComponentProps, type ReactNode, } from "react"; import { useStore } from "@nanostores/react"; @@ -74,6 +75,7 @@ import { import { useClientSupports } from "~/shared/client-supports"; import { $selectedInstancePath } from "~/shared/awareness"; import { $settings } from "~/builder/shared/client-settings"; +import { composeEventHandlers } from "~/shared/event-utils"; // Only here to keep the same section module interface export const properties = []; @@ -169,7 +171,7 @@ const insertStyles = (text: string) => { * paste css declarations * */ -const AdvancedSearch = ({ +const AddProperty = ({ usedProperties, onSelect, onClose, @@ -212,7 +214,20 @@ const AdvancedSearch = ({ const descriptionItem = combobox.items[combobox.highlightedIndex]; const description = getNewPropertyDescription(descriptionItem); const descriptions = combobox.items.map(getNewPropertyDescription); - + const inputProps = combobox.getInputProps(); + const handleAbort = (event: KeyboardEvent) => { + if (event.key === "Escape") { + onClose(); + } + }; + const handleKeyDown = composeEventHandlers( + handleAbort, + inputProps.onKeyDown, + { + // Pass prevented events to the combobox (e.g., the Escape key doesn't work otherwise, as it's blocked by Radix) + checkForDefaultPrevented: false, + } + ); return (