11import { colord } from "colord" ;
22import { useEffect , useMemo , useRef , useState , type ReactNode } from "react" ;
3+ import { useStore } from "@nanostores/react" ;
34import { computed } from "nanostores" ;
45import { matchSorter } from "match-sorter" ;
56import { isFeatureEnabled } from "@webstudio-is/feature-flags" ;
@@ -20,7 +21,7 @@ import {
2021 properties as propertiesData ,
2122 propertyDescriptions ,
2223} from "@webstudio-is/css-data" ;
23- import { useStore } from "@nanostores/react " ;
24+ import { ROOT_INSTANCE_ID } from "@webstudio-is/sdk " ;
2425import {
2526 hyphenateProperty ,
2627 toValue ,
@@ -35,13 +36,20 @@ import { styleConfigByName } from "../../shared/configs";
3536import { deleteProperty , setProperty } from "../../shared/use-style-data" ;
3637import {
3738 $definedStyles ,
39+ $matchingBreakpoints ,
40+ getDefinedStyles ,
3841 useComputedStyleDecl ,
3942 useComputedStyles ,
4043} from "../../shared/model" ;
4144import { getDots } from "../../shared/style-section" ;
4245import { PropertyInfo } from "../../property-label" ;
4346import { sections } from "../sections" ;
4447import { ColorPopover } from "../../shared/color-picker" ;
48+ import {
49+ $selectedInstanceSelector ,
50+ $styles ,
51+ $styleSourceSelections ,
52+ } from "~/shared/nano-states" ;
4553
4654// Only here to keep the same section module interface
4755export const properties = [ ] ;
@@ -206,7 +214,7 @@ const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
206214 ) ;
207215} ;
208216
209- const $customProperties = computed ( $definedStyles , ( definedStyles ) => {
217+ const $availableCustomProperties = computed ( $definedStyles , ( definedStyles ) => {
210218 const customProperties = new Set < StyleProperty > ( ) ;
211219 for ( const { property } of definedStyles ) {
212220 if ( property . startsWith ( "--" ) ) {
@@ -224,7 +232,7 @@ const AdvancedPropertyValue = ({
224232 property : StyleProperty ;
225233} ) => {
226234 const styleDecl = useComputedStyleDecl ( property ) ;
227- const customProperties = useStore ( $customProperties ) ;
235+ const availableCustomProperties = useStore ( $availableCustomProperties ) ;
228236 const { items } = styleConfigByName ( property ) ;
229237 const inputRef = useRef < HTMLInputElement > ( null ) ;
230238 useEffect ( ( ) => {
@@ -267,7 +275,7 @@ const AdvancedPropertyValue = ({
267275 value : item . name ,
268276 } ) ) ,
269277 // very basic custom properties autocomplete
270- ...Array . from ( customProperties ) . map ( ( name ) => ( {
278+ ...Array . from ( availableCustomProperties ) . map ( ( name ) => ( {
271279 type : "keyword" as const ,
272280 value : name ,
273281 } ) ) ,
@@ -299,23 +307,46 @@ const initialProperties = new Set<StyleProperty>([
299307 "opacity" ,
300308] ) ;
301309
302- const $advancedProperties = computed ( $definedStyles , ( definedStyles ) => {
303- // All properties used by the panels except the advanced panel
304- const baseProperties = new Set < StyleProperty > ( [ ] ) ;
305- for ( const { properties } of sections . values ( ) ) {
306- for ( const property of properties ) {
307- baseProperties . add ( property ) ;
310+ const $advancedProperties = computed (
311+ [
312+ $selectedInstanceSelector ,
313+ $styleSourceSelections ,
314+ $matchingBreakpoints ,
315+ $styles ,
316+ ] ,
317+ ( instanceSelector , styleSourceSelections , matchingBreakpoints , styles ) => {
318+ if ( instanceSelector === undefined ) {
319+ return [ ] ;
308320 }
309- }
310- const advancedProperties = new Set < StyleProperty > ( initialProperties ) ;
311- for ( const { property, listed } of definedStyles ) {
312- // exclude properties from style panel UI unless edited in advanced section
313- if ( baseProperties . has ( property ) === false || listed ) {
314- advancedProperties . add ( property ) ;
321+ const instanceAndRootSelector =
322+ instanceSelector [ 0 ] === ROOT_INSTANCE_ID
323+ ? instanceSelector
324+ : // prevent showing properties inherited from root
325+ // to not bloat advanced panel
326+ instanceSelector ;
327+ const definedStyles = getDefinedStyles ( {
328+ instanceSelector : instanceAndRootSelector ,
329+ matchingBreakpoints,
330+ styleSourceSelections,
331+ styles,
332+ } ) ;
333+ // All properties used by the panels except the advanced panel
334+ const baseProperties = new Set < StyleProperty > ( [ ] ) ;
335+ for ( const { properties } of sections . values ( ) ) {
336+ for ( const property of properties ) {
337+ baseProperties . add ( property ) ;
338+ }
315339 }
340+ const advancedProperties = new Set < StyleProperty > ( initialProperties ) ;
341+ for ( const { property, listed } of definedStyles ) {
342+ // exclude properties from style panel UI unless edited in advanced section
343+ if ( baseProperties . has ( property ) === false || listed ) {
344+ advancedProperties . add ( property ) ;
345+ }
346+ }
347+ return Array . from ( advancedProperties ) . reverse ( ) ;
316348 }
317- return Array . from ( advancedProperties ) . reverse ( ) ;
318- } ) ;
349+ ) ;
319350
320351export const Section = ( ) => {
321352 const [ isAdding , setIsAdding ] = useState ( false ) ;
0 commit comments