Skip to content

Commit

Permalink
💚 [docs] Fix static build for the online editor
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-liu committed Feb 12, 2025
1 parent 5e28151 commit f9ab7f4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 55 deletions.
57 changes: 57 additions & 0 deletions docs/src/editor/online-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,60 @@ export function OnlineEditorInput(props: ComponentProps<'div'>) {
export function OnlineEditorOutput(props: ComponentProps<'div'>) {
return <div {...props} ref={useOnlineEditorCtrl().outputRef} />
}

export function OnlineEditorPageContent() {
let initCode = `\
// ↓ ↓ ↓ Add support code if needed. ↑ ↑ ↑ Do not delete \`import ...\` ↑
// ↑ ↑ ↑ Add support code if needed. ↓ ↓ ↓ Do not delete the \`rules\` variable ↓
let rules = [
// ↓ ↓ ↓ Add rules and/or layers. ↑ ↑ ↑ Do not delete the \`rules\` variable ↑
rule('Playground').manipulators([
map('⇪').toHyper().toIfAlone('⎋'),
{ escape: toKey('caps_lock') },
]),
// ↑ ↑ ↑ Add rules and/or layers. ↓ ↓ ↓ Do not delete \`]\` below ↓
]\n`
return (
<OnlineEditorProvider code={initCode}>
<OnlineEditorPageHeader />
<div
style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr',
flex: 1,
}}>
<OnlineEditorInput />
<OnlineEditorOutput />
</div>
</OnlineEditorProvider>
)
}

function OnlineEditorPageHeader() {
let ctrl = useOnlineEditorCtrl()
function handleCopyJson() {
let text = ctrl.editors.output?.getValue()
if (text) {
void navigator.clipboard.writeText(text)
}
}
return (
<div
style={{
padding: '1rem',
display: 'flex',
justifyContent: 'flex-end',
gap: '1rem',
}}>
<a
href="https://karabiner-elements.pqrs.org/docs/manual/configuration/configure-complex-modifications/#create-your-own-rules"
target="_blank">
? Import to Karabiner-Elements
</a>
<button onClick={handleCopyJson}>Copy JSON</button>
</div>
)
}
63 changes: 8 additions & 55 deletions docs/src/pages/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,16 @@
import {
OnlineEditorInput,
OnlineEditorOutput,
OnlineEditorProvider,
useOnlineEditorCtrl,
} from '@site/src/editor/online-editor'
import BrowserOnly from '@docusaurus/BrowserOnly'
import Layout from '@theme/Layout'

let initCode = `\
// ↓ ↓ ↓ Add support code if needed. ↑ ↑ ↑ Do not delete \`import ...\` ↑
// ↑ ↑ ↑ Add support code if needed. ↓ ↓ ↓ Do not delete the \`rules\` variable ↓
let rules = [
// ↓ ↓ ↓ Add rules and/or layers. ↑ ↑ ↑ Do not delete the \`rules\` variable ↑
rule('Playground').manipulators([
map('⇪').toHyper().toIfAlone('⎋'),
{ escape: toKey('caps_lock') },
]),
// ↑ ↑ ↑ Add rules and/or layers. ↓ ↓ ↓ Do not delete \`]\` below ↓
]\n`

export default function EditorPage() {
return (
<Layout title="Online Editor">
<OnlineEditorProvider code={initCode}>
<OnlineEditorHeader />
<div
style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', flex: 1 }}>
<OnlineEditorInput />
<OnlineEditorOutput />
</div>
</OnlineEditorProvider>
<BrowserOnly>
{() => {
let OnlineEditorPageContent =
require('@site/src/editor/online-editor').OnlineEditorPageContent
return <OnlineEditorPageContent />
}}
</BrowserOnly>
</Layout>
)
}

function OnlineEditorHeader() {
let ctrl = useOnlineEditorCtrl()
function handleCopyJson() {
let text = ctrl.editors.output?.getValue()
if (text) {
void navigator.clipboard.writeText(text)
}
}
return (
<div
style={{
padding: '1rem',
display: 'flex',
justifyContent: 'flex-end',
gap: '1rem',
}}>
<a
href="https://karabiner-elements.pqrs.org/docs/manual/configuration/configure-complex-modifications/#create-your-own-rules"
target="_blank">
? Import to Karabiner-Elements
</a>
<button onClick={handleCopyJson}>Copy JSON</button>
</div>
)
}

0 comments on commit f9ab7f4

Please sign in to comment.