@@ -19,6 +19,7 @@ import { TextSelection } from '../preview';
1919import { getContentArea , isExternalURL } from '../utils' ;
2020import { PreviewActions } from './preview-actions' ;
2121import { TextSelectionTooltip } from './text-selection-tooltip' ;
22+ import { useExistingLinkHighlight } from '../hooks/use-existing-link-highlight' ;
2223
2324/**
2425 * Props structure for PreviewIframe.
@@ -92,16 +93,18 @@ export const PreviewIframe = ( {
9293 } , [ previewUrl ] ) ;
9394
9495 // Create an actions bar to be mounted in the iframe with useIframeHighlight().
95- const actionsBar = < PreviewActions
96- activeLink = { activeLink }
97- onAccept = { onAccept }
98- onDiscard = { onDiscard }
99- onUpdateLink = { onUpdateLink }
100- onRemove = { onRemove }
101- onRestoreOriginal = { onRestoreOriginal }
102- selectedText = { selectedText ?? null }
103- iframeRef = { iframeRef }
104- /> ;
96+ const actionsBar = useMemo ( ( ) => (
97+ < PreviewActions
98+ activeLink = { activeLink }
99+ onAccept = { onAccept }
100+ onDiscard = { onDiscard }
101+ onUpdateLink = { onUpdateLink }
102+ onRemove = { onRemove }
103+ onRestoreOriginal = { onRestoreOriginal }
104+ selectedText = { selectedText ?? null }
105+ iframeRef = { iframeRef }
106+ />
107+ ) , [ activeLink , onAccept , onDiscard , onUpdateLink , onRemove , onRestoreOriginal , selectedText , iframeRef ] ) ;
105108
106109 /**
107110 * Highlights the smart link in the iframe.
@@ -111,7 +114,6 @@ export const PreviewIframe = ( {
111114 const {
112115 injectHighlightStyles,
113116 highlightSmartLink,
114- highlightLinkType,
115117 removeSmartLinkHighlights,
116118 } = useIframeHighlight ( {
117119 iframeRef,
@@ -123,6 +125,15 @@ export const PreviewIframe = ( {
123125 actionsBar,
124126 } ) ;
125127
128+ const {
129+ injectExistingLinkHighlightStyles,
130+ highlightExistingLinkType,
131+ } = useExistingLinkHighlight ( {
132+ iframeRef,
133+ contentAreaRef,
134+ activeLink,
135+ } ) ;
136+
126137 /**
127138 * Hides the admin bar from the iframe if the preview is in frontend mode.
128139 *
@@ -298,6 +309,7 @@ export const PreviewIframe = ( {
298309 }
299310
300311 injectHighlightStyles ( iframe ) ;
312+ injectExistingLinkHighlightStyles ( iframe ) ;
301313
302314 // Updates the content area ref to the iframe's content area.
303315 const contentArea = getContentArea ( iframe . contentDocument ) ;
@@ -311,19 +323,17 @@ export const PreviewIframe = ( {
311323 }
312324
313325 hideAdminBar ( iframe ) ;
314- highlightLinkType ( iframe , selectedLinkType ) ;
315326 disableNavigation ( iframe ) ;
316327
317328 onLoadingChange ( false ) ;
318329 jumpToSmartLink ( iframe ) ;
319330 } , [ contentAreaRef ,
320331 disableNavigation ,
321332 hideAdminBar ,
322- highlightLinkType ,
323333 injectHighlightStyles ,
334+ injectExistingLinkHighlightStyles ,
324335 jumpToSmartLink ,
325336 onLoadingChange ,
326- selectedLinkType ,
327337 ] ) ;
328338
329339 /**
@@ -399,8 +409,8 @@ export const PreviewIframe = ( {
399409 return ;
400410 }
401411
402- highlightLinkType ( iframe , selectedLinkType ) ;
403- } , [ contentAreaRef , highlightLinkType , isLoading , selectedLinkType ] ) ;
412+ highlightExistingLinkType ( iframe , selectedLinkType ) ;
413+ } , [ contentAreaRef , highlightExistingLinkType , isLoading , selectedLinkType ] ) ;
404414
405415 return (
406416 < div className = "wp-parsely-preview" >
0 commit comments