Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit a7a7be3

Browse files
feat: use devtools ui
1 parent fbd7f9a commit a7a7be3

38 files changed

+623
-383
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
2+
"root": true,
23
"extends": [
34
"@nuxtjs/eslint-config-typescript"
45
],
56
"rules": {
7+
"import/named": "off",
68
"@typescript-eslint/no-unused-vars": [
79
"off"
810
]

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ dist
2222
.vercel_build_output
2323
.build-*
2424
.env
25+
!client/.env
2526
.netlify
2627

27-
# Env
28-
.env
29-
3028
# Testing
3129
reports
3230
coverage

.nuxtrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
imports.autoImport=false
2+
typescript.includeWorkspace=true

client/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NUXT_PUBLIC_MV_BASE_URL=http://localhost:3000/
File renamed without changes.

src/client/components/MediaDropPlaceholder.vue renamed to client/components/MediaDropPlaceholder.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const isDropping = ref(false)
55
// drag file over app handlers, to show drop placeholder
66
// we need to keep track of how deep the drag is because it raises on each child elements
77
let dragCount = 0
8-
function onDragenter (e) {
8+
function onDragenter (e: DragEvent) {
99
dragCount += 1
1010
if (dragCount === 1) {
1111
isDropping.value = true
@@ -63,8 +63,8 @@ onBeforeUnmount(() => {
6363

6464
<template>
6565
<div>
66-
<div v-if="isDropping" class="fixed inset-0 transition-all hover:backdrop-blur-none backdrop-blur-sm bg-white/30" />
67-
<div v-show="isDropping" class="fixed inset-0 my-24 mx-32">
66+
<div v-if="isDropping" class="fixed inset-0 transition-all hover:backdrop-blur-none backdrop-blur-sm bg-base/30" />
67+
<div v-show="isDropping" class="fixed inset-0">
6868
<Transition
6969
enter-active-class="transition duration-100 ease-out"
7070
enter-from-class="transform scale-0 opacity-0"
@@ -74,7 +74,7 @@ onBeforeUnmount(() => {
7474
leave-to-class="transform scale-0 opacity-0"
7575
>
7676
<div v-if="isDropping" class="h-full flex-1 flex items-center justify-center">
77-
<div class="rounded border border-slate-100 drop-shadow-sm flex bg-white items-center justify-center w-[500px] h-[230px] mx-auto">
77+
<div class="rounded border n-border-base drop-shadow-sm flex bg-base items-center justify-center w-[500px] h-[230px] mx-auto">
7878
<div class="text-2xl">
7979
Drop your files
8080
</div>

src/client/components/MediaGallery.vue renamed to client/components/MediaGallery.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const props = defineProps<{
77
</script>
88

99
<template>
10-
<div class="grid grid-cols-3 md:grid-cols-6 lg:grid-cols-12 gap-4">
10+
<div class="flex flex-wrap gap-4">
1111
<MediaGalleryItem
1212
v-for="key in props.assetsKeys"
1313
:key="key"

src/client/components/MediaGalleryItem.vue renamed to client/components/MediaGalleryItem.vue

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<script setup lang="ts">
22
import { inject, onMounted, ref } from 'vue'
3-
import { keyToPath } from '../shared'
4-
import type { AssetStats } from '../../../types/preview'
3+
import { useRuntimeConfig } from '#app'
4+
import type { AssetStats } from '../../types/preview'
5+
import { useKeyPath } from '~/composables/keys'
56
67
const props = defineProps<{
7-
assetKey: string
8+
assetKey: string;
89
}>()
910
1011
const isImage = ref(true)
1112
const fileStat = ref<AssetStats>()
13+
const mvBaseURL = useRuntimeConfig().public.mvBaseURL
1214
const config = inject<any>('mediaViewerConfig')
13-
const src = keyToPath(props.assetKey, config)
15+
const src = useKeyPath(props.assetKey, config)
1416
1517
onMounted(() => {
1618
// check if image loads, the @error.once seems to be cached
@@ -19,17 +21,24 @@ onMounted(() => {
1921
image.onerror = async () => {
2022
image.onerror = null
2123
// @ts-ignore
22-
fileStat.value = await $fetch(`/__media_viewer__/stats?key=${props.assetKey}`, {
23-
baseURL: '/'
24-
})
24+
fileStat.value = await $fetch(
25+
`/__media_viewer/stats?key=${props.assetKey}`,
26+
{
27+
baseURL: mvBaseURL
28+
}
29+
)
2530
isImage.value = false
2631
}
2732
image.src = src.value
2833
})
2934
</script>
3035

3136
<template>
32-
<NuxtLink :key="props.assetKey" :to="`#${props.assetKey}`" class="transition-all prevent-drag hover:scale-150">
37+
<NuxtLink
38+
:key="props.assetKey"
39+
:to="`#${props.assetKey}`"
40+
class="transition-all prevent-drag hover:scale-110"
41+
>
3342
<img
3443
v-if="isImage"
3544
:src="`${src}?h=300`"
@@ -38,9 +47,12 @@ onMounted(() => {
3847
loading="lazy"
3948
decoding="async"
4049
draggable="false"
41-
class="prevent-drag rounded border select-none pointer-events-none border-slate-100 w-[150px] h-[150px] preview bg-white object-scale-down"
50+
class="prevent-drag rounded border select-none pointer-events-none n-border-base w-[150px] h-[150px] preview bg-white object-scale-down"
51+
>
52+
<div
53+
v-else
54+
class="rounded flex flex-col justify-center border select-none pointer-events-none n-border-base w-[150px] h-[150px] preview bg-white object-scale-down"
4255
>
43-
<div v-else class="rounded flex flex-col justify-center border select-none pointer-events-none border-slate-100 w-[150px] h-[150px] preview bg-white object-scale-down">
4456
<div class="truncate w-full text-center">
4557
{{ fileStat?.name }}
4658
</div>
@@ -53,10 +65,17 @@ onMounted(() => {
5365

5466
<style scoped>
5567
.preview {
56-
background-image: repeating-conic-gradient(#f8fafc 0% 25%, transparent 0% 50%);
68+
background-image: repeating-conic-gradient(
69+
#f8fafc 0% 25%,
70+
#ffffff 0% 50%
71+
);
5772
background-size: 15px 15px;
5873
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
5974
}
75+
.dark .preview {
76+
background-image: repeating-conic-gradient(#1c1c1c 0% 25%, #151515 0% 50%);
77+
}
78+
6079
.prevent-drag {
6180
-webkit-user-drag: none;
6281
-khtml-user-drag: none;

src/client/components/MediaPreview.vue renamed to client/components/MediaPreview.vue

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<script setup lang="ts">
22
import { computed, reactive, provide, watchEffect, watch } from 'vue'
33
// @ts-ignore
4-
import { useRoute } from '#app'
4+
import { useRuntimeConfig, useRoute } from '#app'
55
6-
import type { PreviewState } from '../../../types/preview'
7-
import { vFocus, generateSnippet } from '../shared'
6+
import type { PreviewState } from '../../types/preview'
87
import MediaPreviewImage from './MediaPreviewImage.vue'
98
import MediaPreviewStats from './MediaPreviewStats.vue'
9+
import { generateSnippet } from '~~/utils/snippets'
10+
import { vFocus } from '~~/utils/directives'
1011
1112
// keep track of the current image in hash so we can use the history
1213
const route = useRoute()
1314
const selectedAssetKey = computed(() => route.hash ? route.hash.substring(1) : '')
15+
const mvBaseURL = useRuntimeConfig().public.mvBaseURL
1416
1517
// provide state to childs
1618
const previewState = reactive({
@@ -32,8 +34,8 @@ watchEffect(async () => {
3234
}
3335
3436
// @ts-ignore
35-
previewState.stats = await $fetch(`/__media_viewer__/stats?key=${selectedAssetKey.value}`, {
36-
baseURL: '/'
37+
previewState.stats = await $fetch(`/__media_viewer/stats?key=${selectedAssetKey.value}`, {
38+
baseURL: mvBaseURL
3739
})
3840
3941
// reset preview state
@@ -54,11 +56,6 @@ watch(previewState, () => {
5456
5557
// prevent gallery scrolling when preview modal is open
5658
watchEffect(() => {
57-
// @ts-ignore
58-
if (process.server) {
59-
return
60-
}
61-
6259
if (selectedAssetKey.value) {
6360
document.documentElement.classList.add('overflow-hidden')
6461
} else {
@@ -68,9 +65,8 @@ watchEffect(() => {
6865
</script>
6966

7067
<template>
71-
<ClientOnly>
72-
<NuxtLink v-if="selectedAssetKey" to="/" class="fixed inset-0 transition-all hover:backdrop-blur-none backdrop-blur-sm bg-white/30" />
73-
<div v-show="selectedAssetKey" class="fixed inset-0 my-24 mx-32">
68+
<div>
69+
<div v-show="selectedAssetKey" class="fixed inset-0">
7470
<Transition
7571
enter-active-class="transition duration-100 ease-out"
7672
enter-from-class="transform scale-0 opacity-0"
@@ -79,13 +75,13 @@ watchEffect(() => {
7975
leave-from-class="transform scale-1 opacity-100"
8076
leave-to-class="transform scale-0 opacity-0"
8177
>
82-
<div v-if="selectedAssetKey" v-focus tabindex="0" class="rounded border border-slate-100 drop-shadow-sm flex flex-1 relative bg-white h-full items-center justify-center">
78+
<div v-if="selectedAssetKey" v-focus tabindex="0" class="rounded border n-border-base drop-shadow-sm flex flex-1 relative n-bg-base h-full items-center justify-center">
8379
<div class="rounded flex flex-1 h-full w-full">
84-
<MediaPreviewImage :selected-asset-key="selectedAssetKey" />
85-
<MediaPreviewStats :selected-asset-key="selectedAssetKey" />
80+
<MediaPreviewImage class="w-6/12 md:w-7/12 lg:w-8/12" :selected-asset-key="selectedAssetKey" />
81+
<MediaPreviewStats class="w-6/12 md:w-5/12 lg:w-4/12" :selected-asset-key="selectedAssetKey" />
8682
</div>
8783
</div>
8884
</Transition>
8985
</div>
90-
</ClientOnly>
86+
</div>
9187
</template>

src/client/components/MediaPreviewImage.vue renamed to client/components/MediaPreviewImage.vue

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { ref, computed, inject, watchEffect, onBeforeUnmount, watch } from 'vue'
33
// @ts-ignore
44
import { useRoute } from '#app'
5-
import { keyToPath } from '../shared'
6-
import type { PreviewState } from '../../../types/preview'
5+
import type { PreviewState } from '../../types/preview'
6+
import { useKeyPath } from '~~/composables/keys'
77
88
const route = useRoute()
99
@@ -12,7 +12,7 @@ const mode = ref<'scale' | 'real'>('scale')
1212
const config = inject<any>('mediaViewerConfig')
1313
1414
const selectedAssetKey = computed(() => route.hash ? route.hash.substring(1) : '')
15-
const selectedAssetSrc = keyToPath(selectedAssetKey, config)
15+
const selectedAssetSrc = useKeyPath(selectedAssetKey, config)
1616
1717
const previewState = inject<PreviewState>('previewState')
1818
const isImage = computed(() => previewState?.stats?.mimetype?.startsWith('image/'))
@@ -64,8 +64,8 @@ watch(mode, () => {
6464
</script>
6565

6666
<template>
67-
<div class="relative overflow-hidden rounded-l border-slate-100 border-r preview w-7/12 flex items-center justify-center">
68-
<div v-if="!isImage" class="rounded flex flex-col justify-center border select-none pointer-events-none border-slate-100 w-[150px] h-[150px] bg-white object-scale-down">
67+
<div class="relative overflow-hidden rounded-l n-border-base border-r preview flex items-center justify-center">
68+
<div v-if="!isImage" class="rounded flex flex-col justify-center border select-none pointer-events-none n-border-base w-[150px] h-[150px] n-bg-base object-scale-down">
6969
<div class="truncate w-full text-center">
7070
{{ previewState?.stats?.name }}
7171
</div>
@@ -92,41 +92,44 @@ watch(mode, () => {
9292
class="prevent-drag block object-scale-down w-full max-w-full max-h-full"
9393
tabindex="0"
9494
>
95-
<div class="absolute right-6 top-6 flex gap-2">
95+
<div class="absolute left-4 right-4 top-4 flex justify-between gap-2">
96+
<NButton
97+
to="/"
98+
icon="carbon:arrow-left"
99+
class="n-bg-base"
100+
>
101+
<span>Back</span>
102+
</NButton>
96103
<div>
97-
<button
98-
type="button"
99-
class=" text-sm py-1 px-3 rounded-l border-r-0 border border-slate-100 disabled:opacity-60 disabled:cursor-not-allowed active:hover:bg-indigo-400 active:hover:text-white"
104+
<NButton
100105
:class="[
101-
mode === 'scale' && 'bg-indigo-400 text-white',
102-
mode !== 'scale' && 'bg-white',
106+
mode === 'scale' ? 'bg-primary' : 'n-bg-base',
103107
]"
108+
class="border-r-0 rounded-r-none"
104109
:disabled="!isImage"
105110
@click="mode = 'scale'"
106111
>
107112
Overview
108-
</button>
109-
<button
110-
type="button"
111-
class=" text-sm py-1 px-3 rounded-r bg-white border border-slate-100 disabled:opacity-60 disabled:cursor-not-allowed active:hover:bg-indigo-400 active:hover:text-white"
113+
</NButton>
114+
<NButton
112115
:class="[
113-
mode === 'real' && 'bg-indigo-400 text-white',
114-
mode !== 'real' && 'bg-white',
116+
mode === 'real' ? 'bg-primary' : 'n-bg-base',
115117
]"
118+
class="border-l-0 rounded-l-none"
116119
:disabled="!isImage"
117120
@click="mode = 'real'"
118121
>
119-
Realtime preview
120-
</button>
122+
Real-size preview
123+
</NButton>
121124
</div>
122125

123-
<a
124-
:href="selectedAssetSrc"
125-
class=" text-sm py-1 px-3 rounded bg-white border border-slate-100 hover:bg-indigo-400 hover:text-white"
126+
<NButton
127+
:to="selectedAssetSrc"
126128
target="_blank"
129+
class="n-bg-base"
127130
>
128131
Open in new tab
129-
</a>
132+
</NButton>
130133
</div>
131134
</div>
132135
</template>
@@ -137,6 +140,9 @@ watch(mode, () => {
137140
background-size: 20px 20px;
138141
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
139142
}
143+
.dark .preview {
144+
background-image: repeating-conic-gradient(#1c1c1c 0% 25%, #151515 0% 50%);
145+
}
140146
.prevent-drag, .prevent-drag:deep(*) {
141147
-webkit-user-drag: none;
142148
-khtml-user-drag: none;

0 commit comments

Comments
 (0)