mirror of
https://github.com/garraflavatra/rolens.git
synced 2024-12-01 13:20:54 +00:00
Universal code viewer
This commit is contained in:
parent
f9f1bc168c
commit
2e312dc7cb
@ -1,12 +1,18 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import CodeViewer from './codeviewer.svelte';
|
||||||
|
|
||||||
export let code = '';
|
export let code = '';
|
||||||
|
|
||||||
|
let modalCode = '';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="examplecode">
|
<div class="examplecode" on:pointerdown={() => modalCode = code}>
|
||||||
<strong>CLI command</strong>
|
<strong>CLI command</strong>
|
||||||
<code>{code}</code>
|
<code>{code}</code>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<CodeViewer bind:code={modalCode} language="js" />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.examplecode {
|
.examplecode {
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
|
@ -1,22 +1,31 @@
|
|||||||
<script>
|
<script>
|
||||||
import hljs from 'highlight.js/lib/core';
|
import hljs from 'highlight.js/lib/core';
|
||||||
import hljsJson from 'highlight.js/lib/languages/json';
|
import hljsJSON from 'highlight.js/lib/languages/json';
|
||||||
import 'highlight.js/styles/atom-one-dark.css';
|
import hljsJavaScript from 'highlight.js/lib/languages/javascript';
|
||||||
import Icon from './icon.svelte';
|
import Icon from './icon.svelte';
|
||||||
import Modal from './modal.svelte';
|
import Modal from './modal.svelte';
|
||||||
|
import 'highlight.js/styles/atom-one-dark.css';
|
||||||
|
|
||||||
export let json = '';
|
export let code = '';
|
||||||
|
export let language = 'json';
|
||||||
|
|
||||||
hljs.registerLanguage('json', hljsJson);
|
const languageNames = {
|
||||||
$: highlighted = json ? hljs.highlight('json', json).value : '';
|
json: 'JSON',
|
||||||
|
js: 'JavaScript',
|
||||||
|
};
|
||||||
|
|
||||||
|
hljs.registerLanguage('json', hljsJSON);
|
||||||
|
hljs.registerLanguage('js', hljsJavaScript);
|
||||||
|
|
||||||
|
$: highlighted = code ? hljs.highlight(language, code).value : '';
|
||||||
|
|
||||||
function copy() {
|
function copy() {
|
||||||
navigator.clipboard.writeText(json);
|
navigator.clipboard.writeText(code);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if json}
|
{#if code}
|
||||||
<Modal bind:show={json} title="JSON viewer" contentPadding={false}>
|
<Modal bind:show={code} title="{languageNames[language]} viewer" contentPadding={false}>
|
||||||
<div class="codeblock">
|
<div class="codeblock">
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button class="btn" on:click={copy}>
|
<button class="btn" on:click={copy}>
|
@ -5,7 +5,7 @@
|
|||||||
import { input } from '../../actions';
|
import { input } from '../../actions';
|
||||||
import ObjectGrid from '../../components/objectgrid.svelte';
|
import ObjectGrid from '../../components/objectgrid.svelte';
|
||||||
import Icon from '../../components/icon.svelte';
|
import Icon from '../../components/icon.svelte';
|
||||||
import JsonViewer from '../../components/jsonviewer.svelte';
|
import CodeViewer from '../../components/codeviewer.svelte';
|
||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<JsonViewer bind:json />
|
<CodeViewer bind:code={json} language="json" />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.find {
|
.find {
|
||||||
|
Loading…
Reference in New Issue
Block a user