@@ -2,6 +2,7 @@ import { useState } from "react";
2
2
import { useStore } from "@nanostores/react" ;
3
3
import { nanoid } from "nanoid" ;
4
4
import { computed , type WritableAtom } from "nanostores" ;
5
+ import { pseudoClassesByTag } from "@webstudio-is/html-data" ;
5
6
import {
6
7
type Instance ,
7
8
type StyleSource ,
@@ -41,6 +42,8 @@ import { removeByMutable } from "~/shared/array-utils";
41
42
import { cloneStyles } from "~/shared/tree-utils" ;
42
43
import { serverSyncStore } from "~/shared/sync" ;
43
44
import { $selectedInstance } from "~/shared/awareness" ;
45
+ import { $instanceTags } from "./shared/model" ;
46
+ import { humanizeString } from "~/shared/string-utils" ;
44
47
45
48
const selectStyleSource = (
46
49
styleSourceId : StyleSource [ "id" ] ,
@@ -325,12 +328,26 @@ const clearStyles = (styleSourceId: StyleSource["id"]) => {
325
328
} ;
326
329
327
330
const $componentStates = computed (
328
- [ $selectedInstance , $registeredComponentMetas ] ,
329
- ( selectedInstance , registeredComponentMetas ) => {
331
+ [ $selectedInstance , $registeredComponentMetas , $instanceTags ] ,
332
+ ( selectedInstance , registeredComponentMetas , instanceTags ) => {
330
333
if ( selectedInstance === undefined ) {
331
334
return ;
332
335
}
333
- return registeredComponentMetas . get ( selectedInstance . component ) ?. states ;
336
+ const tag = instanceTags . get ( selectedInstance . id ) ;
337
+ const tagStates = [
338
+ ...pseudoClassesByTag [ "*" ] ,
339
+ ...( pseudoClassesByTag [ tag ?? "" ] ?? [ ] ) ,
340
+ ] . map ( ( state ) => ( {
341
+ category : "states" as const ,
342
+ label : humanizeString ( state ) ,
343
+ selector : state ,
344
+ } ) ) ;
345
+ const meta = registeredComponentMetas . get ( selectedInstance . component ) ;
346
+ const componentStates = ( meta ?. states ?? [ ] ) . map ( ( item ) => ( {
347
+ category : "component-states" as const ,
348
+ ...item ,
349
+ } ) ) ;
350
+ return [ ...tagStates , ...componentStates ] ;
334
351
}
335
352
) ;
336
353
0 commit comments