Skip to content

add: plug script #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d266357
add: plug script
nikhiltidke101 May 13, 2025
f9bc015
Merge branch 'main' into feat/plug
nikhiltidke101 May 13, 2025
5e5d10e
feat: integrate Plug SDK into main application
nikhiltidke101 May 13, 2025
c67893b
Merge branch 'feat/plug' of https://github.com/devrev/fern-api-docs i…
nikhiltidke101 May 13, 2025
e4a7d6c
Remove Plug component implementation from the codebase.
nikhiltidke101 May 13, 2025
0f6d93b
Remove unused Plug component import from main application file.
nikhiltidke101 May 13, 2025
165cf3b
chore: add @types/node to devDependencies in package.json
nikhiltidke101 May 13, 2025
4a013b9
fix: update Plug SDK initialization to use dynamic app ID from fetche…
nikhiltidke101 May 14, 2025
60f9545
feat: add search component and integrate into main application
nikhiltidke101 May 14, 2025
e447a28
refactor: comment out theme switch and search component initialization
nikhiltidke101 May 14, 2025
6a880d9
refactor: streamline search component integration
nikhiltidke101 May 14, 2025
86365f2
refactor: remove unused sidenav code from main application
nikhiltidke101 May 14, 2025
60a24d0
refactor: update search component integration in main application
nikhiltidke101 May 14, 2025
2aa4d8e
refactor: comment out search component rendering logic
nikhiltidke101 May 14, 2025
23e4e72
refactor: comment out theme switch and search component imports
nikhiltidke101 May 14, 2025
dc7a90a
refactor: integrate theme switch and search components into main appl…
nikhiltidke101 May 14, 2025
35de9ea
refactor: integrate search component rendering into main application
nikhiltidke101 May 14, 2025
7f93d54
feat: implement event handling for Plug SDK in main application
nikhiltidke101 May 14, 2025
0c61799
refactor: update key event handling for search agent activation
nikhiltidke101 May 14, 2025
f177745
refactor: comment out search component rendering logic
nikhiltidke101 May 14, 2025
5b65429
refactor: restore search component rendering logic in main application
nikhiltidke101 May 14, 2025
7b884bc
refactor: reorder imports for theme switch and search components in m…
nikhiltidke101 May 14, 2025
63e36ee
refactor: enhance event logging for Plug SDK integration in main appl…
nikhiltidke101 May 14, 2025
85b23b5
feat: add Widget component for Plug SDK integration in main application
nikhiltidke101 May 14, 2025
96ae4d8
feat: replace Widget component with Plug SDK integration in main appl…
nikhiltidke101 May 14, 2025
acdd873
refactor: restructure sidenav to include header wrapper for theme swi…
nikhiltidke101 May 14, 2025
9c4198e
refactor: improve event handling for Plug SDK widget readiness in mai…
nikhiltidke101 May 14, 2025
92db0e1
refactor: update sidenav structure and search button styling in main …
nikhiltidke101 May 14, 2025
5e87b13
refactor: adjust rendering order of theme switch and search component…
nikhiltidke101 May 14, 2025
967a035
refactor: remove PLUG_APP_ID environment variable from workflow files
nikhiltidke101 May 14, 2025
81fe745
refactor: remove @types/node dependency from custom implementation pa…
nikhiltidke101 May 14, 2025
b5b686e
refactor: remove Widget component from custom implementation package
nikhiltidke101 May 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/fern-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
registry-url: https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{secrets.AUTH_TOKEN}}


- name: Build Navigation
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/preview-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
registry-url: https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{secrets.AUTH_TOKEN}}


- name: Install Fern
run: npm install -g fern-api
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
registry-url: https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{secrets.AUTH_TOKEN}}


- name: Download Fern
run: npm install -g fern-api
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
registry-url: https://npm.pkg.github.com/
env:
NODE_AUTH_TOKEN: ${{secrets.AUTH_TOKEN}}


- name: Build Navigation
run: |
Expand Down
38 changes: 38 additions & 0 deletions custom-implementation/src/components/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export const Search = () => {
return (
<button
id="fern-search-button"
className="fern-search-bar w-full"
style={{ marginBottom: '8px' }}
onClick={() => {
if ((window as any).plugSDK) {
(window as any).plugSDK.toggleSearchAgent()
}
}}>
<span className="search-placeholder">
<svg
width="1.5em"
height="1.5em"
viewBox="0 0 24 24"
strokeWidth="1.5"
fill="none"
xmlns="http://www.w3.org/2000/svg"
color="currentColor"
className="size-icon-md">
<path
d="M17 17L21 21"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"></path>
<path
d="M3 11C3 15.4183 6.58172 19 11 19C13.213 19 15.2161 18.1015 16.6644 16.6493C18.1077 15.2022 19 13.2053 19 11C19 6.58172 15.4183 3 11 3C6.58172 3 3 6.58172 3 11Z"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"></path>
</svg>
<span>Search...</span>
</span>
<kbd className="keyboard-shortcut-hint">/</kbd>
</button>
)
}
55 changes: 52 additions & 3 deletions custom-implementation/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import React from 'react'

import Header from './components/header'
import Footer from './components/footer'

import { Search } from './components/search'
import { ThemeSwitch } from './components/theme-switch'

import { getPageData } from './modules/sanity/utils'
Expand All @@ -22,16 +24,28 @@ const render = async () => {
*/

const data = await getPageData()

const sidenav = document.querySelector('button.fern-search-bar')
?.parentElement as HTMLElement

const theme = document.getElementsByTagName('html')[0].getAttribute('class')

if (!document.getElementById('theme-switch')) {
if (!document.getElementById('sidenav-header-wrapper')) {
const sidenavHeaderWrapper = document.createElement('div')
sidenavHeaderWrapper.setAttribute('id', 'sidenav-header-wrapper')
sidenav.appendChild(sidenavHeaderWrapper)

const search = document.createElement('div')
search.setAttribute('id', 'search-component')
sidenavHeaderWrapper.appendChild(search)
ReactDOM.render(React.createElement(Search), search)

const wrapper = document.createElement('div')
wrapper.setAttribute('id', 'theme-switch')
sidenav.appendChild(wrapper)
sidenavHeaderWrapper.appendChild(wrapper)
ReactDOM.render(React.createElement(ThemeSwitch), wrapper)

sidenav.replaceWith(sidenavHeaderWrapper)
}

const fernHeaderId = document.getElementById(FERN_CONTENT_WRAPPER_ID)
Expand Down Expand Up @@ -92,11 +106,46 @@ const render = async () => {
if (footer) footer.style.display = 'block'
},
)

// Add Plug component directly to body
if (!document.getElementById('plug-platform')) {
const plugScript = document.createElement('script')
plugScript.setAttribute('type', 'text/javascript')
plugScript.setAttribute('id', 'plug-platform')
plugScript.setAttribute('src', 'https://plug-platform.devrev.ai/static/plug.js')
document.body.appendChild(plugScript)

// Initialize Plug SDK after script loads
plugScript.onload = () => {
if ((window as any).plugSDK) {
(window as any).plugSDK?.init?.({
app_id: data?.plug?.id,
enable_session_recording: true,
});

// Wait for the widget to be ready before adding event listeners
(window as any).plugSDK.onEvent((payload: any) => {
if(payload.type === "ON_PLUG_WIDGET_READY") {
// Initialize search agent after widget is ready
(window as any).plugSDK.initSearchAgent();

// Add keyboard shortcut for search agent
document.addEventListener("keydown", function(event) {
// Check if event.key is defined before accessing it
if (event && event.key === "/") {
event.preventDefault();
(window as any).plugSDK.toggleSearchAgent();
}
});
}
});
}
}
}
}

let observations = 0
document.addEventListener('DOMContentLoaded', async () => {
console.log('DOMContentLoaded')
await render()
new MutationObserver(async (e, o) => {
await render()
Expand Down
9 changes: 8 additions & 1 deletion custom-implementation/src/modules/sanity/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const SANITY_TYPES = {
export const getPageData = async (): Promise<{
header: object
footer: object
plug: { id: string }
}> => {
const header = await CLIENT.fetch(
`*[_type == 'headerV2' && slug.current == 'developer']{
Expand All @@ -28,5 +29,11 @@ export const getPageData = async (): Promise<{
}[0]`,
)

return { header, footer }
const plug = await CLIENT.fetch(
`*[_type == 'externalLink' && slug.current == 'devrev-plug-app-id']{
"id": href
}[0]`,
)

return { header, footer, plug }
}
Loading