11import { useStore } from "@nanostores/react" ;
22import {
3- $editableBlockChildOutline ,
3+ $blockChildOutline ,
44 $instances ,
55 $isContentMode ,
66 $registeredComponentMetas ,
7- type EditableBlockChildOutline ,
7+ type BlockChildOutline ,
88} from "~/shared/nano-states" ;
99import {
1010 Box ,
@@ -23,7 +23,7 @@ import {
2323 Text ,
2424 iconButtonSize ,
2525} from "@webstudio-is/design-system" ;
26- import { EditableBlockChildAddButtonOutline } from "./outline" ;
26+ import { BlockChildAddButtonOutline } from "./outline" ;
2727import { applyScale } from "./apply-scale" ;
2828import { $scale } from "~/builder/shared/nano-states" ;
2929import { PlusIcon } from "@webstudio-is/icons" ;
@@ -33,8 +33,8 @@ import { isFeatureEnabled } from "@webstudio-is/feature-flags";
3333import type { DroppableTarget , InstanceSelector } from "~/shared/tree-utils" ;
3434import type { Instance , Instances } from "@webstudio-is/sdk" ;
3535import {
36- editableBlockComponent ,
37- editableBlockTemplateComponent ,
36+ blockComponent ,
37+ blockTemplateComponent ,
3838} from "@webstudio-is/react-sdk" ;
3939import {
4040 extractWebstudioFragment ,
@@ -47,7 +47,7 @@ import {
4747import { shallowEqual } from "shallow-equal" ;
4848import { MetaIcon } from "~/builder/shared/meta-icon" ;
4949
50- export const findEditableBlockSelector = (
50+ export const findBlockSelector = (
5151 anchor : InstanceSelector ,
5252 instances : Instances
5353) => {
@@ -59,7 +59,7 @@ export const findEditableBlockSelector = (
5959 return ;
6060 }
6161
62- let editableBlockInstanceSelector : InstanceSelector | undefined = undefined ;
62+ let blockInstanceSelector : InstanceSelector | undefined = undefined ;
6363
6464 for ( let i = 0 ; i < anchor . length ; ++ i ) {
6565 const instanceId = anchor [ i ] ;
@@ -69,40 +69,37 @@ export const findEditableBlockSelector = (
6969 return ;
7070 }
7171
72- if ( instance . component === editableBlockComponent ) {
73- editableBlockInstanceSelector = anchor . slice ( i ) ;
72+ if ( instance . component === blockComponent ) {
73+ blockInstanceSelector = anchor . slice ( i ) ;
7474 break ;
7575 }
7676 }
7777
78- if ( editableBlockInstanceSelector === undefined ) {
78+ if ( blockInstanceSelector === undefined ) {
7979 return ;
8080 }
8181
82- return editableBlockInstanceSelector ;
82+ return blockInstanceSelector ;
8383} ;
8484
8585const findTemplates = ( anchor : InstanceSelector , instances : Instances ) => {
86- const editableBlockInstanceSelector = findEditableBlockSelector (
87- anchor ,
88- instances
89- ) ;
90- if ( editableBlockInstanceSelector === undefined ) {
86+ const blockInstanceSelector = findBlockSelector ( anchor , instances ) ;
87+ if ( blockInstanceSelector === undefined ) {
9188 toast . error ( "Editable block not found" ) ;
9289 return ;
9390 }
9491
95- const editableBlockInstance = instances . get ( editableBlockInstanceSelector [ 0 ] ) ;
92+ const blockInstance = instances . get ( blockInstanceSelector [ 0 ] ) ;
9693
97- if ( editableBlockInstance === undefined ) {
94+ if ( blockInstance === undefined ) {
9895 toast . error ( "Editable block instance not found" ) ;
9996 return ;
10097 }
10198
102- const templateInstanceId = editableBlockInstance . children . find (
99+ const templateInstanceId = blockInstance . children . find (
103100 ( child ) =>
104101 child . type === "id" &&
105- instances . get ( child . value ) ?. component === editableBlockTemplateComponent
102+ instances . get ( child . value ) ?. component === blockTemplateComponent
106103 ) ?. value ;
107104
108105 if ( templateInstanceId === undefined ) {
@@ -125,7 +122,7 @@ const findTemplates = (anchor: InstanceSelector, instances: Instances) => {
125122 . filter ( ( child ) => child !== undefined )
126123 . map ( ( child ) => [
127124 child ,
128- [ child . id , templateInstanceId , ...editableBlockInstanceSelector ] ,
125+ [ child . id , templateInstanceId , ...blockInstanceSelector ] ,
129126 ] ) ;
130127
131128 return result ;
@@ -136,29 +133,27 @@ const getInsertionIndex = (
136133 instances : Instances ,
137134 insertBefore : boolean = false
138135) => {
139- const editableBlockSelector = findEditableBlockSelector ( anchor , instances ) ;
140- if ( editableBlockSelector === undefined ) {
136+ const blockSelector = findBlockSelector ( anchor , instances ) ;
137+ if ( blockSelector === undefined ) {
141138 return ;
142139 }
143140
144- const insertAtInitialPosition = shallowEqual ( editableBlockSelector , anchor ) ;
141+ const insertAtInitialPosition = shallowEqual ( blockSelector , anchor ) ;
145142
146- const editableBlockInstance = instances . get ( editableBlockSelector [ 0 ] ) ;
143+ const blockInstance = instances . get ( blockSelector [ 0 ] ) ;
147144
148- if ( editableBlockInstance === undefined ) {
145+ if ( blockInstance === undefined ) {
149146 toast . error ( "Editable block instance not found" ) ;
150147 return ;
151148 }
152149
153- const index = editableBlockInstance . children . findIndex ( ( child ) => {
150+ const index = blockInstance . children . findIndex ( ( child ) => {
154151 if ( child . type !== "id" ) {
155152 return false ;
156153 }
157154
158155 if ( insertAtInitialPosition ) {
159- return (
160- instances . get ( child . value ) ?. component === editableBlockTemplateComponent
161- ) ;
156+ return instances . get ( child . value ) ?. component === blockTemplateComponent ;
162157 }
163158
164159 return child . value === anchor [ 0 ] ;
@@ -256,10 +251,7 @@ const TemplatesMenu = ({
256251 templateSelector [ 0 ]
257252 ) ;
258253
259- const parentSelector = findEditableBlockSelector (
260- anchor ,
261- instances
262- ) ;
254+ const parentSelector = findBlockSelector ( anchor , instances ) ;
263255
264256 if ( parentSelector === undefined ) {
265257 return ;
@@ -322,19 +314,19 @@ const TemplatesMenu = ({
322314 ) ;
323315} ;
324316
325- export const EditableBlockChildHoveredInstanceOutline = ( ) => {
326- const editableBlockChildOutline = useStore ( $editableBlockChildOutline ) ;
317+ export const BlockChildHoveredInstanceOutline = ( ) => {
318+ const blockChildOutline = useStore ( $blockChildOutline ) ;
327319 const scale = useStore ( $scale ) ;
328320 const isContentMode = useStore ( $isContentMode ) ;
329321
330322 const timeoutRef = useRef < undefined | ReturnType < typeof setTimeout > > (
331323 undefined
332324 ) ;
333325 const [ buttonOutline , setButtonOutline ] = useState <
334- undefined | EditableBlockChildOutline
326+ undefined | BlockChildOutline
335327 > ( undefined ) ;
336328
337- const outline = editableBlockChildOutline ?? buttonOutline ;
329+ const outline = blockChildOutline ?? buttonOutline ;
338330
339331 const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
340332
@@ -353,7 +345,7 @@ export const EditableBlockChildHoveredInstanceOutline = () => {
353345 const rect = applyScale ( outline . rect , scale ) ;
354346
355347 return (
356- < EditableBlockChildAddButtonOutline rect = { rect } >
348+ < BlockChildAddButtonOutline rect = { rect } >
357349 < Flex
358350 css = { {
359351 width : "min-content" ,
@@ -399,6 +391,6 @@ export const EditableBlockChildHoveredInstanceOutline = () => {
399391 </ IconButton >
400392 </ TemplatesMenu >
401393 </ Flex >
402- </ EditableBlockChildAddButtonOutline >
394+ </ BlockChildAddButtonOutline >
403395 ) ;
404396} ;
0 commit comments