-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
137 additions
and
138 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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,118 @@ | ||
import {createRoot} from 'react-dom/client'; | ||
import {ThemeProvider} from '@gravity-ui/uikit'; | ||
import {useCallback, useState, useEffect} from 'react'; | ||
import {Container, Row, Col} from '@gravity-ui/uikit'; | ||
|
||
import {App} from './app'; | ||
import {CallOut} from './callout'; | ||
import {InputArea} from './input-area'; | ||
import {OutputArea} from './output-area'; | ||
|
||
import './index.css'; | ||
import '@doc-tools/transform/dist/js/yfm.js'; | ||
import {useTabs} from './useTabs'; | ||
import {generateMD, generateHTML, generateTokens} from './generators'; | ||
import persistRestore from './persistRestore'; | ||
|
||
const container = document.getElementById('app'); | ||
const root = createRoot(container as HTMLElement); | ||
import './styles.css'; | ||
|
||
root.render( | ||
<ThemeProvider theme="light"> | ||
<App /> | ||
</ThemeProvider> | ||
); | ||
(window as any).MonacoEnvironment = { | ||
getWorker: (_, label: string) => { | ||
if (label === 'json') { | ||
return new Worker( | ||
new URL('monaco-editor/esm/vs/language/json/json.worker?worker', 'monaco-worker'), | ||
); | ||
} | ||
return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker?worker', 'monaco-worker')); | ||
}, | ||
}; | ||
|
||
const App = () => { | ||
return(<> | ||
<Container> | ||
<CallOut /> | ||
<Playground persistRestore={true} /> | ||
</Container> | ||
</>) | ||
}; | ||
|
||
export type PlaygroundProperties = { | ||
content?: string; | ||
persistRestore?: boolean; | ||
} | ||
|
||
function Playground(props: PlaygroundProperties) { | ||
const persist = useCallback(persistRestore.persist, []); | ||
const restore = useCallback(persistRestore.restore, []); | ||
const content = props?.persistRestore ? restore() : props?.content | ||
const [input, setInput] = useState(content ?? ''); | ||
const [generated, setGenerated] = useState(input); | ||
|
||
const generate = useCallback((active: string) => { | ||
if (active === 'markdown') { | ||
setGenerated(generateMD(input)); | ||
} else if (active === 'html') { | ||
setGenerated(generateHTML(input)); | ||
} else if (active === 'tokens') { | ||
setGenerated(generateTokens(input)); | ||
} else if (active === 'preview') { | ||
setGenerated(generateHTML(input)); | ||
} else { | ||
setGenerated(input); | ||
} | ||
}, [input]); | ||
|
||
const [ | ||
inputItems, | ||
inputActive, | ||
handleSetInputAreaTabActive | ||
] = useTabs({ | ||
items: [ { id: 'input', title: 'input' } ], | ||
initial: 'input', | ||
}); | ||
|
||
const [ | ||
outputItems, | ||
outputActive, | ||
handleSetOutputAreaTabActive | ||
] = useTabs({ | ||
items: [ | ||
{ id: 'preview', title: 'html preview' }, | ||
{ id: 'html', title: 'html' }, | ||
{ id: 'markdown', title: 'markdown' }, | ||
{ id: 'tokens', title: 'tokens' }, | ||
], | ||
initial: 'preview', | ||
onSetActive: generate, | ||
}); | ||
|
||
const handleInputChange = (input?: string) => { | ||
setInput(input || ''); | ||
}; | ||
|
||
useEffect(() => { | ||
generate(outputActive); | ||
|
||
if (props?.persistRestore) { | ||
persist(input); | ||
} | ||
}, [input]); | ||
|
||
return ( | ||
<Row space={6} className="diplodoc-playground"> | ||
<Col s="12"/> | ||
<InputArea | ||
handleSelectTab={handleSetInputAreaTabActive} | ||
handleInputChange={handleInputChange} | ||
input={input} | ||
|
||
tabActive={inputActive} | ||
tabItems={inputItems} | ||
/> | ||
<OutputArea | ||
handleSelectTab={handleSetOutputAreaTabActive} | ||
tabItems={outputItems} | ||
tabActive={outputActive} | ||
output={generated} | ||
/> | ||
</Row> | ||
); | ||
} | ||
|
||
export {App, Playground}; | ||
export default {App, Playground}; |
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,16 @@ | ||
import {createRoot} from 'react-dom/client'; | ||
import {ThemeProvider} from '@gravity-ui/uikit'; | ||
|
||
import {App} from './index'; | ||
|
||
import './index.css'; | ||
import '@doc-tools/transform/dist/js/yfm.js'; | ||
|
||
const container = document.getElementById('app'); | ||
const root = createRoot(container as HTMLElement); | ||
|
||
root.render( | ||
<ThemeProvider theme="light"> | ||
<App /> | ||
</ThemeProvider> | ||
); |
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