can edit raw content
This commit is contained in:
6
src/assets/icons/edit.svg
Normal file
6
src/assets/icons/edit.svg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-edit" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3a47" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||||
|
<path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" />
|
||||||
|
<path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
|
||||||
|
<path d="M16 5l3 3" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 466 B |
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, defineAsyncComponent, nextTick, watch } from 'vue'
|
import { computed, defineAsyncComponent, nextTick, ref, watch } from 'vue'
|
||||||
|
|
||||||
import { useFile } from '@/hooks/useFile.hook'
|
import { useFile } from '@/hooks/useFile.hook'
|
||||||
import { useImages } from '@/hooks/useImages.hook'
|
import { useImages } from '@/hooks/useImages.hook'
|
||||||
@@ -29,7 +29,7 @@ const repo = computed(() => props.repo)
|
|||||||
|
|
||||||
const { scrollToFocusedNote } = useRouteQueryStackedNotes()
|
const { scrollToFocusedNote } = useRouteQueryStackedNotes()
|
||||||
|
|
||||||
const { content } = useFile(sha)
|
const { content, rawContent } = useFile(sha)
|
||||||
const className = computed(() => `stacked-note-${props.index}`)
|
const className = computed(() => `stacked-note-${props.index}`)
|
||||||
const { listenToClick } = useLinks(className.value, sha)
|
const { listenToClick } = useLinks(className.value, sha)
|
||||||
const titleClassName = computed(() => `title-${className.value}`)
|
const titleClassName = computed(() => `title-${className.value}`)
|
||||||
@@ -41,6 +41,11 @@ 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 mode = ref<'read' | 'edit'>('read')
|
||||||
|
const toggleMode = () => {
|
||||||
|
mode.value = mode.value === 'read' ? 'edit' : 'read'
|
||||||
|
}
|
||||||
|
|
||||||
watch(content, () => {
|
watch(content, () => {
|
||||||
if (!content.value) {
|
if (!content.value) {
|
||||||
return
|
return
|
||||||
@@ -64,21 +69,33 @@ watch(content, () => {
|
|||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<div class="title-stacked-note" :class="titleClassName">
|
<div class="title-stacked-note" :class="titleClassName">
|
||||||
<a @click.prevent="scrollToFocusedNote(props.sha)">{{
|
<a @click.prevent="scrollToFocusedNote(props.sha)"
|
||||||
displayedTitle
|
>{{ displayedTitle }}
|
||||||
}}</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="false" class="share">
|
<section class="text-content">
|
||||||
|
<button
|
||||||
|
class="action button is-text"
|
||||||
|
:class="{ 'is-link': mode === 'edit' }"
|
||||||
|
@click="toggleMode"
|
||||||
|
>
|
||||||
|
<img src="@/assets/icons/edit.svg" alt="edit" />
|
||||||
|
</button>
|
||||||
<router-link
|
<router-link
|
||||||
|
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"
|
||||||
>
|
>
|
||||||
<img src="@/assets/icons/share.svg" alt="share" />
|
<img src="@/assets/icons/share.svg" alt="share" />
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
<div v-if="mode === 'edit'" class="edit">
|
||||||
<section class="note-content" v-html="content"></section>
|
<textarea id="" v-model="rawContent" name="raw-content"></textarea>
|
||||||
|
</div>
|
||||||
|
<div v-if="mode === 'read'" class="note-content" v-html="content"></div>
|
||||||
|
</section>
|
||||||
<linked-notes v-if="hasBacklinks && content" :sha="sha" />
|
<linked-notes v-if="hasBacklinks && content" :sha="sha" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -120,7 +137,15 @@ $border-color: rgba(18, 19, 58, 0.2);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.share {
|
.text-content {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
div {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.action {
|
||||||
float: right;
|
float: right;
|
||||||
margin: 0.2rem;
|
margin: 0.2rem;
|
||||||
|
|
||||||
@@ -129,6 +154,14 @@ $border-color: rgba(18, 19, 58, 0.2);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: none;
|
||||||
|
flex: 1;
|
||||||
|
resize: none;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 768px) {
|
@media screen and (max-width: 768px) {
|
||||||
.stacked-note {
|
.stacked-note {
|
||||||
padding: 0 0.5rem 1rem;
|
padding: 0 0.5rem 1rem;
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import { getFileContent } from '@/modules/repo/services/repo'
|
|||||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||||
|
|
||||||
export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||||
const { render } = useMarkdown(toValue(sha))
|
const { render, getRawContent: getRawContentFromFile } = useMarkdown(
|
||||||
|
toValue(sha)
|
||||||
|
)
|
||||||
const store = useUserRepoStore()
|
const store = useUserRepoStore()
|
||||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(toValue(sha))
|
const { getCachedNote, saveCacheNote } = prepareNoteCache(toValue(sha))
|
||||||
const fromCache = ref(false)
|
const fromCache = ref(false)
|
||||||
@@ -14,26 +16,6 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
|||||||
const content = ref('')
|
const content = ref('')
|
||||||
const rawContent = ref('')
|
const rawContent = ref('')
|
||||||
|
|
||||||
const getRawContent = async () => {
|
|
||||||
const fileContent = await getCachedFileContent()
|
|
||||||
if (!fileContent) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content.value = render(fileContent)
|
|
||||||
rawContent.value = fileContent
|
|
||||||
return rawContent.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const getContent = async () => {
|
|
||||||
const fileContent = await getCachedFileContent()
|
|
||||||
if (!fileContent) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content.value = render(fileContent)
|
|
||||||
rawContent.value = fileContent
|
|
||||||
return content.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const getCachedFileContent = async (): Promise<string | null> => {
|
const getCachedFileContent = async (): Promise<string | null> => {
|
||||||
const cachedNote = await getCachedNote()
|
const cachedNote = await getCachedNote()
|
||||||
|
|
||||||
@@ -57,12 +39,32 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
|||||||
return contentFile
|
return contentFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getRawContent = async () => {
|
||||||
|
const fileContent = await getCachedFileContent()
|
||||||
|
if (!fileContent) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rawContent.value = getRawContentFromFile(fileContent)
|
||||||
|
return rawContent.value
|
||||||
|
}
|
||||||
|
|
||||||
|
const getContent = async () => {
|
||||||
|
const fileContent = await getCachedFileContent()
|
||||||
|
if (!fileContent) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
content.value = render(fileContent)
|
||||||
|
return content.value
|
||||||
|
}
|
||||||
|
|
||||||
if (retrieveContent) {
|
if (retrieveContent) {
|
||||||
getContent()
|
getContent()
|
||||||
|
getRawContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
|
rawContent,
|
||||||
getRawContent,
|
getRawContent,
|
||||||
getContent,
|
getContent,
|
||||||
getCachedFileContent,
|
getCachedFileContent,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ const md = new MarkdownIt({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const useMarkdown = (defaultPrefix?: Ref<string> | string) => {
|
export const useMarkdown = (defaultPrefix?: Ref<string> | string) => {
|
||||||
|
const getRawContent = (content: string) => decodeBase64ToUTF8(content)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
toHTML: (content: string) => (content ? md.render(content) : ''),
|
toHTML: (content: string) => (content ? md.render(content) : ''),
|
||||||
render: (content: string, prefix?: string) =>
|
render: (content: string, prefix?: string) =>
|
||||||
@@ -47,6 +49,7 @@ export const useMarkdown = (defaultPrefix?: Ref<string> | string) => {
|
|||||||
? md.render(decodeBase64ToUTF8(content), {
|
? md.render(decodeBase64ToUTF8(content), {
|
||||||
docId: defaultPrefix ? toValue(defaultPrefix) : prefix ?? ''
|
docId: defaultPrefix ? toValue(defaultPrefix) : prefix ?? ''
|
||||||
})
|
})
|
||||||
: ''
|
: '',
|
||||||
|
getRawContent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ export const useSpacedRepetitionCards = () => {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const { getRawContent } = useFile(cardFile.sha, false)
|
const { getContent } = useFile(cardFile.sha, false)
|
||||||
const content = (await getRawContent()) ?? ''
|
const content = (await getContent()) ?? ''
|
||||||
|
|
||||||
const [front, back, references] =
|
const [front, back, references] =
|
||||||
decodeBase64ToUTF8(content).split('___') ?? []
|
decodeBase64ToUTF8(content).split('___') ?? []
|
||||||
|
|||||||
Reference in New Issue
Block a user