feat: ✨ mermaid
run mermaid on stacked notes
This commit is contained in:
@@ -5,28 +5,29 @@ import {
|
|||||||
nextTick,
|
nextTick,
|
||||||
onMounted,
|
onMounted,
|
||||||
ref,
|
ref,
|
||||||
watch
|
watch,
|
||||||
} from 'vue'
|
} from "vue"
|
||||||
|
|
||||||
import { useEditionMode } from '@/hooks/useEditionMode'
|
import { useEditionMode } from "@/hooks/useEditionMode"
|
||||||
import { useFile } from '@/hooks/useFile.hook'
|
import { useFile } from "@/hooks/useFile.hook"
|
||||||
import { useGitHubContent } from '@/hooks/useGitHubContent.hook'
|
import { useGitHubContent } from "@/hooks/useGitHubContent.hook"
|
||||||
import { useImages } from '@/hooks/useImages.hook'
|
import { useImages } from "@/hooks/useImages.hook"
|
||||||
import { useLinks } from '@/hooks/useLinks.hook'
|
import { useLinks } from "@/hooks/useLinks.hook"
|
||||||
import { useNoteOverlay } from '@/hooks/useNoteOverlay.hook'
|
import { useNoteOverlay } from "@/hooks/useNoteOverlay.hook"
|
||||||
import { useRouteQueryStackedNotes } from '@/hooks/useRouteQueryStackedNotes.hook'
|
import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook"
|
||||||
import { useTitleNotes } from '@/hooks/useTitleNotes.hook'
|
import { useTitleNotes } from "@/hooks/useTitleNotes.hook"
|
||||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
|
||||||
import { encodeUTF8ToBase64 } from '@/utils/decodeBase64ToUTF8'
|
import { encodeUTF8ToBase64 } from "@/utils/decodeBase64ToUTF8"
|
||||||
import { filenameToNoteTitle } from '@/utils/noteTitle'
|
import { filenameToNoteTitle } from "@/utils/noteTitle"
|
||||||
import { generateTweets } from '@/utils/twitter'
|
import { generateTweets } from "@/utils/twitter"
|
||||||
|
import mermaid from "mermaid"
|
||||||
|
|
||||||
const LinkedNotes = defineAsyncComponent(
|
const LinkedNotes = defineAsyncComponent(
|
||||||
() => import('@/components/LinkedNotes.vue')
|
() => import("@/components/LinkedNotes.vue"),
|
||||||
)
|
)
|
||||||
|
|
||||||
const EditNote = defineAsyncComponent(
|
const EditNote = defineAsyncComponent(
|
||||||
() => import('@/modules/note/components/EditNote.vue')
|
() => import("@/modules/note/components/EditNote.vue"),
|
||||||
)
|
)
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -50,7 +51,7 @@ const {
|
|||||||
rawContent,
|
rawContent,
|
||||||
getRawContent,
|
getRawContent,
|
||||||
saveCacheNote,
|
saveCacheNote,
|
||||||
getEditedSha
|
getEditedSha,
|
||||||
} = useFile(sha)
|
} = useFile(sha)
|
||||||
const initialRawContent = ref<string | null>(null)
|
const initialRawContent = ref<string | null>(null)
|
||||||
const className = computed(() => `stacked-note-${props.index}`)
|
const className = computed(() => `stacked-note-${props.index}`)
|
||||||
@@ -62,12 +63,12 @@ const store = useUserRepoStore()
|
|||||||
const hasBacklinks = computed(() => store.userSettings?.backlink)
|
const hasBacklinks = computed(() => store.userSettings?.backlink)
|
||||||
|
|
||||||
const { displayNoteOverlay } = useNoteOverlay(className.value, index)
|
const { displayNoteOverlay } = useNoteOverlay(className.value, index)
|
||||||
const displayedTitle = computed(() => filenameToNoteTitle(props.title ?? ''))
|
const displayedTitle = computed(() => filenameToNoteTitle(props.title ?? ""))
|
||||||
const breadcrumbs = computed(() => displayedTitle.value.split(' / '))
|
const breadcrumbs = computed(() => displayedTitle.value.split(" / "))
|
||||||
|
|
||||||
const { updateFile } = useGitHubContent({
|
const { updateFile } = useGitHubContent({
|
||||||
user: user.value,
|
user: user.value,
|
||||||
repo: repo.value
|
repo: repo.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -85,18 +86,21 @@ watch([content, mode], () => {
|
|||||||
listenToClick()
|
listenToClick()
|
||||||
useImages(props.sha)
|
useImages(props.sha)
|
||||||
generateTweets()
|
generateTweets()
|
||||||
|
mermaid.run({
|
||||||
|
querySelector: `.note-${sha.value} .mermaid`,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(mode, async (newMode) => {
|
watch(mode, async (newMode) => {
|
||||||
const hasUserFinishedToEdit =
|
const hasUserFinishedToEdit =
|
||||||
newMode === 'read' && rawContent.value !== initialRawContent.value
|
newMode === "read" && rawContent.value !== initialRawContent.value
|
||||||
|
|
||||||
if (!hasUserFinishedToEdit) {
|
if (!hasUserFinishedToEdit) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!path.value) {
|
if (!path.value) {
|
||||||
console.warn('no path found for this file')
|
console.warn("no path found for this file")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -105,17 +109,17 @@ watch(mode, async (newMode) => {
|
|||||||
const newSha = await updateFile({
|
const newSha = await updateFile({
|
||||||
content: rawContent.value,
|
content: rawContent.value,
|
||||||
path: path.value,
|
path: path.value,
|
||||||
sha: editedSha
|
sha: editedSha,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!newSha) {
|
if (!newSha) {
|
||||||
console.warn('no new SHA found for this file')
|
console.warn("no new SHA found for this file")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await saveCacheNote(encodeUTF8ToBase64(rawContent.value), {
|
await saveCacheNote(encodeUTF8ToBase64(rawContent.value), {
|
||||||
editedSha: newSha
|
editedSha: newSha,
|
||||||
})
|
})
|
||||||
initialRawContent.value = rawContent.value
|
initialRawContent.value = rawContent.value
|
||||||
})
|
})
|
||||||
@@ -127,7 +131,7 @@ watch(mode, async (newMode) => {
|
|||||||
:class="{
|
:class="{
|
||||||
[className]: true,
|
[className]: true,
|
||||||
overlay: displayNoteOverlay,
|
overlay: displayNoteOverlay,
|
||||||
[`note-${sha}`]: true
|
[`note-${sha}`]: true,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
@@ -177,7 +181,7 @@ watch(mode, async (newMode) => {
|
|||||||
v-if="false"
|
v-if="false"
|
||||||
:to="{
|
:to="{
|
||||||
name: 'ShareNotes',
|
name: 'ShareNotes',
|
||||||
params: { user: user, repo: repo, note: sha }
|
params: { user: user, repo: repo, note: sha },
|
||||||
}"
|
}"
|
||||||
class="action"
|
class="action"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user