notes search

This commit is contained in:
2023-04-29 14:56:48 +02:00
parent 1d6826e255
commit 4cc7c01365
8 changed files with 87 additions and 27 deletions

42
package-lock.json generated
View File

@@ -20,10 +20,12 @@
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"hamburgers": "^1.2.1", "hamburgers": "^1.2.1",
"marked": "^4.3.0", "marked": "^4.3.0",
"shortid": "^2.2.16",
"vue": "^3.2.47" "vue": "^3.2.47"
}, },
"devDependencies": { "devDependencies": {
"@types/dompurify": "^3.0.2", "@types/dompurify": "^3.0.2",
"@types/shortid": "^0.0.29",
"@vitejs/plugin-vue": "^4.1.0", "@vitejs/plugin-vue": "^4.1.0",
"autoprefixer": "^10.4.14", "autoprefixer": "^10.4.14",
"postcss": "^8.4.23", "postcss": "^8.4.23",
@@ -1140,6 +1142,12 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.1.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.1.tgz",
"integrity": "sha512-DZxSZWXxFfOlx7k7Rv4LAyiMroaxa3Ly/7OOzZO8cBNho0YzAi4qlbrx8W27JGqG57IgR/6J7r+nOJWw6kcvZA==" "integrity": "sha512-DZxSZWXxFfOlx7k7Rv4LAyiMroaxa3Ly/7OOzZO8cBNho0YzAi4qlbrx8W27JGqG57IgR/6J7r+nOJWw6kcvZA=="
}, },
"node_modules/@types/shortid": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/@types/shortid/-/shortid-0.0.29.tgz",
"integrity": "sha512-9BCYD9btg2CY4kPcpMQ+vCR8U6V8f/KvixYD5ZbxoWlkhddNF5IeZMVL3p+QFUkg+Hb+kPAG9Jgk4bnnF1v/Fw==",
"dev": true
},
"node_modules/@types/trusted-types": { "node_modules/@types/trusted-types": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz",
@@ -2767,6 +2775,19 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/shortid": {
"version": "2.2.16",
"resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.16.tgz",
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
"dependencies": {
"nanoid": "^2.1.0"
}
},
"node_modules/shortid/node_modules/nanoid": {
"version": "2.1.11",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz",
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA=="
},
"node_modules/simple-swizzle": { "node_modules/simple-swizzle": {
"version": "0.2.2", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
@@ -3966,6 +3987,12 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.1.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.1.tgz",
"integrity": "sha512-DZxSZWXxFfOlx7k7Rv4LAyiMroaxa3Ly/7OOzZO8cBNho0YzAi4qlbrx8W27JGqG57IgR/6J7r+nOJWw6kcvZA==" "integrity": "sha512-DZxSZWXxFfOlx7k7Rv4LAyiMroaxa3Ly/7OOzZO8cBNho0YzAi4qlbrx8W27JGqG57IgR/6J7r+nOJWw6kcvZA=="
}, },
"@types/shortid": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/@types/shortid/-/shortid-0.0.29.tgz",
"integrity": "sha512-9BCYD9btg2CY4kPcpMQ+vCR8U6V8f/KvixYD5ZbxoWlkhddNF5IeZMVL3p+QFUkg+Hb+kPAG9Jgk4bnnF1v/Fw==",
"dev": true
},
"@types/trusted-types": { "@types/trusted-types": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz", "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz",
@@ -5035,6 +5062,21 @@
"lru-cache": "^6.0.0" "lru-cache": "^6.0.0"
} }
}, },
"shortid": {
"version": "2.2.16",
"resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.16.tgz",
"integrity": "sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==",
"requires": {
"nanoid": "^2.1.0"
},
"dependencies": {
"nanoid": {
"version": "2.1.11",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz",
"integrity": "sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA=="
}
}
},
"simple-swizzle": { "simple-swizzle": {
"version": "0.2.2", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",

View File

@@ -21,10 +21,12 @@
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"hamburgers": "^1.2.1", "hamburgers": "^1.2.1",
"marked": "^4.3.0", "marked": "^4.3.0",
"shortid": "^2.2.16",
"vue": "^3.2.47" "vue": "^3.2.47"
}, },
"devDependencies": { "devDependencies": {
"@types/dompurify": "^3.0.2", "@types/dompurify": "^3.0.2",
"@types/shortid": "^0.0.29",
"@vitejs/plugin-vue": "^4.1.0", "@vitejs/plugin-vue": "^4.1.0",
"autoprefixer": "^10.4.14", "autoprefixer": "^10.4.14",
"postcss": "^8.4.23", "postcss": "^8.4.23",

View File

@@ -28,10 +28,10 @@ const activeViewMode = ref(viewModes[0])
class="mt-[50px] px-3 py-6" class="mt-[50px] px-3 py-6"
/> />
<main <main
class="transition[margin-left] absolute bottom-0 right-0 top-[50px] flex-1 overflow-auto border-x-[1px] bg-white px-10 py-6 duration-200 ease-out" class="transition[margin-left] absolute bottom-0 left-0 right-0 top-[50px] flex overflow-auto border-x-[1px] bg-white px-10 py-6 duration-200 ease-out"
:class="sideBarCollapsed ? 'ml-0' : 'ml-sidebar'" :class="sideBarCollapsed ? 'ml-0' : 'ml-sidebar'"
> >
<Note v-if="activeNote" :note="activeNote" /> <Note v-if="activeNote" :note="activeNote" class="w-full" />
</main> </main>
</div> </div>
</template> </template>

View File

@@ -4,9 +4,14 @@ defineProps<{
}>() }>()
</script> </script>
<template> <template>
<h1 class="flex items-center text-3xl pb-2"> <div>
<i class="bi bi-house mr-2 text-secondary text-base" v-if="note.isRoot"></i <h1 class="flex items-center pb-2 text-3xl">
>{{ note.title }} <i
</h1> class="bi bi-house mr-2 text-base text-secondary"
<div>{{ note.content }}</div> v-if="note.isRoot"
></i
>{{ note.title }}
</h1>
<div>{{ note.content }}</div>
</div>
</template> </template>

View File

@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, computed } from 'vue' import { ref, watch, computed } from 'vue'
import { notes, findNotes } from '@/composables/useNotes' import { notes, findNotes, activeNote } from '@/composables/useNotes'
const active = ref(false) const active = ref(false)
watch(active, () => { watch(active, () => {
@@ -13,7 +13,8 @@ const results = computed<Note[]>(() => {
}) })
const click = (note: Note) => { const click = (note: Note) => {
console.log(note.title) activeNote.value = note
active.value = false
} }
</script> </script>
<template> <template>
@@ -29,20 +30,33 @@ const click = (note: Note) => {
/> />
<div <div
class="z-1000 dropdown absolute left-0 right-0 top-[100%]" class="z-1000 dropdown absolute left-0 right-0 top-[100%]"
v-if="active && results.length > 0" v-if="active"
> >
<ul <ul
tabindex="0" tabindex="0"
class="menu mt-1 w-full rounded-md bg-base-100 p-2 text-black shadow" class="menu mt-1 w-full rounded-md bg-base-100 p-2 text-black shadow"
> >
<li v-for="note in results"> <li
v-for="note in results"
v-if="results.length > 0"
class="flex flex-row"
:class="{ disabled: activeNote?.id === note.id }"
>
<a <a
class="px-2 py-1" class="flex-1 items-center px-2 py-1"
@click.stop.prevent="() => click(note)" @click.stop.prevent="() => click(note)"
@mousedown.prevent @mousedown.prevent
>{{ note.title }}</a :class="{ disabled: activeNote?.id === note.id }"
>
<span
class="badge-ghost badge badge-sm mr-0.5"
v-if="activeNote?.id === note.id"
>current</span
>
{{ note.title }}</a
> >
</li> </li>
<li v-else><a>No notes found</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -25,13 +25,7 @@ watch(
) )
export const setDefaultNotes = (defaultNotes: BaseNote[]) => { export const setDefaultNotes = (defaultNotes: BaseNote[]) => {
baseNotes.value = defaultNotes.map( baseNotes.value = defaultNotes
(note): BaseNote => ({
...note,
created: new Date().getTime(),
modified: new Date().getTime(),
})
)
} }
export const getNoteById = (noteId: string) => { export const getNoteById = (noteId: string) => {
@@ -41,7 +35,7 @@ export const getNoteById = (noteId: string) => {
export const findNotes = (query: string): Note[] => { export const findNotes = (query: string): Note[] => {
const removeMdFromText = (mdText: string): string => { const removeMdFromText = (mdText: string): string => {
const div = document.createElement('div') const div = document.createElement('div')
div.innerHTML = mdToHtml(mdText, 'c@') div.innerHTML = mdToHtml(mdText, 'c@', getNoteById)
const textWithoutMd = div.textContent || div.innerText || '' const textWithoutMd = div.textContent || div.innerText || ''
return textWithoutMd return textWithoutMd
} }

2
src/global.d.ts vendored
View File

@@ -1,6 +1,6 @@
declare global { declare global {
interface BaseNote { interface BaseNote {
id?: string id: string
title: string title: string
content: string content: string
created: number created: number

View File

@@ -1,3 +1,5 @@
import shortid from 'shortid'
export const defaultNotes: BaseNote[] = [ export const defaultNotes: BaseNote[] = [
{ {
isRoot: true, isRoot: true,
@@ -8,13 +10,14 @@ export const defaultNotes: BaseNote[] = [
* Click on **Mindmap mode** in the menu left to visualize your notes * Click on **Mindmap mode** in the menu left to visualize your notes
\n \n
Let's get started!`, Let's get started!`,
created: 0,
modified: 0,
}, },
{ {
title: 'brackets', title: 'brackets',
content: `If you type square brackets around text a link is created automatically. Like magic!`, content: `If you type square brackets around text a link is created automatically. Like magic!`,
created: 0,
modified: 0,
}, },
] ].map((note) => ({
id: shortid.generate(),
created: new Date().getTime(),
modified: new Date().getTime(),
...note,
}))