-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
frontend/app/src/app/(main)/(admin)/site-settings/custom_js/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use client' | ||
|
||
import Highlight from 'highlight.js/lib/core'; | ||
import html from 'highlight.js/lib/languages/xml'; | ||
import { useEffect, useState } from 'react'; | ||
import './code-theme.scss'; | ||
|
||
export interface HtmlViewerProps { | ||
content: string; | ||
mime: string; | ||
} | ||
|
||
Highlight.registerLanguage('html', html); | ||
|
||
export function HtmlViewer ({ value: propValue }: { value: string }) { | ||
const [value, setValue] = useState(() => propValue.replaceAll('<', '<')); | ||
|
||
useEffect(() => { | ||
setValue(propValue); | ||
try { | ||
const { value: result } = Highlight.highlight('html', propValue); | ||
setValue(result); | ||
} catch { | ||
} | ||
}, [propValue]); | ||
|
||
return ( | ||
<code> | ||
<pre className="whitespace-pre-wrap text-xs font-mono" dangerouslySetInnerHTML={{ __html: value }} /> | ||
</code> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use client'; | ||
|
||
import { HtmlViewer } from '@/components/html-viewer'; | ||
import { Button } from '@/components/ui/button'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
const base = process.env.SITE_URL || ''; | ||
|
||
export function WidgetSnippet () { | ||
const [copied, setCopied] = useState(false); | ||
|
||
const [url, setUrl] = useState(base + '/widget.js'); | ||
|
||
const script = `<script src="${url}" async></script>` | ||
|
||
useEffect(() => { | ||
if (!process.env.SITE_URL) { | ||
setUrl(location.origin + '/widget.js'); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div className="rounded-lg p-2 border mb-4 relative bg-foreground/5"> | ||
<div className='text-xs font-mono opacity-30 select-none'><<span className='hljs-name'>html</span>></div> | ||
<div className='text-xs font-mono opacity-30 select-none'><<span className="hljs-name">body</span>></div> | ||
<div className='text-xs font-mono opacity-30 select-none whitespace-pre'> ...</div> | ||
<HtmlViewer value={` ${script}`} /> | ||
<div className="text-xs font-mono opacity-30 select-none"></<span className="hljs-name">body</span>></div> | ||
<div className='text-xs font-mono opacity-30 select-none'></<span className='hljs-name'>html</span>></div> | ||
<Button variant="secondary" size='sm' className='absolute top-0.5 right-0.5 select-none' onClick={() => { | ||
navigator.clipboard.writeText(script); | ||
setCopied(true); | ||
}}> | ||
{copied ? 'Copied' : 'Copy'} | ||
</Button> | ||
</div> | ||
); | ||
} |