Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/devtools-ui-kit/src/components/NNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script setup lang='ts'>
import { ref } from 'vue'

import type { DevtoolsUiShowNotificationPosition } from '../composables/notification'
import { devtoolsUiProvideNotificationFn } from '../composables/notification'

const show = ref(false)
const icon = ref<string>()
const text = ref<string>()
const classes = ref<string>()
const position = ref<DevtoolsUiShowNotificationPosition>('top-center')

devtoolsUiProvideNotificationFn((data) => {
text.value = data.message
icon.value = data.icon
classes.value = data.classes ?? 'text-primary border-primary'
icon.value = data.icon
show.value = true
position.value = data.position ?? 'top-center'
setTimeout(() => {
show.value = false
}, data.duration ?? 1500)
})
</script>

<template>
<div
fixed left-0 right-0 z-999 text-center
:class="[
{ 'pointer-events-none overflow-hidden': !show },
{ 'top-0': position.startsWith('top') },
{ 'bottom-0': position.startsWith('bottom') },
]"
>
<div flex :style="{ justifyContent: position.includes('right') ? 'right' : position.includes('left') ? 'left' : 'center' }">
<div
border="~ base"
flex="~ inline gap2"
m-3 inline-block items-center rounded px-4 py-1 transition-all duration-300 bg-base
:style="show ? {} : { transform: `translateY(${position.startsWith('top') ? '-' : ''}300%)` }"
:class="[show ? 'shadow' : 'shadow-none', classes]"
>
<div v-if="icon" :class="icon" />
<div>{{ text }}</div>
</div>
</div>
</div>
</template>
17 changes: 17 additions & 0 deletions packages/devtools-ui-kit/src/composables/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let _devtoolsUiShowNotification: typeof devtoolsUiShowNotification

export type DevtoolsUiShowNotificationPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'

export function devtoolsUiShowNotification(data: {
message: string
icon?: string
classes?: string
duration?: number
position?: DevtoolsUiShowNotificationPosition
}) {
_devtoolsUiShowNotification?.(data)
}

export function devtoolsUiProvideNotificationFn(fn: typeof devtoolsUiShowNotification) {
_devtoolsUiShowNotification = fn
}
5 changes: 4 additions & 1 deletion packages/devtools-ui-kit/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'node:url'
import { addComponentsDir, createResolver, defineNuxtModule, installModule } from '@nuxt/kit'
import { addComponentsDir, addImportsDir, createResolver, defineNuxtModule, installModule } from '@nuxt/kit'
import defu from 'defu'
import { extendUnocssOptions } from './unocss'

Expand All @@ -24,6 +24,9 @@ export default defineNuxtModule<ModuleOptions>({
dev: false,
},
async setup(options, nuxt) {
// composables
addImportsDir(rPath('./composables'))

// Standard components
addComponentsDir({ path: rPath('./components') })

Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ registerCommands(() =>
<template>
<div fixed inset-0 h-screen w-screen font-sans>
<NuxtLoadingIndicator />
<Notification />
<NNotification />
<NLoading v-if="waiting">
Connecting....
</NLoading>
Expand Down
14 changes: 7 additions & 7 deletions packages/devtools/client/components/AssetDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ async function saveTextContent() {
}], '')
editDialog.value = false
textContentCounter.value++
showNotification({
devtoolsUiShowNotification({
message: 'Updated',
icon: 'i-carbon-checkmark',
classes: 'text-green',
})
}
catch (error) {
showNotification({
devtoolsUiShowNotification({
message: 'Something went wrong!',
icon: 'i-carbon-warning',
classes: 'text-red',
Expand Down Expand Up @@ -129,14 +129,14 @@ async function deleteAsset() {
await rpc.deleteStaticAsset(await ensureDevAuthToken(), asset.value.filePath)
asset.value = undefined as any
deleteDialog.value = false
showNotification({
devtoolsUiShowNotification({
message: 'Asset deleted',
icon: 'i-carbon-checkmark',
classes: 'text-green',
})
}
catch (error) {
showNotification({
devtoolsUiShowNotification({
message: 'Something went wrong!',
icon: 'i-carbon-warning',
classes: 'text-red',
Expand All @@ -151,7 +151,7 @@ async function renameAsset() {
const oldName = parts.slice(-1)[0].split('.').slice(0, -1).join('.')

if (!newName.value || newName.value === oldName) {
return showNotification({
return devtoolsUiShowNotification({
message: 'Please enter a new name',
icon: 'i-carbon-warning',
classes: 'text-orange',
Expand All @@ -164,14 +164,14 @@ async function renameAsset() {
await rpc.renameStaticAsset(await ensureDevAuthToken(), asset.value.filePath, fullPath)
asset.value = undefined as any
renameDialog.value = false
showNotification({
devtoolsUiShowNotification({
message: 'Asset renamed',
icon: 'i-carbon-checkmark',
classes: 'text-green',
})
}
catch (error) {
showNotification({
devtoolsUiShowNotification({
message: 'Something went wrong!',
icon: 'i-carbon-warning',
classes: 'text-red',
Expand Down
8 changes: 4 additions & 4 deletions packages/devtools/client/components/AssetDropZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function setFiles(data: FileList | null) {
}
else {
if (file.type === '') {
showNotification({
devtoolsUiShowNotification({
message: 'Folders are not supported yet',
icon: 'carbon:face-dissatisfied',
classes: 'text-orange',
Expand All @@ -61,7 +61,7 @@ function setFiles(data: FileList | null) {
newFiles.push(file)
}
else {
showNotification({
devtoolsUiShowNotification({
message: `"${file.type}" file type is not allowed`,
icon: 'carbon:face-dissatisfied',
classes: 'text-orange',
Expand Down Expand Up @@ -96,14 +96,14 @@ async function uploadFiles() {
}
await rpc.writeStaticAssets(await ensureDevAuthToken(), [...uploadFiles], props.folder).then(() => {
close()
showNotification({
devtoolsUiShowNotification({
message: 'Files uploaded successfully!',
icon: 'i-carbon:checkmark',
})
}).catch((error) => {
console.error(error)
close()
showNotification({
devtoolsUiShowNotification({
message: `Error uploading files: ${error}`,
icon: 'i-carbon-warning',
classes: 'text-red',
Expand Down
34 changes: 0 additions & 34 deletions packages/devtools/client/components/Notification.vue

This file was deleted.

4 changes: 2 additions & 2 deletions packages/devtools/client/composables/dev-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function ensureDevAuthToken() {
isDevAuthed.value = await rpc.verifyAuthToken(devAuthToken.value!)
if (!isDevAuthed.value) {
devAuthToken.value = null
showNotification({
devtoolsUiShowNotification({
message: 'Invalid auth token, action canceled',
icon: 'i-carbon-warning-alt',
classes: 'text-red',
Expand Down Expand Up @@ -74,7 +74,7 @@ async function authConfirmAction() {

if (result === false) {
// @unocss-include
showNotification({
devtoolsUiShowNotification({
message: 'Action canceled',
icon: 'carbon-close',
classes: 'text-orange',
Expand Down
15 changes: 0 additions & 15 deletions packages/devtools/client/composables/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,3 @@ interface RestartDialog {
export function useRestartDialogs() {
return useState<RestartDialog[]>('devtools:restart-dialogs', () => [])
}

let _showNotification: typeof showNotification

export function showNotification(data: {
message: string
icon?: string
classes?: string
duration?: number
}) {
_showNotification?.(data)
}

export function provideNotificationFn(fn: typeof showNotification) {
_showNotification = fn
}
2 changes: 1 addition & 1 deletion packages/devtools/client/composables/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useCopy() {
return (text: string) => {
clipboard.copy(text)

showNotification({
devtoolsUiShowNotification({
message: 'Copied to clipboard',
icon: 'carbon-checkmark',
})
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/pages/modules/timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function showPopup() {
await rpc.enableTimeline(false)
}
catch {
showNotification({
devtoolsUiShowNotification({
message: 'Failed to enable timeline automatically. Check the terminal for more details.',
icon: 'i-carbon-warning',
classes: 'text-red',
Expand Down