2023-07-27 00:31:52 -05:00
|
|
|
<!--
|
2024-02-13 09:50:11 -06:00
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 00:31:52 -05:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2019-01-26 23:34:52 -06:00
|
|
|
<template>
|
2024-01-17 21:16:12 -06:00
|
|
|
<div :class="$style.codeBlockRoot">
|
2024-01-17 19:53:29 -06:00
|
|
|
<button :class="$style.codeBlockCopyButton" class="_button" @click="copy">
|
|
|
|
<i class="ti ti-copy"></i>
|
2023-12-02 19:58:42 -06:00
|
|
|
</button>
|
2024-01-17 19:53:29 -06:00
|
|
|
<Suspense>
|
|
|
|
<template #fallback>
|
|
|
|
<MkLoading />
|
|
|
|
</template>
|
|
|
|
<XCode v-if="show && lang" :code="code" :lang="lang"/>
|
|
|
|
<pre v-else-if="show" :class="$style.codeBlockFallbackRoot"><code :class="$style.codeBlockFallbackCode">{{ code }}</code></pre>
|
|
|
|
<button v-else :class="$style.codePlaceholderRoot" @click="show = true">
|
|
|
|
<div :class="$style.codePlaceholderContainer">
|
|
|
|
<div><i class="ti ti-code"></i> {{ i18n.ts.code }}</div>
|
|
|
|
<div>{{ i18n.ts.clickToShow }}</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</Suspense>
|
|
|
|
</div>
|
2019-01-26 23:34:52 -06:00
|
|
|
</template>
|
|
|
|
|
2022-01-10 09:05:18 -06:00
|
|
|
<script lang="ts" setup>
|
2023-12-02 19:58:42 -06:00
|
|
|
import { defineAsyncComponent, ref } from 'vue';
|
2024-01-17 19:53:29 -06:00
|
|
|
import * as os from '@/os.js';
|
2023-10-29 00:12:40 -05:00
|
|
|
import MkLoading from '@/components/global/MkLoading.vue';
|
2023-12-02 19:58:42 -06:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2024-01-17 19:53:29 -06:00
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2024-01-17 19:53:29 -06:00
|
|
|
const props = defineProps<{
|
2022-01-10 09:05:18 -06:00
|
|
|
code: string;
|
|
|
|
lang?: string;
|
|
|
|
}>();
|
|
|
|
|
2023-12-02 19:58:42 -06:00
|
|
|
const show = ref(!defaultStore.state.dataSaver.code);
|
|
|
|
|
2022-08-30 10:24:33 -05:00
|
|
|
const XCode = defineAsyncComponent(() => import('@/components/MkCode.core.vue'));
|
2024-01-17 19:53:29 -06:00
|
|
|
|
|
|
|
function copy() {
|
|
|
|
copyToClipboard(props.code);
|
|
|
|
os.success();
|
|
|
|
}
|
2019-01-26 23:34:52 -06:00
|
|
|
</script>
|
2023-10-29 00:12:40 -05:00
|
|
|
|
|
|
|
<style module lang="scss">
|
2024-01-17 19:53:29 -06:00
|
|
|
.codeBlockRoot {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.codeBlockCopyButton {
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 0.8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-15 21:34:35 -06:00
|
|
|
.codeBlockFallbackRoot {
|
|
|
|
display: block;
|
|
|
|
overflow-wrap: anywhere;
|
2024-02-06 00:03:07 -06:00
|
|
|
background: var(--bg);
|
2023-12-15 21:34:35 -06:00
|
|
|
padding: 1em;
|
|
|
|
margin: .5em 0;
|
|
|
|
overflow: auto;
|
|
|
|
border-radius: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.codeBlockFallbackCode {
|
|
|
|
font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
|
|
|
|
}
|
|
|
|
|
2023-12-02 19:58:42 -06:00
|
|
|
.codePlaceholderRoot {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
outline: none;
|
|
|
|
font: inherit;
|
|
|
|
color: inherit;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
border-radius: 8px;
|
|
|
|
padding: 24px;
|
|
|
|
margin-top: 4px;
|
2024-02-06 00:03:07 -06:00
|
|
|
color: var(--fg);
|
|
|
|
background: var(--bg);
|
2023-12-02 19:58:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
.codePlaceholderContainer {
|
|
|
|
text-align: center;
|
|
|
|
font-size: 0.8em;
|
|
|
|
}
|
2023-10-29 00:12:40 -05:00
|
|
|
</style>
|