Skip to content

Commit

Permalink
Add fullscreen mode for mermaid
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Aug 14, 2023
1 parent 8cc578f commit 5ada407
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 42 deletions.
55 changes: 13 additions & 42 deletions components/content/Mermaid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,24 @@
-->

<script setup lang="ts">
const { $mermaid } = useNuxtApp()
import FullscreenView from '../ep/FullscreenView.vue'
import MermaidDiagram from '../ep/MermaidDiagram.vue'
const props = defineProps<{
code: string
}>()
const decodedCode = computed(() => {
return atob(props.code)
})
const root = ref<HTMLElement | null>(null)
const codeBlock = ref<HTMLElement | null>(null)
const isDiagramLoading = ref(true)
async function renderMermaidDiagram() {
isDiagramLoading.value = true
if (codeBlock.value && $mermaid) {
try {
await $mermaid.run({
nodes: [codeBlock.value],
suppressErrors: true
})
} catch (e) {}
isDiagramLoading.value = false
}
}
onMounted(() => {
renderMermaidDiagram()
})
</script>

<template>
<figure ref="root" class="relative">
<pre
ref="codeBlock"
style="background: none"
:class="{
'opacity-0': isDiagramLoading
}"
v-text="decodedCode"
></pre>
<div>
<div v-if="isDiagramLoading" class="absolute inset-0 font-serif">
Mermaid diagram is loading...
</div>
</div>
</figure>
<FullscreenView>
<template #default="{ onClick, isFullscreen }">
<MermaidDiagram
:class="{
'cursor-zoom-in hover:shadow transition-shadow': !isFullscreen
}"
:code="props.code"
@click="onClick"
/>
</template>
</FullscreenView>
</template>
67 changes: 67 additions & 0 deletions components/ep/MermaidDiagram.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--
~ Copyright 2023 Exactpro (Exactpro Systems Limited)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<script setup lang="ts">
const { $mermaid } = useNuxtApp()
const props = defineProps<{
code: string
}>()
const decodedCode = computed(() => {
return atob(props.code)
})
const root = ref<HTMLElement | null>(null)
const codeBlock = ref<HTMLElement | null>(null)
const isDiagramLoading = ref(true)
async function renderMermaidDiagram() {
isDiagramLoading.value = true
if (codeBlock.value && $mermaid) {
try {
await $mermaid.run({
nodes: [codeBlock.value],
suppressErrors: true
})
} catch (e) {}
isDiagramLoading.value = false
}
}
onMounted(() => {
renderMermaidDiagram()
})
</script>

<template>
<figure ref="root" class="relative">
<pre
ref="codeBlock"
style="background: none"
:class="{
'opacity-0': isDiagramLoading
}"
v-text="decodedCode"
></pre>
<div>
<div v-if="isDiagramLoading" class="absolute inset-0 font-serif">
Mermaid diagram is loading...
</div>
</div>
</figure>
</template>

0 comments on commit 5ada407

Please sign in to comment.