33 */
44import { __ } from '@wordpress/i18n' ;
55import { useAnchor } from '@wordpress/rich-text' ;
6+ import { useEffect } from '@wordpress/element' ;
67import { Popover , TabPanel } from '@wordpress/components' ;
78
89/**
@@ -23,85 +24,97 @@ import { createFormatHelpers } from '../utils';
2324 * @param {boolean } props.isActive - Indicates if the format is currently active.
2425 * @return {JSX.Element } - The rendered InlineUI component.
2526 */
26- function InlineUI ( {
27+ function InlineUI ( {
2728 activeAttributes,
2829 value,
2930 onChange,
3031 onClose,
3132 contentRef,
3233 isActive,
33- } ) {
34+ } ) {
3435 const name = 'blablablocks/infotip' ; // Format type name
3536
36- const { update, remove } = createFormatHelpers ( {
37+ const { update, remove } = createFormatHelpers ( {
3738 value,
3839 onChange,
3940 formatType : name ,
4041 activeAttributes,
41- } ) ;
42+ } ) ;
4243
43- const anchor = useAnchor ( {
44+ const anchor = useAnchor ( {
4445 editableContentElement : contentRef ,
4546 settings : { isActive } ,
46- } ) ;
47+ } ) ;
48+
49+ useEffect ( ( ) => {
50+ return ( ) => {
51+ const { ownerDocument } = contentRef . current ;
52+ const infotips = ownerDocument . querySelectorAll ( 'tatva-infotip' ) ;
53+ infotips . forEach ( ( infotip ) => {
54+ if ( infotip && typeof infotip . hideTooltip === 'function' ) {
55+ infotip . hideTooltip ( ) ;
56+ }
57+ } ) ;
58+ } ;
59+ } , [ contentRef ] ) ;
4760
4861 return (
4962 < Popover
50- anchor = { anchor }
63+ anchor = { anchor }
5164 className = "block-editor-format-toolbar__blablablocks-infotip-popover"
5265 position = "middle center"
53- onClose = { onClose }
54- offset = { 30 }
66+ onClose = { onClose }
67+ offset = { 30 }
5568 shift
5669 __unstableSlotName = "__unstable-block-tools-after"
5770 >
5871 < TabPanel
5972 className = "block-editor-format-toolbar__blablablocks-infotip-tab-panel"
60- tabs = { [
73+ tabs = { [
6174 {
6275 name : 'text' ,
63- title : __ ( 'Text' , 'blablablocks-formats' ) ,
76+ title : __ ( 'Text' , 'blablablocks-formats' ) ,
6477 content : (
6578 < TextTab
66- activeAttributes = { activeAttributes }
67- name = { name }
68- onChange = { onChange }
69- onClose = { onClose }
70- removeAttributes = { remove }
71- updateAttributes = { update }
72- value = { value }
79+ activeAttributes = { activeAttributes }
80+ name = { name }
81+ onChange = { onChange }
82+ onClose = { onClose }
83+ removeAttributes = { remove }
84+ updateAttributes = { update }
85+ value = { value }
7386 />
7487 ) ,
7588 } ,
7689 {
7790 name : 'overlay' ,
78- title : __ ( 'Overlay' , 'blablablocks-formats' ) ,
91+ title : __ ( 'Overlay' , 'blablablocks-formats' ) ,
7992 content : (
8093 < OverlayTab
81- activeAttributes = { activeAttributes }
82- updateAttributes = { update }
83- removeAttributes = { remove }
94+ activeAttributes = { activeAttributes }
95+ updateAttributes = { update }
96+ removeAttributes = { remove }
8497 />
8598 ) ,
86- disabled : ! activeAttributes . content ,
99+ disabled : ! activeAttributes . content ,
87100 } ,
88101 {
89102 name : 'icon' ,
90- title : __ ( 'Icon' , 'blablablocks-formats' ) ,
103+ title : __ ( 'Icon' , 'blablablocks-formats' ) ,
91104 content : (
92105 < IconTab
93- activeAttributes = { activeAttributes }
94- updateAttributes = { update }
95- removeAttributes = { remove }
106+ activeAttributes = { activeAttributes }
107+ updateAttributes = { update }
108+ removeAttributes = { remove }
96109 />
97110 ) ,
98111 disabled :
99- ! activeAttributes . content &&
100- ! activeAttributes [ 'icon-enabled' ] ,
112+ ! activeAttributes . content &&
113+ ! activeAttributes [ 'icon-enabled' ] ,
101114 } ,
102- ] }
115+ ] }
103116 >
104- { ( tab ) => tab . content }
117+ { ( tab ) => tab . content }
105118 </ TabPanel >
106119 </ Popover >
107120 ) ;
0 commit comments