@okam/directus-next-component 1.1.1 → 1.3.0
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/components/DirectusFile/config.d.ts +4 -0
- package/components/DirectusFile/config.js +8 -0
- package/components/DirectusFile/config.mjs +9 -0
- package/components/DirectusFile/index.d.ts +3 -0
- package/components/DirectusFile/index.js +13 -0
- package/components/DirectusFile/index.mjs +14 -0
- package/components/DirectusFile/interface.d.ts +11 -0
- package/components/DirectusImg/index.d.ts +3 -0
- package/components/DirectusImg/index.js +25 -0
- package/components/DirectusImg/index.mjs +26 -0
- package/components/DirectusImg/interface.d.ts +4 -0
- package/components/DirectusLink/index.d.ts +3 -0
- package/components/DirectusLink/index.js +14 -0
- package/components/DirectusLink/index.mjs +15 -0
- package/components/DirectusLink/interface.d.ts +13 -0
- package/components/DirectusVideo/index.d.ts +3 -0
- package/components/DirectusVideo/index.js +12 -0
- package/components/DirectusVideo/index.mjs +13 -0
- package/components/DirectusVideo/interface.d.ts +5 -0
- package/hooks/directus-file.d.ts +24 -0
- package/hooks/directus-file.js +40 -0
- package/hooks/directus-file.mjs +41 -0
- package/hooks/directus-link.d.ts +3 -0
- package/hooks/directus-link.js +82 -0
- package/hooks/directus-link.mjs +83 -0
- package/hooks/navigation-items.d.ts +10 -0
- package/hooks/navigation-items.js +58 -0
- package/hooks/navigation-items.mjs +59 -0
- package/index.d.ts +12 -0
- package/index.js +16 -0
- package/index.mjs +16 -0
- package/lib/directus-next-rewrite.js +87 -0
- package/lib/directus-next-rewrite.mjs +87 -0
- package/lib/withDirectus.js +12 -0
- package/lib/withDirectus.mjs +13 -0
- package/package.json +20 -5
- package/server.d.ts +9 -0
- package/server.js +22 -0
- package/server.mjs +22 -0
- package/types/files.d.ts +24 -0
- package/types/links.d.ts +18 -0
- package/types/navigation-items.d.ts +31 -0
- package/types/page-settings.d.ts +17 -0
- package/README.md +0 -29
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -1
- package/src/index.d.ts +0 -0
- package/src/lib/hello-server.d.ts +0 -1
- package/src/server.d.ts +0 -3
- /package/{src/lib → lib}/directus-next-rewrite.d.ts +0 -0
- /package/{src/lib → lib}/withDirectus.d.ts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const config = require("./config.js");
|
|
4
|
+
const DirectusFile = (props) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const { type, ...rest } = props;
|
|
7
|
+
const fileType = (_a = type == null ? void 0 : type.split("/")) == null ? void 0 : _a[0];
|
|
8
|
+
const configComponent = config[fileType ?? ""];
|
|
9
|
+
const { as: Component = configComponent } = props;
|
|
10
|
+
if (!Component) return null;
|
|
11
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...rest });
|
|
12
|
+
};
|
|
13
|
+
module.exports = DirectusFile;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import directusFileConfig from "./config.mjs";
|
|
3
|
+
const DirectusFile = (props) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const { type, ...rest } = props;
|
|
6
|
+
const fileType = (_a = type == null ? void 0 : type.split("/")) == null ? void 0 : _a[0];
|
|
7
|
+
const configComponent = directusFileConfig[fileType ?? ""];
|
|
8
|
+
const { as: Component = configComponent } = props;
|
|
9
|
+
if (!Component) return null;
|
|
10
|
+
return /* @__PURE__ */ jsx(Component, { ...rest });
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
DirectusFile as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TDefaultComponent } from '@okam/stack-ui';
|
|
2
|
+
import type { TFiles } from '../../types/files';
|
|
3
|
+
export interface TDirectusFileProps extends TFiles, TDefaultComponent {
|
|
4
|
+
/**
|
|
5
|
+
* Serves to fall back to different parts of the URLs. Some properties have default values:
|
|
6
|
+
* - hostname: `NEXT_PUBLIC_IMG_DOMAIN`
|
|
7
|
+
* - port: `NEXT_PUBLIC_IMG_PORT`
|
|
8
|
+
* - protocol: `NEXT_PUBLIC_IMG_PROTOCOL`
|
|
9
|
+
*/
|
|
10
|
+
baseUrl?: URL;
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const nextComponent = require("@okam/next-component");
|
|
4
|
+
const thumbhash = require("unlazy/thumbhash");
|
|
5
|
+
const directusFile = require("../../hooks/directus-file.js");
|
|
6
|
+
const DirectusImg = (props) => {
|
|
7
|
+
const { fit, baseUrl, focal_point_x: focalPointX, focal_point_y: focalPointY, thumbhash: thumbhash$1, width, height } = props;
|
|
8
|
+
const fileProps = directusFile(props, baseUrl, { fit });
|
|
9
|
+
if (!fileProps) return null;
|
|
10
|
+
const hasFocalPoint = !!focalPointX && !!focalPointY && !!width && !!height;
|
|
11
|
+
const style = hasFocalPoint ? {
|
|
12
|
+
objectFit: "cover",
|
|
13
|
+
objectPosition: `${focalPointX / width * 100}% ${focalPointY / height * 100}%`
|
|
14
|
+
} : void 0;
|
|
15
|
+
if (!fileProps) return null;
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
17
|
+
nextComponent.Img,
|
|
18
|
+
{
|
|
19
|
+
style,
|
|
20
|
+
...thumbhash$1 ? { blurDataURL: thumbhash.createPngDataUri(thumbhash$1), placeholder: "blur" } : {},
|
|
21
|
+
...fileProps
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
module.exports = DirectusImg;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Img } from "@okam/next-component";
|
|
3
|
+
import { createPngDataUri } from "unlazy/thumbhash";
|
|
4
|
+
import useDirectusFile from "../../hooks/directus-file.mjs";
|
|
5
|
+
const DirectusImg = (props) => {
|
|
6
|
+
const { fit, baseUrl, focal_point_x: focalPointX, focal_point_y: focalPointY, thumbhash, width, height } = props;
|
|
7
|
+
const fileProps = useDirectusFile(props, baseUrl, { fit });
|
|
8
|
+
if (!fileProps) return null;
|
|
9
|
+
const hasFocalPoint = !!focalPointX && !!focalPointY && !!width && !!height;
|
|
10
|
+
const style = hasFocalPoint ? {
|
|
11
|
+
objectFit: "cover",
|
|
12
|
+
objectPosition: `${focalPointX / width * 100}% ${focalPointY / height * 100}%`
|
|
13
|
+
} : void 0;
|
|
14
|
+
if (!fileProps) return null;
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
Img,
|
|
17
|
+
{
|
|
18
|
+
style,
|
|
19
|
+
...thumbhash ? { blurDataURL: createPngDataUri(thumbhash), placeholder: "blur" } : {},
|
|
20
|
+
...fileProps
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
DirectusImg as default
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const stackUi = require("@okam/stack-ui");
|
|
4
|
+
const directusLink = require("../../hooks/directus-link.js");
|
|
5
|
+
const DirectusLink = (props) => {
|
|
6
|
+
const { type, componentsConfig } = props;
|
|
7
|
+
const linkProps = directusLink(props);
|
|
8
|
+
if (!type) return null;
|
|
9
|
+
const LinkComponent = componentsConfig == null ? void 0 : componentsConfig[type];
|
|
10
|
+
if (LinkComponent) return /* @__PURE__ */ jsxRuntime.jsx(LinkComponent, { ...props });
|
|
11
|
+
if (!linkProps.href) return null;
|
|
12
|
+
return /* @__PURE__ */ jsxRuntime.jsx(stackUi.Anchor, { ...linkProps });
|
|
13
|
+
};
|
|
14
|
+
module.exports = DirectusLink;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Anchor } from "@okam/stack-ui";
|
|
3
|
+
import useDirectusLink from "../../hooks/directus-link.mjs";
|
|
4
|
+
const DirectusLink = (props) => {
|
|
5
|
+
const { type, componentsConfig } = props;
|
|
6
|
+
const linkProps = useDirectusLink(props);
|
|
7
|
+
if (!type) return null;
|
|
8
|
+
const LinkComponent = componentsConfig == null ? void 0 : componentsConfig[type];
|
|
9
|
+
if (LinkComponent) return /* @__PURE__ */ jsx(LinkComponent, { ...props });
|
|
10
|
+
if (!linkProps.href) return null;
|
|
11
|
+
return /* @__PURE__ */ jsx(Anchor, { ...linkProps });
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
DirectusLink as default
|
|
15
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TDefaultComponent, TAnchorProps } from '@okam/stack-ui';
|
|
2
|
+
import type { AriaAttributes, ComponentType } from 'react';
|
|
3
|
+
import type { TLinks } from '../../types/links';
|
|
4
|
+
export type TDirectusLink = Omit<TDefaultComponent, 'children'> & Omit<Partial<TLinks>, 'tokens'> & AriaAttributes;
|
|
5
|
+
export interface TUseDirectusLink extends TDirectusLink {
|
|
6
|
+
propsConfig?: TDirectusLinkPropsConfig;
|
|
7
|
+
}
|
|
8
|
+
export interface TDirectusLinkProps extends TDirectusLink {
|
|
9
|
+
componentsConfig?: TDirectusLinkComponentsConfig;
|
|
10
|
+
propsConfig?: TDirectusLinkPropsConfig;
|
|
11
|
+
}
|
|
12
|
+
export type TDirectusLinkComponentsConfig = Record<string, ComponentType<TDirectusLinkProps>>;
|
|
13
|
+
export type TDirectusLinkPropsConfig<ReturnProps extends TAnchorProps = TAnchorProps> = Record<string, (props: TUseDirectusLink) => ReturnProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const stackUi = require("@okam/stack-ui");
|
|
4
|
+
const directusFile = require("../../hooks/directus-file.js");
|
|
5
|
+
const DirectusVideo = (props) => {
|
|
6
|
+
const { baseUrl } = props;
|
|
7
|
+
const fileProps = directusFile(props, baseUrl);
|
|
8
|
+
if (!fileProps) return null;
|
|
9
|
+
const { type } = fileProps;
|
|
10
|
+
return /* @__PURE__ */ jsxRuntime.jsx(stackUi.Video, { ...fileProps, type: type ?? void 0 });
|
|
11
|
+
};
|
|
12
|
+
module.exports = DirectusVideo;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Video } from "@okam/stack-ui";
|
|
3
|
+
import useDirectusFile from "../../hooks/directus-file.mjs";
|
|
4
|
+
const DirectusVideo = (props) => {
|
|
5
|
+
const { baseUrl } = props;
|
|
6
|
+
const fileProps = useDirectusFile(props, baseUrl);
|
|
7
|
+
if (!fileProps) return null;
|
|
8
|
+
const { type } = fileProps;
|
|
9
|
+
return /* @__PURE__ */ jsx(Video, { ...fileProps, type: type ?? void 0 });
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
DirectusVideo as default
|
|
13
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { VideoHTMLAttributes } from 'react';
|
|
2
|
+
import type { TDirectusFileProps } from '../DirectusFile/interface';
|
|
3
|
+
type TDirectusVideoAttributes = Omit<VideoHTMLAttributes<HTMLVideoElement>, 'height' | 'id' | 'title' | 'width'>;
|
|
4
|
+
export type TDirectusVideoProps = TDirectusVideoAttributes & TDirectusFileProps;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Nullable } from '@okam/stack-ui';
|
|
2
|
+
import type { TFiles } from '../types/files';
|
|
3
|
+
export default function useDirectusFile(file: Nullable<TFiles>, baseUrl?: URL, searchParams?: Record<string, Nullable<string>>): {
|
|
4
|
+
tags?: any;
|
|
5
|
+
location?: string | null | undefined;
|
|
6
|
+
storage?: string | null | undefined;
|
|
7
|
+
focal_point_divider?: string | null | undefined;
|
|
8
|
+
focal_point_x?: number | null | undefined;
|
|
9
|
+
focal_point_y?: number | null | undefined;
|
|
10
|
+
filename_disk?: string | null | undefined;
|
|
11
|
+
filename_download?: string | null | undefined;
|
|
12
|
+
type?: string | null | undefined;
|
|
13
|
+
duration?: number | null | undefined;
|
|
14
|
+
embed?: string | null | undefined;
|
|
15
|
+
caption?: string | null | undefined;
|
|
16
|
+
thumbhash?: string | null | undefined;
|
|
17
|
+
filenameDownload?: string | null | undefined;
|
|
18
|
+
src: string;
|
|
19
|
+
alt: string;
|
|
20
|
+
width: number | undefined;
|
|
21
|
+
height: number | undefined;
|
|
22
|
+
title: string | undefined;
|
|
23
|
+
id: string;
|
|
24
|
+
} | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const IMG_DOMAIN = process.env.NEXT_PUBLIC_IMG_DOMAIN;
|
|
3
|
+
const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
|
|
4
|
+
const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
|
|
5
|
+
function setSearchParams(url, searchParams) {
|
|
6
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
7
|
+
if (!value) return;
|
|
8
|
+
url.searchParams.set(key, value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function getDirectusUrl(file, baseUrl, searchParams) {
|
|
12
|
+
const { id, filename_download, filenameDownload } = file ?? {};
|
|
13
|
+
const { protocol = IMG_PROTOCOL, port = IMG_PORT, hostname = IMG_DOMAIN } = baseUrl ?? {};
|
|
14
|
+
if (!hostname || !id) return null;
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(`/assets/${id}/${filename_download ?? filenameDownload ?? ""}`, `${protocol}://${hostname}`);
|
|
17
|
+
if (port) url.port = port;
|
|
18
|
+
if (searchParams) setSearchParams(url, searchParams);
|
|
19
|
+
return url;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.warn(error);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function useDirectusFile(file, baseUrl, searchParams) {
|
|
26
|
+
const { description, width, height, title, id, ...rest } = file ?? {};
|
|
27
|
+
if (!file || !id) return null;
|
|
28
|
+
const url = getDirectusUrl(file, baseUrl, searchParams);
|
|
29
|
+
if (!url) return null;
|
|
30
|
+
return {
|
|
31
|
+
src: url.href,
|
|
32
|
+
alt: description ?? "",
|
|
33
|
+
width: width ?? void 0,
|
|
34
|
+
height: height ?? void 0,
|
|
35
|
+
title: title ?? void 0,
|
|
36
|
+
id,
|
|
37
|
+
...rest
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
module.exports = useDirectusFile;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const IMG_DOMAIN = process.env.NEXT_PUBLIC_IMG_DOMAIN;
|
|
2
|
+
const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
|
|
3
|
+
const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
|
|
4
|
+
function setSearchParams(url, searchParams) {
|
|
5
|
+
Object.entries(searchParams).forEach(([key, value]) => {
|
|
6
|
+
if (!value) return;
|
|
7
|
+
url.searchParams.set(key, value);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function getDirectusUrl(file, baseUrl, searchParams) {
|
|
11
|
+
const { id, filename_download, filenameDownload } = file ?? {};
|
|
12
|
+
const { protocol = IMG_PROTOCOL, port = IMG_PORT, hostname = IMG_DOMAIN } = baseUrl ?? {};
|
|
13
|
+
if (!hostname || !id) return null;
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(`/assets/${id}/${filename_download ?? filenameDownload ?? ""}`, `${protocol}://${hostname}`);
|
|
16
|
+
if (port) url.port = port;
|
|
17
|
+
if (searchParams) setSearchParams(url, searchParams);
|
|
18
|
+
return url;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.warn(error);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function useDirectusFile(file, baseUrl, searchParams) {
|
|
25
|
+
const { description, width, height, title, id, ...rest } = file ?? {};
|
|
26
|
+
if (!file || !id) return null;
|
|
27
|
+
const url = getDirectusUrl(file, baseUrl, searchParams);
|
|
28
|
+
if (!url) return null;
|
|
29
|
+
return {
|
|
30
|
+
src: url.href,
|
|
31
|
+
alt: description ?? "",
|
|
32
|
+
width: width ?? void 0,
|
|
33
|
+
height: height ?? void 0,
|
|
34
|
+
title: title ?? void 0,
|
|
35
|
+
id,
|
|
36
|
+
...rest
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
useDirectusFile as default
|
|
41
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const Link = require("next/link.js");
|
|
3
|
+
const directusFile = require("./directus-file.js");
|
|
4
|
+
function useFile(props) {
|
|
5
|
+
const { file } = props;
|
|
6
|
+
const { filename_download: filenameDownload } = file ?? {};
|
|
7
|
+
const href = directusFile(file);
|
|
8
|
+
return {
|
|
9
|
+
href: (href == null ? void 0 : href.toString()) ?? void 0,
|
|
10
|
+
download: filenameDownload ?? true
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function useCollection(props) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const { collection, target } = props;
|
|
16
|
+
return {
|
|
17
|
+
href: ((_b = (_a = collection == null ? void 0 : collection.translations) == null ? void 0 : _a[0]) == null ? void 0 : _b.path) ?? void 0,
|
|
18
|
+
target: target ?? void 0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function useExternalLink(props) {
|
|
22
|
+
const { external_link: externalLink, target } = props;
|
|
23
|
+
return {
|
|
24
|
+
href: externalLink ?? void 0,
|
|
25
|
+
target: target ?? void 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function useAnchor(props) {
|
|
29
|
+
const { anchor } = props;
|
|
30
|
+
return { href: anchor ?? void 0 };
|
|
31
|
+
}
|
|
32
|
+
const defaultPropsConfig = {
|
|
33
|
+
collection: useCollection,
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
35
|
+
"external-link": useExternalLink,
|
|
36
|
+
file: useFile,
|
|
37
|
+
anchor: useAnchor
|
|
38
|
+
};
|
|
39
|
+
function useDirectusLink(props) {
|
|
40
|
+
var _a;
|
|
41
|
+
const {
|
|
42
|
+
type,
|
|
43
|
+
label,
|
|
44
|
+
prefetch,
|
|
45
|
+
replace,
|
|
46
|
+
scroll,
|
|
47
|
+
tokens,
|
|
48
|
+
themeName,
|
|
49
|
+
customTheme,
|
|
50
|
+
propsConfig,
|
|
51
|
+
as = Link,
|
|
52
|
+
target,
|
|
53
|
+
anchor,
|
|
54
|
+
collection,
|
|
55
|
+
external_link: externalLink,
|
|
56
|
+
file,
|
|
57
|
+
id,
|
|
58
|
+
...rest
|
|
59
|
+
} = props;
|
|
60
|
+
if (!type) return {};
|
|
61
|
+
const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
|
|
62
|
+
const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
|
|
63
|
+
const { href, ...restOfLinkProps } = linkProps;
|
|
64
|
+
if (!href) return {};
|
|
65
|
+
return {
|
|
66
|
+
...rest,
|
|
67
|
+
as,
|
|
68
|
+
...themeName ? { themeName } : {},
|
|
69
|
+
...customTheme ? { customTheme } : {},
|
|
70
|
+
...tokens ? { tokens } : {},
|
|
71
|
+
nextLinkProps: {
|
|
72
|
+
href,
|
|
73
|
+
prefetch: prefetch ?? void 0,
|
|
74
|
+
scroll: scroll ?? void 0,
|
|
75
|
+
replace: replace ?? void 0
|
|
76
|
+
},
|
|
77
|
+
href,
|
|
78
|
+
children: label,
|
|
79
|
+
...restOfLinkProps
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
module.exports = useDirectusLink;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Link from "next/link.js";
|
|
2
|
+
import useDirectusFile from "./directus-file.mjs";
|
|
3
|
+
function useFile(props) {
|
|
4
|
+
const { file } = props;
|
|
5
|
+
const { filename_download: filenameDownload } = file ?? {};
|
|
6
|
+
const href = useDirectusFile(file);
|
|
7
|
+
return {
|
|
8
|
+
href: (href == null ? void 0 : href.toString()) ?? void 0,
|
|
9
|
+
download: filenameDownload ?? true
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function useCollection(props) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const { collection, target } = props;
|
|
15
|
+
return {
|
|
16
|
+
href: ((_b = (_a = collection == null ? void 0 : collection.translations) == null ? void 0 : _a[0]) == null ? void 0 : _b.path) ?? void 0,
|
|
17
|
+
target: target ?? void 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function useExternalLink(props) {
|
|
21
|
+
const { external_link: externalLink, target } = props;
|
|
22
|
+
return {
|
|
23
|
+
href: externalLink ?? void 0,
|
|
24
|
+
target: target ?? void 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function useAnchor(props) {
|
|
28
|
+
const { anchor } = props;
|
|
29
|
+
return { href: anchor ?? void 0 };
|
|
30
|
+
}
|
|
31
|
+
const defaultPropsConfig = {
|
|
32
|
+
collection: useCollection,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
34
|
+
"external-link": useExternalLink,
|
|
35
|
+
file: useFile,
|
|
36
|
+
anchor: useAnchor
|
|
37
|
+
};
|
|
38
|
+
function useDirectusLink(props) {
|
|
39
|
+
var _a;
|
|
40
|
+
const {
|
|
41
|
+
type,
|
|
42
|
+
label,
|
|
43
|
+
prefetch,
|
|
44
|
+
replace,
|
|
45
|
+
scroll,
|
|
46
|
+
tokens,
|
|
47
|
+
themeName,
|
|
48
|
+
customTheme,
|
|
49
|
+
propsConfig,
|
|
50
|
+
as = Link,
|
|
51
|
+
target,
|
|
52
|
+
anchor,
|
|
53
|
+
collection,
|
|
54
|
+
external_link: externalLink,
|
|
55
|
+
file,
|
|
56
|
+
id,
|
|
57
|
+
...rest
|
|
58
|
+
} = props;
|
|
59
|
+
if (!type) return {};
|
|
60
|
+
const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
|
|
61
|
+
const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
|
|
62
|
+
const { href, ...restOfLinkProps } = linkProps;
|
|
63
|
+
if (!href) return {};
|
|
64
|
+
return {
|
|
65
|
+
...rest,
|
|
66
|
+
as,
|
|
67
|
+
...themeName ? { themeName } : {},
|
|
68
|
+
...customTheme ? { customTheme } : {},
|
|
69
|
+
...tokens ? { tokens } : {},
|
|
70
|
+
nextLinkProps: {
|
|
71
|
+
href,
|
|
72
|
+
prefetch: prefetch ?? void 0,
|
|
73
|
+
scroll: scroll ?? void 0,
|
|
74
|
+
replace: replace ?? void 0
|
|
75
|
+
},
|
|
76
|
+
href,
|
|
77
|
+
children: label,
|
|
78
|
+
...restOfLinkProps
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
useDirectusLink as default
|
|
83
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Nullable } from '@okam/stack-ui';
|
|
2
|
+
import type { TDirectusLinkProps } from '../components/DirectusLink/interface';
|
|
3
|
+
import type { TNavigationItems, TNavigationItemsTree } from '../types/navigation-items';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param navigationItems A tree of navigation items, with parents and children
|
|
7
|
+
* @param onNavigationItem Called when a navigation item is about to be added to the tree
|
|
8
|
+
* @returns A tree of navigation items with ready-to-use DirectusLink components
|
|
9
|
+
*/
|
|
10
|
+
export default function useNavigationItems<Depth extends number, Link, NavigationItems extends TNavigationItems<NavigationItems, Link, Depth> = TNavigationItems<unknown, Link, Depth>>(items: Nullable<Nullable<TNavigationItems<NavigationItems, Link, Depth>>[]>, onNavigationItem: (item: Nullable<TNavigationItems<NavigationItems, Link, Depth>>) => Nullable<TDirectusLinkProps>): Nullable<Nullable<TNavigationItemsTree>[]>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const index = require("../components/DirectusLink/index.js");
|
|
4
|
+
function createLinkProps(item, onNavigationItem) {
|
|
5
|
+
const { tokens, variant } = item ?? {};
|
|
6
|
+
const link = onNavigationItem(item);
|
|
7
|
+
const linkTokens = {
|
|
8
|
+
...tokens,
|
|
9
|
+
...link == null ? void 0 : link.tokens,
|
|
10
|
+
type: variant
|
|
11
|
+
};
|
|
12
|
+
const linkProps = {
|
|
13
|
+
...link,
|
|
14
|
+
tokens: linkTokens
|
|
15
|
+
};
|
|
16
|
+
return linkProps;
|
|
17
|
+
}
|
|
18
|
+
function createParentTree(item, onNavigationItem, depth = -1) {
|
|
19
|
+
const { parent } = item ?? {};
|
|
20
|
+
const linkProps = createLinkProps(item, onNavigationItem);
|
|
21
|
+
const { id } = linkProps ?? {};
|
|
22
|
+
if (!id) return null;
|
|
23
|
+
return {
|
|
24
|
+
link: /* @__PURE__ */ jsxRuntime.jsx(index, { ...linkProps }),
|
|
25
|
+
linkProps,
|
|
26
|
+
parent: createParentTree(parent, onNavigationItem, depth - 1),
|
|
27
|
+
depth
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createChildrenTree(item, onNavigationItem, depth = 1) {
|
|
31
|
+
const { children } = item ?? {};
|
|
32
|
+
const linkProps = createLinkProps(item, onNavigationItem);
|
|
33
|
+
const { id } = linkProps ?? {};
|
|
34
|
+
if (!id) return null;
|
|
35
|
+
return {
|
|
36
|
+
link: /* @__PURE__ */ jsxRuntime.jsx(index, { ...linkProps }),
|
|
37
|
+
linkProps,
|
|
38
|
+
children: children == null ? void 0 : children.map((child) => createChildrenTree(child, onNavigationItem, depth + 1)),
|
|
39
|
+
depth
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function useNavigationItems(items, onNavigationItem) {
|
|
43
|
+
const tree = items == null ? void 0 : items.map((item) => {
|
|
44
|
+
const { children, parent } = item ?? {};
|
|
45
|
+
const linkProps = createLinkProps(item, onNavigationItem);
|
|
46
|
+
const parentTree = createParentTree(parent, onNavigationItem);
|
|
47
|
+
const childrenTree = children == null ? void 0 : children.map((child) => createChildrenTree(child, onNavigationItem));
|
|
48
|
+
return {
|
|
49
|
+
depth: 0,
|
|
50
|
+
parent: parentTree,
|
|
51
|
+
children: childrenTree,
|
|
52
|
+
link: /* @__PURE__ */ jsxRuntime.jsx(index, { ...linkProps }),
|
|
53
|
+
linkProps
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
return tree;
|
|
57
|
+
}
|
|
58
|
+
module.exports = useNavigationItems;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import DirectusLink from "../components/DirectusLink/index.mjs";
|
|
3
|
+
function createLinkProps(item, onNavigationItem) {
|
|
4
|
+
const { tokens, variant } = item ?? {};
|
|
5
|
+
const link = onNavigationItem(item);
|
|
6
|
+
const linkTokens = {
|
|
7
|
+
...tokens,
|
|
8
|
+
...link == null ? void 0 : link.tokens,
|
|
9
|
+
type: variant
|
|
10
|
+
};
|
|
11
|
+
const linkProps = {
|
|
12
|
+
...link,
|
|
13
|
+
tokens: linkTokens
|
|
14
|
+
};
|
|
15
|
+
return linkProps;
|
|
16
|
+
}
|
|
17
|
+
function createParentTree(item, onNavigationItem, depth = -1) {
|
|
18
|
+
const { parent } = item ?? {};
|
|
19
|
+
const linkProps = createLinkProps(item, onNavigationItem);
|
|
20
|
+
const { id } = linkProps ?? {};
|
|
21
|
+
if (!id) return null;
|
|
22
|
+
return {
|
|
23
|
+
link: /* @__PURE__ */ jsx(DirectusLink, { ...linkProps }),
|
|
24
|
+
linkProps,
|
|
25
|
+
parent: createParentTree(parent, onNavigationItem, depth - 1),
|
|
26
|
+
depth
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createChildrenTree(item, onNavigationItem, depth = 1) {
|
|
30
|
+
const { children } = item ?? {};
|
|
31
|
+
const linkProps = createLinkProps(item, onNavigationItem);
|
|
32
|
+
const { id } = linkProps ?? {};
|
|
33
|
+
if (!id) return null;
|
|
34
|
+
return {
|
|
35
|
+
link: /* @__PURE__ */ jsx(DirectusLink, { ...linkProps }),
|
|
36
|
+
linkProps,
|
|
37
|
+
children: children == null ? void 0 : children.map((child) => createChildrenTree(child, onNavigationItem, depth + 1)),
|
|
38
|
+
depth
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function useNavigationItems(items, onNavigationItem) {
|
|
42
|
+
const tree = items == null ? void 0 : items.map((item) => {
|
|
43
|
+
const { children, parent } = item ?? {};
|
|
44
|
+
const linkProps = createLinkProps(item, onNavigationItem);
|
|
45
|
+
const parentTree = createParentTree(parent, onNavigationItem);
|
|
46
|
+
const childrenTree = children == null ? void 0 : children.map((child) => createChildrenTree(child, onNavigationItem));
|
|
47
|
+
return {
|
|
48
|
+
depth: 0,
|
|
49
|
+
parent: parentTree,
|
|
50
|
+
children: childrenTree,
|
|
51
|
+
link: /* @__PURE__ */ jsx(DirectusLink, { ...linkProps }),
|
|
52
|
+
linkProps
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
return tree;
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
useNavigationItems as default
|
|
59
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as DirectusLink } from './components/DirectusLink';
|
|
2
|
+
export { default as DirectusImg } from './components/DirectusImg';
|
|
3
|
+
export { default as DirectusVideo } from './components/DirectusVideo';
|
|
4
|
+
export { default as DirectusFile } from './components/DirectusFile';
|
|
5
|
+
export { default as useDirectusFile } from './hooks/directus-file';
|
|
6
|
+
export { default as useDirectusLink } from './hooks/directus-link';
|
|
7
|
+
export { default as useNavigationItems } from './hooks/navigation-items';
|
|
8
|
+
export type { TFiles } from './types/files';
|
|
9
|
+
export type { TPageSettings } from './types/page-settings';
|
|
10
|
+
export type { TNavigationItems, TNavigationItemsTree } from './types/navigation-items';
|
|
11
|
+
export type { TLinks } from './types/links';
|
|
12
|
+
export type { TDirectusLinkProps, TUseDirectusLink, TDirectusLink, TDirectusLinkPropsConfig, TDirectusLinkComponentsConfig, } from './components/DirectusLink/interface';
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const index = require("./components/DirectusLink/index.js");
|
|
4
|
+
const index$1 = require("./components/DirectusImg/index.js");
|
|
5
|
+
const index$2 = require("./components/DirectusVideo/index.js");
|
|
6
|
+
const index$3 = require("./components/DirectusFile/index.js");
|
|
7
|
+
const directusFile = require("./hooks/directus-file.js");
|
|
8
|
+
const directusLink = require("./hooks/directus-link.js");
|
|
9
|
+
const navigationItems = require("./hooks/navigation-items.js");
|
|
10
|
+
exports.DirectusLink = index;
|
|
11
|
+
exports.DirectusImg = index$1;
|
|
12
|
+
exports.DirectusVideo = index$2;
|
|
13
|
+
exports.DirectusFile = index$3;
|
|
14
|
+
exports.useDirectusFile = directusFile;
|
|
15
|
+
exports.useDirectusLink = directusLink;
|
|
16
|
+
exports.useNavigationItems = navigationItems;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { default as default2 } from "./components/DirectusLink/index.mjs";
|
|
2
|
+
import { default as default3 } from "./components/DirectusImg/index.mjs";
|
|
3
|
+
import { default as default4 } from "./components/DirectusVideo/index.mjs";
|
|
4
|
+
import { default as default5 } from "./components/DirectusFile/index.mjs";
|
|
5
|
+
import { default as default6 } from "./hooks/directus-file.mjs";
|
|
6
|
+
import { default as default7 } from "./hooks/directus-link.mjs";
|
|
7
|
+
import { default as default8 } from "./hooks/navigation-items.mjs";
|
|
8
|
+
export {
|
|
9
|
+
default5 as DirectusFile,
|
|
10
|
+
default3 as DirectusImg,
|
|
11
|
+
default2 as DirectusLink,
|
|
12
|
+
default4 as DirectusVideo,
|
|
13
|
+
default6 as useDirectusFile,
|
|
14
|
+
default7 as useDirectusLink,
|
|
15
|
+
default8 as useNavigationItems
|
|
16
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const server_js = require("next/server.js");
|
|
4
|
+
const radash = require("radash");
|
|
5
|
+
async function fetchPageSettings(pathName, lang = "fr-CA") {
|
|
6
|
+
const graphqlEndpoint = process.env.NEXT_PUBLIC_GRAPHQL_URL;
|
|
7
|
+
const graphqlApiKey = process.env.NEXT_PUBLIC_API_TOKEN;
|
|
8
|
+
if (!graphqlEndpoint || !graphqlApiKey) {
|
|
9
|
+
throw new Error("Missing graphql configuration: NEXT_PUBLIC_GRAPHQL_URL or NEXT_API_TOKEN_ADMIN");
|
|
10
|
+
}
|
|
11
|
+
let langCodeFilter = "_eq";
|
|
12
|
+
if (lang.length === 2) {
|
|
13
|
+
langCodeFilter = "_contains";
|
|
14
|
+
}
|
|
15
|
+
const query = `
|
|
16
|
+
query PageSettings($path: String = null, $lang: String = "fr-CA") {
|
|
17
|
+
page_settings(
|
|
18
|
+
filter: { translations: { path: { _eq: $path }, languages_code: {code: {${langCodeFilter}: $lang}} }},
|
|
19
|
+
limit: 1
|
|
20
|
+
) {
|
|
21
|
+
belongs_to_key
|
|
22
|
+
belongs_to_collection
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
const graphqlBody = {
|
|
27
|
+
query,
|
|
28
|
+
variables: {
|
|
29
|
+
lang,
|
|
30
|
+
path: pathName
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const response = await fetch(graphqlEndpoint, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
Authorization: `Bearer ${graphqlApiKey}`
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(graphqlBody)
|
|
42
|
+
});
|
|
43
|
+
const { data } = await response.json();
|
|
44
|
+
const key = radash.get(data, "page_settings.0.belongs_to_key");
|
|
45
|
+
const collection = radash.get(data, "page_settings.0.belongs_to_collection");
|
|
46
|
+
if (key == null || collection == null) {
|
|
47
|
+
throw new Error("No page settings found");
|
|
48
|
+
}
|
|
49
|
+
return `/${collection}/${key}`;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error("GraphQL Error", e.message);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function removeLocaleFromPathName(pathName, locale) {
|
|
56
|
+
if (pathName.includes(locale)) {
|
|
57
|
+
return pathName.replace(`/${locale}`, "");
|
|
58
|
+
}
|
|
59
|
+
return pathName;
|
|
60
|
+
}
|
|
61
|
+
async function directusRouteMiddleware(request, locales) {
|
|
62
|
+
const { pathname } = request.nextUrl;
|
|
63
|
+
const locale = locales.find((l) => pathname.startsWith(`/${l}`));
|
|
64
|
+
const pathNameWithoutLocale = locale ? removeLocaleFromPathName(pathname, locale) : pathname;
|
|
65
|
+
const route = await fetchPageSettings(pathNameWithoutLocale, locale);
|
|
66
|
+
if (route === null) {
|
|
67
|
+
return server_js.NextResponse.next();
|
|
68
|
+
}
|
|
69
|
+
const url = request.nextUrl.clone();
|
|
70
|
+
url.pathname = route;
|
|
71
|
+
return server_js.NextResponse.rewrite(url);
|
|
72
|
+
}
|
|
73
|
+
const config = {
|
|
74
|
+
matcher: [
|
|
75
|
+
/*
|
|
76
|
+
* Match all request paths except for the ones starting with:
|
|
77
|
+
* - api (API routes)
|
|
78
|
+
* - _next/static (static files)
|
|
79
|
+
* - _next/image (image optimization files)
|
|
80
|
+
* - favicon.ico (favicon file)
|
|
81
|
+
*/
|
|
82
|
+
"/((?!api|_next/static|_next/image|favicon.ico).*)"
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
exports.config = config;
|
|
86
|
+
exports.directusRouteMiddleware = directusRouteMiddleware;
|
|
87
|
+
exports.fetchPageSettings = fetchPageSettings;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { NextResponse } from "next/server.js";
|
|
2
|
+
import { get } from "radash";
|
|
3
|
+
async function fetchPageSettings(pathName, lang = "fr-CA") {
|
|
4
|
+
const graphqlEndpoint = process.env.NEXT_PUBLIC_GRAPHQL_URL;
|
|
5
|
+
const graphqlApiKey = process.env.NEXT_PUBLIC_API_TOKEN;
|
|
6
|
+
if (!graphqlEndpoint || !graphqlApiKey) {
|
|
7
|
+
throw new Error("Missing graphql configuration: NEXT_PUBLIC_GRAPHQL_URL or NEXT_API_TOKEN_ADMIN");
|
|
8
|
+
}
|
|
9
|
+
let langCodeFilter = "_eq";
|
|
10
|
+
if (lang.length === 2) {
|
|
11
|
+
langCodeFilter = "_contains";
|
|
12
|
+
}
|
|
13
|
+
const query = `
|
|
14
|
+
query PageSettings($path: String = null, $lang: String = "fr-CA") {
|
|
15
|
+
page_settings(
|
|
16
|
+
filter: { translations: { path: { _eq: $path }, languages_code: {code: {${langCodeFilter}: $lang}} }},
|
|
17
|
+
limit: 1
|
|
18
|
+
) {
|
|
19
|
+
belongs_to_key
|
|
20
|
+
belongs_to_collection
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
const graphqlBody = {
|
|
25
|
+
query,
|
|
26
|
+
variables: {
|
|
27
|
+
lang,
|
|
28
|
+
path: pathName
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(graphqlEndpoint, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Authorization: `Bearer ${graphqlApiKey}`
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(graphqlBody)
|
|
40
|
+
});
|
|
41
|
+
const { data } = await response.json();
|
|
42
|
+
const key = get(data, "page_settings.0.belongs_to_key");
|
|
43
|
+
const collection = get(data, "page_settings.0.belongs_to_collection");
|
|
44
|
+
if (key == null || collection == null) {
|
|
45
|
+
throw new Error("No page settings found");
|
|
46
|
+
}
|
|
47
|
+
return `/${collection}/${key}`;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error("GraphQL Error", e.message);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function removeLocaleFromPathName(pathName, locale) {
|
|
54
|
+
if (pathName.includes(locale)) {
|
|
55
|
+
return pathName.replace(`/${locale}`, "");
|
|
56
|
+
}
|
|
57
|
+
return pathName;
|
|
58
|
+
}
|
|
59
|
+
async function directusRouteMiddleware(request, locales) {
|
|
60
|
+
const { pathname } = request.nextUrl;
|
|
61
|
+
const locale = locales.find((l) => pathname.startsWith(`/${l}`));
|
|
62
|
+
const pathNameWithoutLocale = locale ? removeLocaleFromPathName(pathname, locale) : pathname;
|
|
63
|
+
const route = await fetchPageSettings(pathNameWithoutLocale, locale);
|
|
64
|
+
if (route === null) {
|
|
65
|
+
return NextResponse.next();
|
|
66
|
+
}
|
|
67
|
+
const url = request.nextUrl.clone();
|
|
68
|
+
url.pathname = route;
|
|
69
|
+
return NextResponse.rewrite(url);
|
|
70
|
+
}
|
|
71
|
+
const config = {
|
|
72
|
+
matcher: [
|
|
73
|
+
/*
|
|
74
|
+
* Match all request paths except for the ones starting with:
|
|
75
|
+
* - api (API routes)
|
|
76
|
+
* - _next/static (static files)
|
|
77
|
+
* - _next/image (image optimization files)
|
|
78
|
+
* - favicon.ico (favicon file)
|
|
79
|
+
*/
|
|
80
|
+
"/((?!api|_next/static|_next/image|favicon.ico).*)"
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
config,
|
|
85
|
+
directusRouteMiddleware,
|
|
86
|
+
fetchPageSettings
|
|
87
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-next-component",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"main": "./index.js",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./index.mjs",
|
|
9
|
+
"require": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"import": "./server.mjs",
|
|
13
|
+
"require": "./server.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"registry": "https://registry.npmjs.org"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"url": "https://github.com/OKAMca/stack.git"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/server.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as withDirectus } from './lib/withDirectus';
|
|
2
|
+
export * from './lib/directus-next-rewrite';
|
|
3
|
+
export { default as DirectusLink } from './components/DirectusLink';
|
|
4
|
+
export { default as DirectusImg } from './components/DirectusImg';
|
|
5
|
+
export { default as DirectusVideo } from './components/DirectusVideo';
|
|
6
|
+
export { default as DirectusFile } from './components/DirectusFile';
|
|
7
|
+
export { default as useDirectusFile } from './hooks/directus-file';
|
|
8
|
+
export { default as useDirectusLink } from './hooks/directus-link';
|
|
9
|
+
export { default as useNavigationItems } from './hooks/navigation-items';
|
package/server.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const withDirectus = require("./lib/withDirectus.js");
|
|
4
|
+
const directusNextRewrite = require("./lib/directus-next-rewrite.js");
|
|
5
|
+
const index = require("./components/DirectusLink/index.js");
|
|
6
|
+
const index$1 = require("./components/DirectusImg/index.js");
|
|
7
|
+
const index$2 = require("./components/DirectusVideo/index.js");
|
|
8
|
+
const index$3 = require("./components/DirectusFile/index.js");
|
|
9
|
+
const directusFile = require("./hooks/directus-file.js");
|
|
10
|
+
const directusLink = require("./hooks/directus-link.js");
|
|
11
|
+
const navigationItems = require("./hooks/navigation-items.js");
|
|
12
|
+
exports.withDirectus = withDirectus;
|
|
13
|
+
exports.config = directusNextRewrite.config;
|
|
14
|
+
exports.directusRouteMiddleware = directusNextRewrite.directusRouteMiddleware;
|
|
15
|
+
exports.fetchPageSettings = directusNextRewrite.fetchPageSettings;
|
|
16
|
+
exports.DirectusLink = index;
|
|
17
|
+
exports.DirectusImg = index$1;
|
|
18
|
+
exports.DirectusVideo = index$2;
|
|
19
|
+
exports.DirectusFile = index$3;
|
|
20
|
+
exports.useDirectusFile = directusFile;
|
|
21
|
+
exports.useDirectusLink = directusLink;
|
|
22
|
+
exports.useNavigationItems = navigationItems;
|
package/server.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { default as default2 } from "./lib/withDirectus.mjs";
|
|
2
|
+
import { config, directusRouteMiddleware, fetchPageSettings } from "./lib/directus-next-rewrite.mjs";
|
|
3
|
+
import { default as default3 } from "./components/DirectusLink/index.mjs";
|
|
4
|
+
import { default as default4 } from "./components/DirectusImg/index.mjs";
|
|
5
|
+
import { default as default5 } from "./components/DirectusVideo/index.mjs";
|
|
6
|
+
import { default as default6 } from "./components/DirectusFile/index.mjs";
|
|
7
|
+
import { default as default7 } from "./hooks/directus-file.mjs";
|
|
8
|
+
import { default as default8 } from "./hooks/directus-link.mjs";
|
|
9
|
+
import { default as default9 } from "./hooks/navigation-items.mjs";
|
|
10
|
+
export {
|
|
11
|
+
default6 as DirectusFile,
|
|
12
|
+
default4 as DirectusImg,
|
|
13
|
+
default3 as DirectusLink,
|
|
14
|
+
default5 as DirectusVideo,
|
|
15
|
+
config,
|
|
16
|
+
directusRouteMiddleware,
|
|
17
|
+
fetchPageSettings,
|
|
18
|
+
default7 as useDirectusFile,
|
|
19
|
+
default8 as useDirectusLink,
|
|
20
|
+
default9 as useNavigationItems,
|
|
21
|
+
default2 as withDirectus
|
|
22
|
+
};
|
package/types/files.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TFiles = {
|
|
2
|
+
id?: string | null;
|
|
3
|
+
title?: string | null;
|
|
4
|
+
description?: string | null;
|
|
5
|
+
tags?: any | null;
|
|
6
|
+
location?: string | null;
|
|
7
|
+
storage?: string | null;
|
|
8
|
+
focal_point_divider?: string | null;
|
|
9
|
+
focal_point_x?: number | null;
|
|
10
|
+
focal_point_y?: number | null;
|
|
11
|
+
filename_disk?: string | null;
|
|
12
|
+
filename_download?: string | null;
|
|
13
|
+
type?: string | null;
|
|
14
|
+
width?: number | null;
|
|
15
|
+
height?: number | null;
|
|
16
|
+
duration?: number | null;
|
|
17
|
+
embed?: string | null;
|
|
18
|
+
caption?: string | null;
|
|
19
|
+
thumbhash?: string | null;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `filename_download` instead
|
|
22
|
+
*/
|
|
23
|
+
filenameDownload?: string | null;
|
|
24
|
+
};
|
package/types/links.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TFiles } from './files';
|
|
2
|
+
import type { TPageSettings } from './page-settings';
|
|
3
|
+
/**
|
|
4
|
+
* Represent the directus `links` collection, not the props of the DirectusLink component
|
|
5
|
+
*/
|
|
6
|
+
export type TLinks = {
|
|
7
|
+
anchor?: string | null;
|
|
8
|
+
external_link?: string | null;
|
|
9
|
+
id?: string;
|
|
10
|
+
label?: string | null;
|
|
11
|
+
prefetch?: boolean | null;
|
|
12
|
+
replace?: boolean | null;
|
|
13
|
+
scroll?: boolean | null;
|
|
14
|
+
target?: string | null;
|
|
15
|
+
type?: string | null;
|
|
16
|
+
collection?: TPageSettings | null;
|
|
17
|
+
file?: TFiles | null;
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Nullable } from '@okam/stack-ui';
|
|
3
|
+
import type { TDirectusLinkProps } from '../components/DirectusLink/interface';
|
|
4
|
+
export type TNavigationItemsTree = {
|
|
5
|
+
/**
|
|
6
|
+
* Pre-rendered DirectusLink component for quick usage
|
|
7
|
+
*/
|
|
8
|
+
link: Nullable<React.ReactElement>;
|
|
9
|
+
linkProps: Nullable<TDirectusLinkProps>;
|
|
10
|
+
children?: Nullable<Nullable<TNavigationItemsTree>[]>;
|
|
11
|
+
parent?: Nullable<TNavigationItemsTree>;
|
|
12
|
+
/**
|
|
13
|
+
* Starts at 0.
|
|
14
|
+
* For each level of parent, goes down by 1
|
|
15
|
+
* For each level of children, goes up by 1
|
|
16
|
+
*/
|
|
17
|
+
depth: number;
|
|
18
|
+
};
|
|
19
|
+
type DepthLimit = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
20
|
+
export type TNavigationItemsBase<Link> = {
|
|
21
|
+
tokens?: any | null;
|
|
22
|
+
variant?: string | null;
|
|
23
|
+
} & Link;
|
|
24
|
+
export type TNavigationItemsParents<NavigationItems, Link, Depth extends number> = Depth extends never ? TNavigationItemsBase<Link> : {
|
|
25
|
+
parent?: Nullable<TNavigationItemsParents<NavigationItems, Link, Depth>>;
|
|
26
|
+
} & TNavigationItemsBase<Link>;
|
|
27
|
+
export type TNavigationItemsChildren<NavigationItems, Link, Depth extends number> = Depth extends never ? TNavigationItemsBase<Link> : {
|
|
28
|
+
children?: Nullable<Nullable<TNavigationItemsChildren<NavigationItems, Link, DepthLimit[Depth]>>[]>;
|
|
29
|
+
} & TNavigationItemsBase<Link>;
|
|
30
|
+
export type TNavigationItems<NavigationItems, Link, Depth extends number> = TNavigationItemsChildren<NavigationItems, Link, Depth> & TNavigationItemsParents<NavigationItems, Link, Depth>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type TPageSettings = {
|
|
2
|
+
id: string;
|
|
3
|
+
belongs_to_collection?: string | null;
|
|
4
|
+
translations?: Array<{
|
|
5
|
+
slug?: string | null;
|
|
6
|
+
title?: string | null;
|
|
7
|
+
path?: string | null;
|
|
8
|
+
languages_code?: {
|
|
9
|
+
code: string;
|
|
10
|
+
} | null;
|
|
11
|
+
} | null> | null;
|
|
12
|
+
route?: {
|
|
13
|
+
translations?: Array<{
|
|
14
|
+
route?: string | null;
|
|
15
|
+
} | null> | null;
|
|
16
|
+
} | null;
|
|
17
|
+
};
|
package/README.md
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# directus-next-component
|
|
2
|
-
|
|
3
|
-
This library was generated with [Nx](https://nx.dev).
|
|
4
|
-
|
|
5
|
-
## directusRouteMiddleware usage
|
|
6
|
-
|
|
7
|
-
Create a middleware.ts file in the project, in the `/src/app` directory of the next application, and add the following code to it.
|
|
8
|
-
|
|
9
|
-
```jsx
|
|
10
|
-
// middleware.ts
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
directusRouteMiddleware,
|
|
14
|
-
config as directusRouteMiddlewareConfig,
|
|
15
|
-
} from '@okam/directus-next-component/src/server'
|
|
16
|
-
import type { NextRequest } from 'next/server'
|
|
17
|
-
|
|
18
|
-
export function middleware(request: NextRequest) {
|
|
19
|
-
const { locale } = request.nextUrl
|
|
20
|
-
return directusRouteMiddleware(request, [locale])
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const config = {
|
|
24
|
-
...directusRouteMiddlewareConfig,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
After, modify the `next.config.js` file to add `withDirectus` in the plugins.
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/src/index.d.ts
DELETED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function HelloServer(): Promise<import("react/jsx-runtime").JSX.Element>;
|
package/src/server.d.ts
DELETED
|
File without changes
|
|
File without changes
|