@dyrected/next 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/components/DyrectedImage.d.ts +13 -0
- package/dist/components/DyrectedImage.d.ts.map +1 -0
- package/dist/components/DyrectedImage.js +12 -0
- package/dist/components/DyrectedImage.js.map +1 -0
- package/dist/components/DyrectedMedia.d.ts +13 -0
- package/dist/components/DyrectedMedia.d.ts.map +1 -0
- package/dist/components/DyrectedMedia.js +28 -0
- package/dist/components/DyrectedMedia.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageProps } from 'next/image';
|
|
3
|
+
import { Media } from '@dyrected/sdk';
|
|
4
|
+
export interface DyrectedImageProps extends Omit<ImageProps, 'src' | 'width' | 'height'> {
|
|
5
|
+
media: Media | string;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A wrapper around next/image that handles Dyrected Media objects.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DyrectedImage: React.FC<DyrectedImageProps>;
|
|
13
|
+
//# sourceMappingURL=DyrectedImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DyrectedImage.d.ts","sourceRoot":"","sources":["../../src/components/DyrectedImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,UAAU,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACtF,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA4BtD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Image from 'next/image';
|
|
3
|
+
/**
|
|
4
|
+
* A wrapper around next/image that handles Dyrected Media objects.
|
|
5
|
+
*/
|
|
6
|
+
export const DyrectedImage = ({ media, width, height, alt, ...props }) => {
|
|
7
|
+
if (typeof media === 'string') {
|
|
8
|
+
return (_jsx(Image, { src: media, width: width || 500, height: height || 500, alt: alt || '', ...props }));
|
|
9
|
+
}
|
|
10
|
+
return (_jsx(Image, { src: media.url, width: width || media.width || 500, height: height || media.height || 500, alt: alt || media.filename, ...props }));
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=DyrectedImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DyrectedImage.js","sourceRoot":"","sources":["../../src/components/DyrectedImage.tsx"],"names":[],"mappings":";AACA,OAAO,KAAqB,MAAM,YAAY,CAAC;AAS/C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAiC,CAAC,EAC1D,KAAK,EACL,KAAK,EACL,MAAM,EACN,GAAG,EACH,GAAG,KAAK,EACT,EAAE,EAAE;IACH,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,CACL,KAAC,KAAK,IACJ,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,IAAI,GAAG,EACnB,MAAM,EAAE,MAAM,IAAI,GAAG,EACrB,GAAG,EAAE,GAAG,IAAI,EAAE,KACV,KAAK,GACT,CACH,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,KAAK,IACJ,GAAG,EAAE,KAAK,CAAC,GAAG,EACd,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,KAAK,IAAI,GAAG,EAClC,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EACrC,GAAG,EAAE,GAAG,IAAI,KAAK,CAAC,QAAQ,KACtB,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageProps } from 'next/image';
|
|
3
|
+
import { Media } from '@dyrected/sdk';
|
|
4
|
+
export interface DyrectedMediaProps extends Partial<Omit<ImageProps, 'src' | 'alt'>> {
|
|
5
|
+
media: Media | string;
|
|
6
|
+
alt?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Fallback icon/component for non-visual media (PDFs, etc.)
|
|
9
|
+
*/
|
|
10
|
+
fallback?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const DyrectedMedia: React.FC<DyrectedMediaProps>;
|
|
13
|
+
//# sourceMappingURL=DyrectedMedia.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DyrectedMedia.d.ts","sourceRoot":"","sources":["../../src/components/DyrectedMedia.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,WAAW,kBAAmB,SAAQ,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC;IAClF,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAQD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAgEtD,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Image from 'next/image';
|
|
3
|
+
const getYouTubeId = (url) => {
|
|
4
|
+
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
|
|
5
|
+
const match = url.match(regExp);
|
|
6
|
+
return (match && match[2].length === 11) ? match[2] : null;
|
|
7
|
+
};
|
|
8
|
+
export const DyrectedMedia = ({ media, alt, width = 500, height = 500, fallback, ...props }) => {
|
|
9
|
+
const url = typeof media === 'string' ? media : media.url;
|
|
10
|
+
const mimeType = typeof media === 'string' ? null : media.mimeType;
|
|
11
|
+
const type = typeof media === 'string' ? 'external' : (media.type || 'upload');
|
|
12
|
+
// 1. Check for YouTube
|
|
13
|
+
const youtubeId = getYouTubeId(url);
|
|
14
|
+
if (youtubeId) {
|
|
15
|
+
return (_jsx("div", { className: "dyrected-media-video", style: { position: 'relative', paddingBottom: '56.25%', height: 0 }, children: _jsx("iframe", { src: `https://www.youtube.com/embed/${youtubeId}`, frameBorder: "0", allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture", allowFullScreen: true, style: { position: 'absolute', top: 0, left: 0, width: '100%', height: '100%' } }) }));
|
|
16
|
+
}
|
|
17
|
+
// 2. Check for Images
|
|
18
|
+
if (mimeType?.startsWith('image/') || url.match(/\.(jpg|jpeg|png|gif|webp|avif|svg)$/i)) {
|
|
19
|
+
return (_jsx(Image, { src: url, alt: alt || (typeof media !== 'string' ? media.filename : ''), width: Number(width), height: Number(height), ...props }));
|
|
20
|
+
}
|
|
21
|
+
// 3. Check for Video uploads
|
|
22
|
+
if (mimeType?.startsWith('video/') || url.match(/\.(mp4|webm|ogg)$/i)) {
|
|
23
|
+
return (_jsx("video", { src: url, controls: true, width: width, height: height, className: "dyrected-media-video" }));
|
|
24
|
+
}
|
|
25
|
+
// 4. Fallback for Documents (PDF, ZIP, etc.)
|
|
26
|
+
return (_jsx("div", { className: "dyrected-media-file", children: fallback || (_jsxs("a", { href: url, target: "_blank", rel: "noopener noreferrer", className: "dyrected-file-link", children: ["Download ", typeof media !== 'string' ? media.filename : 'File'] })) }));
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=DyrectedMedia.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DyrectedMedia.js","sourceRoot":"","sources":["../../src/components/DyrectedMedia.tsx"],"names":[],"mappings":";AACA,OAAO,KAAqB,MAAM,YAAY,CAAC;AAY/C,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE;IACnC,MAAM,MAAM,GAAG,iEAAiE,CAAC;IACjF,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAiC,CAAC,EAC1D,KAAK,EACL,GAAG,EACH,KAAK,GAAG,GAAG,EACX,MAAM,GAAG,GAAG,EACZ,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;IAC1D,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;IACnE,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,QA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IACJ,CAAC;IAED,6CAA6C;IAC7C,OAAO,CACL,cAAK,SAAS,EAAC,qBAAqB,YACjC,QAAQ,IAAI,CACX,aAAG,IAAI,EAAE,GAAG,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,qBAAqB,EAAC,SAAS,EAAC,oBAAoB,0BAC1E,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,IAC3D,CACL,GACG,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DyrectedConfig } from '@dyrected/core';
|
|
2
|
+
import { DyrectedClient } from '@dyrected/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a standard Next.js Route Handler for Dyrected CMS.
|
|
5
|
+
* Usage in app/api/dyrected/[...dyrected]/route.ts:
|
|
6
|
+
*
|
|
7
|
+
* export const { GET, POST, PATCH, DELETE } = dyrectedNextHandler(config);
|
|
8
|
+
*/
|
|
9
|
+
export declare function dyrectedNextHandler(config: DyrectedConfig): {
|
|
10
|
+
GET: (req: Request) => Response | Promise<Response>;
|
|
11
|
+
POST: (req: Request) => Response | Promise<Response>;
|
|
12
|
+
PATCH: (req: Request) => Response | Promise<Response>;
|
|
13
|
+
DELETE: (req: Request) => Response | Promise<Response>;
|
|
14
|
+
PUT: (req: Request) => Response | Promise<Response>;
|
|
15
|
+
OPTIONS: (req: Request) => Response | Promise<Response>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns a pre-configured Dyrected SDK client for server-side use.
|
|
19
|
+
* Reads environment variables DYRECTED_URL and DYRECTED_API_KEY.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getDyrectedClient(): DyrectedClient;
|
|
22
|
+
export * from './components/DyrectedMedia.js';
|
|
23
|
+
export * from '@dyrected/sdk';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAgB,cAAc,EAAE,MAAM,eAAe,CAAC;AAG7D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc;;;;;;;EAazD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAQlD;AAED,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createDyrectedApp } from '@dyrected/core';
|
|
2
|
+
import { createClient } from '@dyrected/sdk';
|
|
3
|
+
import { handle } from 'hono/vercel';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a standard Next.js Route Handler for Dyrected CMS.
|
|
6
|
+
* Usage in app/api/dyrected/[...dyrected]/route.ts:
|
|
7
|
+
*
|
|
8
|
+
* export const { GET, POST, PATCH, DELETE } = dyrectedNextHandler(config);
|
|
9
|
+
*/
|
|
10
|
+
export function dyrectedNextHandler(config) {
|
|
11
|
+
const app = createDyrectedApp(config);
|
|
12
|
+
const handler = handle(app);
|
|
13
|
+
return {
|
|
14
|
+
GET: handler,
|
|
15
|
+
POST: handler,
|
|
16
|
+
PATCH: handler,
|
|
17
|
+
DELETE: handler,
|
|
18
|
+
PUT: handler,
|
|
19
|
+
OPTIONS: handler,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a pre-configured Dyrected SDK client for server-side use.
|
|
24
|
+
* Reads environment variables DYRECTED_URL and DYRECTED_API_KEY.
|
|
25
|
+
*/
|
|
26
|
+
export function getDyrectedClient() {
|
|
27
|
+
const baseUrl = process.env.DYRECTED_URL || 'http://localhost:3000';
|
|
28
|
+
const apiKey = process.env.DYRECTED_API_KEY;
|
|
29
|
+
return createClient({
|
|
30
|
+
baseUrl,
|
|
31
|
+
apiKey,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export * from './components/DyrectedMedia.js';
|
|
35
|
+
export * from '@dyrected/sdk';
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAkB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAsB;IACxD,MAAM,GAAG,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAEtC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAE5B,OAAO;QACL,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,OAAO;QACZ,OAAO,EAAE,OAAO;KACjB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,uBAAuB,CAAC;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAE5C,OAAO,YAAY,CAAC;QAClB,OAAO;QACP,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAED,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dyrected/next",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"next": ">=13.4.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"hono": "^4.0.0",
|
|
15
|
+
"@dyrected/core": "0.0.1",
|
|
16
|
+
"@dyrected/sdk": "0.0.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^20.12.12",
|
|
20
|
+
"@types/react": "^18.3.28",
|
|
21
|
+
"@types/react-dom": "^19.2.3",
|
|
22
|
+
"next": "^14.2.3",
|
|
23
|
+
"typescript": "^5.4.5"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"dev": "tsc --watch"
|
|
28
|
+
}
|
|
29
|
+
}
|