@dyrected/nuxt 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.d.ts +15 -0
- package/dist/module.json +5 -0
- package/dist/module.mjs +31 -0
- package/dist/runtime/components/DyrectedImage.vue +29 -0
- package/dist/runtime/components/DyrectedMedia.vue +68 -0
- package/dist/runtime/composables/useDyrected.d.ts +4 -0
- package/dist/runtime/composables/useDyrected.mjs +13 -0
- package/dist/runtime/server/handler.d.ts +2 -0
- package/dist/runtime/server/handler.mjs +8 -0
- package/dist/types.d.mts +8 -0
- package/dist/types.d.ts +8 -0
- package/package.json +28 -0
package/README.md
ADDED
package/dist/module.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DyrectedConfig } from '@dyrected/core';
|
|
2
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
3
|
+
|
|
4
|
+
interface ModuleOptions extends DyrectedConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Mount the Dyrected API on this path.
|
|
7
|
+
* @default '/api/dyrected'
|
|
8
|
+
*/
|
|
9
|
+
apiBase?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare const module: NuxtModule<ModuleOptions>;
|
|
13
|
+
|
|
14
|
+
export { module as default };
|
|
15
|
+
export type { ModuleOptions };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DyrectedConfig } from '@dyrected/core';
|
|
2
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
3
|
+
|
|
4
|
+
interface ModuleOptions extends DyrectedConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Mount the Dyrected API on this path.
|
|
7
|
+
* @default '/api/dyrected'
|
|
8
|
+
*/
|
|
9
|
+
apiBase?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare const module: NuxtModule<ModuleOptions>;
|
|
13
|
+
|
|
14
|
+
export { module as default };
|
|
15
|
+
export type { ModuleOptions };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, addComponent, addImports } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@dyrected/nuxt",
|
|
6
|
+
configKey: "dyrected"
|
|
7
|
+
},
|
|
8
|
+
defaults: {
|
|
9
|
+
apiBase: "/api/dyrected"
|
|
10
|
+
},
|
|
11
|
+
setup(options, nuxt) {
|
|
12
|
+
const resolver = createResolver(import.meta.url);
|
|
13
|
+
addServerHandler({
|
|
14
|
+
route: `${options.apiBase}/**`,
|
|
15
|
+
handler: resolver.resolve("./runtime/server/handler")
|
|
16
|
+
});
|
|
17
|
+
addComponent({
|
|
18
|
+
name: "DyrectedMedia",
|
|
19
|
+
filePath: resolver.resolve("./runtime/components/DyrectedMedia.vue")
|
|
20
|
+
});
|
|
21
|
+
addImports([
|
|
22
|
+
{ name: "useDyrected", from: resolver.resolve("./runtime/composables/useDyrected") },
|
|
23
|
+
{ name: "useDyrectedDoc", from: resolver.resolve("./runtime/composables/useDyrected") }
|
|
24
|
+
]);
|
|
25
|
+
nuxt.options.runtimeConfig.public.dyrected = {
|
|
26
|
+
baseUrl: options.apiBase
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export { module as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<img
|
|
3
|
+
v-if="typeof media === 'string'"
|
|
4
|
+
:src="media"
|
|
5
|
+
:width="width || 500"
|
|
6
|
+
:height="height || 500"
|
|
7
|
+
:alt="alt || ''"
|
|
8
|
+
v-bind="$attrs"
|
|
9
|
+
/>
|
|
10
|
+
<img
|
|
11
|
+
v-else
|
|
12
|
+
:src="media.url"
|
|
13
|
+
:width="width || media.width || 500"
|
|
14
|
+
:height="height || media.height || 500"
|
|
15
|
+
:alt="alt || media.filename"
|
|
16
|
+
v-bind="$attrs"
|
|
17
|
+
/>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import type { Media } from '@dyrected/sdk';
|
|
22
|
+
|
|
23
|
+
defineProps<{
|
|
24
|
+
media: Media | string;
|
|
25
|
+
width?: number | string;
|
|
26
|
+
height?: number | string;
|
|
27
|
+
alt?: string;
|
|
28
|
+
}>();
|
|
29
|
+
</script>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="youtubeId" class="dyrected-media-video" style="position: relative; padding-bottom: 56.25%; height: 0;">
|
|
3
|
+
<iframe
|
|
4
|
+
:src="`https://www.youtube.com/embed/${youtubeId}`"
|
|
5
|
+
frameborder="0"
|
|
6
|
+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
7
|
+
allowfullscreen
|
|
8
|
+
style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
|
|
9
|
+
/>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<img
|
|
13
|
+
v-else-if="isImage"
|
|
14
|
+
:src="url"
|
|
15
|
+
:width="width || 500"
|
|
16
|
+
:height="height || 500"
|
|
17
|
+
:alt="alt || filename"
|
|
18
|
+
v-bind="$attrs"
|
|
19
|
+
/>
|
|
20
|
+
|
|
21
|
+
<video
|
|
22
|
+
v-else-if="isVideo"
|
|
23
|
+
:src="url"
|
|
24
|
+
controls
|
|
25
|
+
:width="width || 500"
|
|
26
|
+
:height="height || 500"
|
|
27
|
+
class="dyrected-media-video"
|
|
28
|
+
v-bind="$attrs"
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
<div v-else class="dyrected-media-file">
|
|
32
|
+
<slot name="fallback">
|
|
33
|
+
<a :href="url" target="_blank" rel="noopener noreferrer" class="dyrected-file-link">
|
|
34
|
+
Download {{ filename || 'File' }}
|
|
35
|
+
</a>
|
|
36
|
+
</slot>
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script setup lang="ts">
|
|
41
|
+
import { computed } from 'vue';
|
|
42
|
+
import type { Media } from '@dyrected/sdk';
|
|
43
|
+
|
|
44
|
+
const props = defineProps<{
|
|
45
|
+
media: Media | string;
|
|
46
|
+
width?: number | string;
|
|
47
|
+
height?: number | string;
|
|
48
|
+
alt?: string;
|
|
49
|
+
}>();
|
|
50
|
+
|
|
51
|
+
const url = computed(() => typeof props.media === 'string' ? props.media : props.media.url);
|
|
52
|
+
const filename = computed(() => typeof props.media === 'string' ? '' : props.media.filename);
|
|
53
|
+
const mimeType = computed(() => typeof props.media === 'string' ? null : props.media.mimeType);
|
|
54
|
+
|
|
55
|
+
const youtubeId = computed(() => {
|
|
56
|
+
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
|
57
|
+
const match = url.value.match(regExp);
|
|
58
|
+
return (match && match[2].length === 11) ? match[2] : null;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const isImage = computed(() => {
|
|
62
|
+
return mimeType.value?.startsWith('image/') || url.value.match(/\.(jpg|jpeg|png|gif|webp|avif|svg)$/i);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const isVideo = computed(() => {
|
|
66
|
+
return mimeType.value?.startsWith('video/') || url.value.match(/\.(mp4|webm|ogg)$/i);
|
|
67
|
+
});
|
|
68
|
+
</script>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createClient } from "@dyrected/sdk";
|
|
2
|
+
import { useRuntimeConfig } from "#app";
|
|
3
|
+
export const useDyrected = () => {
|
|
4
|
+
const config = useRuntimeConfig().public.dyrected;
|
|
5
|
+
const client = createClient({
|
|
6
|
+
baseUrl: config.baseUrl
|
|
7
|
+
});
|
|
8
|
+
return client;
|
|
9
|
+
};
|
|
10
|
+
export const useDyrectedDoc = (collection, slug, options) => {
|
|
11
|
+
const client = useDyrected();
|
|
12
|
+
return client.collection(collection).findOne(slug, options);
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { eventHandler, toRequest } from "h3";
|
|
2
|
+
import { createDyrectedApp } from "@dyrected/core";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
export default eventHandler(async (event) => {
|
|
5
|
+
const config = useRuntimeConfig().dyrected;
|
|
6
|
+
const app = createDyrectedApp(config);
|
|
7
|
+
return app.fetch(toRequest(event.req));
|
|
8
|
+
});
|
package/dist/types.d.mts
ADDED
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dyrected/nuxt",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/module.mjs",
|
|
6
|
+
"types": "./dist/module.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@nuxt/kit": "^3.11.2",
|
|
12
|
+
"h3": "2.0.1-rc.22",
|
|
13
|
+
"@dyrected/core": "0.0.1",
|
|
14
|
+
"@dyrected/sdk": "0.0.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@nuxt/module-builder": "^0.5.5",
|
|
18
|
+
"@nuxt/schema": "^3.11.2",
|
|
19
|
+
"@types/react": "^18.3.28",
|
|
20
|
+
"@types/react-dom": "^19.2.3",
|
|
21
|
+
"nuxt": "^3.11.2",
|
|
22
|
+
"vue": "^3.5.34"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "nuxt-module-build build",
|
|
26
|
+
"dev": "nuxt-module-build build --watch"
|
|
27
|
+
}
|
|
28
|
+
}
|