@@ -5,10 +5,11 @@ import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
5
5
import type { WsComponentMeta } from "@webstudio-is/react-sdk" ;
6
6
import type { Matcher , WebstudioFragment } from "@webstudio-is/sdk" ;
7
7
import {
8
- findClosestContainer ,
8
+ findClosestNonTextualContainer ,
9
9
findClosestInstanceMatchingFragment ,
10
10
isInstanceMatching ,
11
11
isTreeMatching ,
12
+ findClosestContainer ,
12
13
} from "./matcher" ;
13
14
14
15
const metas = new Map ( Object . entries ( { ...coreMetas , ...baseMetas } ) ) ;
@@ -885,7 +886,7 @@ describe("find closest container", () => {
885
886
) . toEqual ( 1 ) ;
886
887
} ) ;
887
888
888
- test ( "skips containers with text" , ( ) => {
889
+ test ( "allow containers with text" , ( ) => {
889
890
expect (
890
891
findClosestContainer ( {
891
892
...renderJsx (
@@ -898,12 +899,74 @@ describe("find closest container", () => {
898
899
metas,
899
900
instanceSelector : [ "box-with-text" , "box" , "body" ] ,
900
901
} )
902
+ ) . toEqual ( 0 ) ;
903
+ } ) ;
904
+
905
+ test ( "allow containers with expression" , ( ) => {
906
+ expect (
907
+ findClosestContainer ( {
908
+ ...renderJsx (
909
+ < $ . Body ws :id = "body" >
910
+ < $ . Box ws :id = "box" >
911
+ < $ . Box ws :id = "box-with-expr" >
912
+ { new ExpressionValue ( "1 + 1" ) }
913
+ </ $ . Box >
914
+ </ $ . Box >
915
+ </ $ . Body >
916
+ ) ,
917
+ metas,
918
+ instanceSelector : [ "box-with-expr" , "box" , "body" ] ,
919
+ } )
920
+ ) . toEqual ( 0 ) ;
921
+ } ) ;
922
+
923
+ test ( "allow root with text" , ( ) => {
924
+ expect (
925
+ findClosestContainer ( {
926
+ ...renderJsx ( < $ . Body ws :id = "body" > text</ $ . Body > ) ,
927
+ metas,
928
+ instanceSelector : [ "body" ] ,
929
+ } )
930
+ ) . toEqual ( 0 ) ;
931
+ } ) ;
932
+ } ) ;
933
+
934
+ describe ( "find closest non textual container" , ( ) => {
935
+ test ( "skips non-container instances" , ( ) => {
936
+ expect (
937
+ findClosestNonTextualContainer ( {
938
+ ...renderJsx (
939
+ < $ . Body ws :id = "body" >
940
+ < $ . Box ws :id = "box" >
941
+ < $ . Image ws :id = "image" />
942
+ </ $ . Box >
943
+ </ $ . Body >
944
+ ) ,
945
+ metas,
946
+ instanceSelector : [ "image" , "box" , "body" ] ,
947
+ } )
948
+ ) . toEqual ( 1 ) ;
949
+ } ) ;
950
+
951
+ test ( "skips containers with text" , ( ) => {
952
+ expect (
953
+ findClosestNonTextualContainer ( {
954
+ ...renderJsx (
955
+ < $ . Body ws :id = "body" >
956
+ < $ . Box ws :id = "box" >
957
+ < $ . Box ws :id = "box-with-text" > text</ $ . Box >
958
+ </ $ . Box >
959
+ </ $ . Body >
960
+ ) ,
961
+ metas,
962
+ instanceSelector : [ "box-with-text" , "box" , "body" ] ,
963
+ } )
901
964
) . toEqual ( 1 ) ;
902
965
} ) ;
903
966
904
967
test ( "skips containers with expression" , ( ) => {
905
968
expect (
906
- findClosestContainer ( {
969
+ findClosestNonTextualContainer ( {
907
970
...renderJsx (
908
971
< $ . Body ws :id = "body" >
909
972
< $ . Box ws :id = "box" >
@@ -921,7 +984,7 @@ describe("find closest container", () => {
921
984
922
985
test ( "allow root with text" , ( ) => {
923
986
expect (
924
- findClosestContainer ( {
987
+ findClosestNonTextualContainer ( {
925
988
...renderJsx ( < $ . Body ws :id = "body" > text</ $ . Body > ) ,
926
989
metas,
927
990
instanceSelector : [ "body" ] ,
0 commit comments