1- import React , { FC , ReactElement , useEffect , useRef , useState } from 'react'
1+ import React , { FC , ReactElement , useEffect , useState } from 'react'
22import { createPortal } from 'react-dom'
33import { IContextNode } from '@mweb/core'
44import { InsertionType } from '@mweb/core'
@@ -13,7 +13,14 @@ export const ContextPortal: FC<{
1313 // ToDo: replace insPoints.find with Map
1414 const target = injectTo
1515 ? context . insPoints . find ( ( ip ) => ip . name === injectTo )
16- : { element : context . element , insertionType : DefaultInsertionType }
16+ : {
17+ element : context . element ,
18+ insertionType :
19+ // ToDo: de-hardcode when context modificators will be implemented (using contexts instead of insertion points)
20+ context . namespace === 'engine' && context . contextType === 'link'
21+ ? InsertionType . Replace
22+ : DefaultInsertionType ,
23+ }
1724
1825 if ( ! target ?. element ) return null
1926 if ( ! target ?. insertionType ) return null
@@ -49,13 +56,29 @@ const InsPointPortal: FC<{
4956 case InsertionType . End :
5057 element . appendChild ( _container )
5158 break
59+ case InsertionType . Replace :
60+ // Only one layout manager will be injected
61+ // so this code will be executed only once for multiple widgets
62+
63+ // We hide the element instead of removing it
64+ // because it must be shown again when the layout manager is unmounted.
65+ // Also it prevents unexpected behaviour of an original website.
66+ element . style . display = 'none'
67+
68+ element . after ( _container )
69+ break
5270 default :
5371 break
5472 }
5573
5674 setContainer ( _container )
5775
5876 return ( ) => {
77+ if ( insertionType === InsertionType . Replace ) {
78+ // ToDo: hidden contexts will be shown
79+ element . style . display = ''
80+ }
81+
5982 _container . remove ( )
6083 setContainer ( null )
6184 }
0 commit comments