@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 ADDED
@@ -0,0 +1,3 @@
1
+ # @dyrected/nuxt
2
+
3
+ This is the nuxt package/app for the Dyrected ecosystem.
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)
@@ -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 };
@@ -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 };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@dyrected/nuxt",
3
+ "configKey": "dyrected",
4
+ "version": "0.0.1"
5
+ }
@@ -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,4 @@
1
+ export declare const useDyrected: () => import("@dyrected/sdk").DyrectedClient;
2
+ export declare const useDyrectedDoc: (collection: string, slug: string, options?: {
3
+ depth?: number;
4
+ }) => Promise<any>;
@@ -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,2 @@
1
+ declare const _default: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<Response>>;
2
+ export default _default;
@@ -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
+ });
@@ -0,0 +1,8 @@
1
+
2
+ import type { } from './module.js'
3
+
4
+
5
+
6
+
7
+
8
+ export type { default } from './module.js'
@@ -0,0 +1,8 @@
1
+
2
+ import type { } from './module'
3
+
4
+
5
+
6
+
7
+
8
+ export type { default } from './module'
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
+ }