@@ -7,6 +7,8 @@ import React from 'react'
7
7
8
8
import Header from './components/header'
9
9
import Footer from './components/footer'
10
+
11
+ import { Search } from './components/search'
10
12
import { ThemeSwitch } from './components/theme-switch'
11
13
12
14
import { getPageData } from './modules/sanity/utils'
@@ -22,16 +24,28 @@ const render = async () => {
22
24
*/
23
25
24
26
const data = await getPageData ( )
27
+
25
28
const sidenav = document . querySelector ( 'button.fern-search-bar' )
26
29
?. parentElement as HTMLElement
27
30
28
31
const theme = document . getElementsByTagName ( 'html' ) [ 0 ] . getAttribute ( 'class' )
29
32
30
- if ( ! document . getElementById ( 'theme-switch' ) ) {
33
+ if ( ! document . getElementById ( 'sidenav-header-wrapper' ) ) {
34
+ const sidenavHeaderWrapper = document . createElement ( 'div' )
35
+ sidenavHeaderWrapper . setAttribute ( 'id' , 'sidenav-header-wrapper' )
36
+ sidenav . appendChild ( sidenavHeaderWrapper )
37
+
38
+ const search = document . createElement ( 'div' )
39
+ search . setAttribute ( 'id' , 'search-component' )
40
+ sidenavHeaderWrapper . appendChild ( search )
41
+ ReactDOM . render ( React . createElement ( Search ) , search )
42
+
31
43
const wrapper = document . createElement ( 'div' )
32
44
wrapper . setAttribute ( 'id' , 'theme-switch' )
33
- sidenav . appendChild ( wrapper )
45
+ sidenavHeaderWrapper . appendChild ( wrapper )
34
46
ReactDOM . render ( React . createElement ( ThemeSwitch ) , wrapper )
47
+
48
+ sidenav . replaceWith ( sidenavHeaderWrapper )
35
49
}
36
50
37
51
const fernHeaderId = document . getElementById ( FERN_CONTENT_WRAPPER_ID )
@@ -92,11 +106,46 @@ const render = async () => {
92
106
if ( footer ) footer . style . display = 'block'
93
107
} ,
94
108
)
109
+
110
+ // Add Plug component directly to body
111
+ if ( ! document . getElementById ( 'plug-platform' ) ) {
112
+ const plugScript = document . createElement ( 'script' )
113
+ plugScript . setAttribute ( 'type' , 'text/javascript' )
114
+ plugScript . setAttribute ( 'id' , 'plug-platform' )
115
+ plugScript . setAttribute ( 'src' , 'https://plug-platform.devrev.ai/static/plug.js' )
116
+ document . body . appendChild ( plugScript )
117
+
118
+ // Initialize Plug SDK after script loads
119
+ plugScript . onload = ( ) => {
120
+ if ( ( window as any ) . plugSDK ) {
121
+ ( window as any ) . plugSDK ?. init ?.( {
122
+ app_id : data ?. plug ?. id ,
123
+ enable_session_recording : true ,
124
+ } ) ;
125
+
126
+ // Wait for the widget to be ready before adding event listeners
127
+ ( window as any ) . plugSDK . onEvent ( ( payload : any ) => {
128
+ if ( payload . type === "ON_PLUG_WIDGET_READY" ) {
129
+ // Initialize search agent after widget is ready
130
+ ( window as any ) . plugSDK . initSearchAgent ( ) ;
131
+
132
+ // Add keyboard shortcut for search agent
133
+ document . addEventListener ( "keydown" , function ( event ) {
134
+ // Check if event.key is defined before accessing it
135
+ if ( event && event . key === "/" ) {
136
+ event . preventDefault ( ) ;
137
+ ( window as any ) . plugSDK . toggleSearchAgent ( ) ;
138
+ }
139
+ } ) ;
140
+ }
141
+ } ) ;
142
+ }
143
+ }
144
+ }
95
145
}
96
146
97
147
let observations = 0
98
148
document . addEventListener ( 'DOMContentLoaded' , async ( ) => {
99
- console . log ( 'DOMContentLoaded' )
100
149
await render ( )
101
150
new MutationObserver ( async ( e , o ) => {
102
151
await render ( )
0 commit comments