@okam/directus-next-component 1.8.13 → 1.8.15
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/CHANGELOG.md +8 -0
- package/components/DirectusFile/config.d.ts +0 -1
- package/components/DirectusFile/index.d.ts +1 -2
- package/components/DirectusFile/index.js +5 -5
- package/components/DirectusFile/index.mjs +5 -5
- package/components/DirectusFile/interface.d.ts +0 -1
- package/components/DirectusImg/index.d.ts +1 -2
- package/components/DirectusImg/index.js +6 -6
- package/components/DirectusImg/index.mjs +6 -6
- package/components/DirectusImg/interface.d.ts +0 -1
- package/components/DirectusLink/index.d.ts +1 -2
- package/components/DirectusLink/index.js +9 -6
- package/components/DirectusLink/index.mjs +9 -6
- package/components/DirectusLink/interface.d.ts +2 -3
- package/components/DirectusVideo/index.d.ts +1 -2
- package/components/DirectusVideo/index.js +4 -3
- package/components/DirectusVideo/index.mjs +4 -3
- package/components/DirectusVideo/interface.d.ts +0 -1
- package/index.d.ts +9 -9
- package/index.js +16 -16
- package/index.mjs +8 -8
- package/lib/directus-next-rewrite.d.ts +0 -1
- package/lib/withDirectus.d.ts +1 -2
- package/lib/withDirectus.js +2 -2
- package/lib/withDirectus.mjs +2 -2
- package/package.json +18 -13
- package/server.d.ts +2 -2
- package/server.js +8 -8
- package/server.mjs +11 -11
- package/types/index.d.ts +3 -3
- package/types/links.d.ts +1 -2
- package/types/metadata.d.ts +2 -3
- package/types/navigationItems.d.ts +22 -4
- package/utils/getDirectusFile/index.d.ts +1 -2
- package/utils/getDirectusFile/index.js +12 -6
- package/utils/getDirectusFile/index.mjs +12 -6
- package/utils/getDirectusLink/index.d.ts +0 -1
- package/utils/getDirectusLink/index.js +16 -16
- package/utils/getDirectusLink/index.mjs +16 -16
- package/utils/getDirectusMetadata/index.d.ts +0 -1
- package/utils/getDirectusMetadata/index.js +23 -23
- package/utils/getDirectusMetadata/index.mjs +23 -23
- package/utils/getDirectusSearchParams/index.d.ts +0 -1
- package/utils/getDirectusSearchParams/index.js +1 -1
- package/utils/getDirectusSearchParams/index.mjs +1 -1
- package/utils/getNavigationItems/index.d.ts +1 -2
- package/utils/getNavigationItems/index.js +8 -6
- package/utils/getNavigationItems/index.mjs +8 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Nullable } from '@okam/stack-ui';
|
|
2
2
|
import { TDirectusLinkProps } from '../components/DirectusLink/interface';
|
|
3
|
-
|
|
4
|
-
export type TNavigationItemsTree = {
|
|
3
|
+
export interface TNavigationItemsTree {
|
|
5
4
|
/**
|
|
6
5
|
* Pre-rendered DirectusLink component for quick usage
|
|
7
6
|
*/
|
|
@@ -15,10 +14,29 @@ export type TNavigationItemsTree = {
|
|
|
15
14
|
* For each level of children, goes up by 1
|
|
16
15
|
*/
|
|
17
16
|
depth: number;
|
|
18
|
-
}
|
|
17
|
+
}
|
|
19
18
|
type DepthLimit = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
19
|
+
/**
|
|
20
|
+
* WHY `any` IS REQUIRED FOR tokens:
|
|
21
|
+
*
|
|
22
|
+
* The tokens field comes from Directus CMS and may contain null/undefined values.
|
|
23
|
+
* However, the downstream TDirectusLinkProps expects TToken (Record<string, string | boolean>).
|
|
24
|
+
*
|
|
25
|
+
* The type mismatch occurs because:
|
|
26
|
+
* 1. CMS data has nullable fields: variant?: string | null
|
|
27
|
+
* 2. getNavigationItems spreads tokens and adds: type: variant
|
|
28
|
+
* 3. TNavigationItemsTree.linkProps expects TToken without null/undefined
|
|
29
|
+
*
|
|
30
|
+
* Fixing this properly would require either:
|
|
31
|
+
* - Runtime filtering of null/undefined values (behavior change)
|
|
32
|
+
* - Changing TToken to allow null/undefined (cascading type changes across stack-ui)
|
|
33
|
+
* - Creating separate CMS and component token types (significant refactor)
|
|
34
|
+
*
|
|
35
|
+
* The `any` type here acts as a type boundary between CMS data and UI components.
|
|
36
|
+
* Type safety is enforced at the component level where tokens are actually consumed.
|
|
37
|
+
*/
|
|
20
38
|
export type TNavigationItemsBase<Link> = {
|
|
21
|
-
tokens?: any
|
|
39
|
+
tokens?: any;
|
|
22
40
|
variant?: string | null;
|
|
23
41
|
} & Link;
|
|
24
42
|
export type TNavigationItemsParents<TNavigationItems, Link, Depth extends number> = Depth extends never ? TNavigationItemsBase<Link> : {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TFiles } from '@okam/directus-next';
|
|
2
2
|
import { Nullable } from '@okam/stack-ui';
|
|
3
|
-
|
|
4
3
|
export declare function getDirectusUrl(file: Nullable<TFiles>, baseUrl?: URL, searchParams?: Record<string, Nullable<string>>): URL | null;
|
|
5
4
|
export declare function getDirectusFile(file: Nullable<TFiles>, baseUrl?: URL, searchParams?: Record<string, Nullable<string>>): {
|
|
6
|
-
tags?:
|
|
5
|
+
tags?: unknown;
|
|
7
6
|
location?: string | null;
|
|
8
7
|
storage?: string | null;
|
|
9
8
|
focal_point_divider?: string | null;
|
|
@@ -6,18 +6,22 @@ const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
|
|
|
6
6
|
const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
|
|
7
7
|
function setSearchParams(url, searchParams) {
|
|
8
8
|
Object.entries(searchParams).forEach(([key, value]) => {
|
|
9
|
-
if (
|
|
9
|
+
if (value == null || value === "")
|
|
10
|
+
return;
|
|
10
11
|
url.searchParams.set(key, value);
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
function getDirectusUrl(file, baseUrl, searchParams) {
|
|
14
15
|
const { id, filename_download, filenameDownload } = file ?? {};
|
|
15
16
|
const { protocol = IMG_PROTOCOL, port = IMG_PORT, hostname = IMG_DOMAIN } = baseUrl ?? {};
|
|
16
|
-
if (
|
|
17
|
+
if (hostname == null || hostname === "" || id == null || id === "")
|
|
18
|
+
return null;
|
|
17
19
|
try {
|
|
18
20
|
const url = new URL(`/assets/${id}/${filename_download ?? filenameDownload ?? ""}`, `${protocol}://${hostname}`);
|
|
19
|
-
if (port
|
|
20
|
-
|
|
21
|
+
if (port != null && port !== "")
|
|
22
|
+
url.port = port;
|
|
23
|
+
if (searchParams != null)
|
|
24
|
+
setSearchParams(url, searchParams);
|
|
21
25
|
return url;
|
|
22
26
|
} catch (error) {
|
|
23
27
|
logger.logger.log("Couldn't create URL", "warn", { error });
|
|
@@ -26,9 +30,11 @@ function getDirectusUrl(file, baseUrl, searchParams) {
|
|
|
26
30
|
}
|
|
27
31
|
function getDirectusFile(file, baseUrl, searchParams) {
|
|
28
32
|
const { description, width, height, title, id, ...rest } = file ?? {};
|
|
29
|
-
if (
|
|
33
|
+
if (file == null || id == null || id === "")
|
|
34
|
+
return null;
|
|
30
35
|
const url = getDirectusUrl(file, baseUrl, searchParams);
|
|
31
|
-
if (
|
|
36
|
+
if (url == null)
|
|
37
|
+
return null;
|
|
32
38
|
return {
|
|
33
39
|
src: url.href,
|
|
34
40
|
alt: description ?? "",
|
|
@@ -4,18 +4,22 @@ const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
|
|
|
4
4
|
const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
|
|
5
5
|
function setSearchParams(url, searchParams) {
|
|
6
6
|
Object.entries(searchParams).forEach(([key, value]) => {
|
|
7
|
-
if (
|
|
7
|
+
if (value == null || value === "")
|
|
8
|
+
return;
|
|
8
9
|
url.searchParams.set(key, value);
|
|
9
10
|
});
|
|
10
11
|
}
|
|
11
12
|
function getDirectusUrl(file, baseUrl, searchParams) {
|
|
12
13
|
const { id, filename_download, filenameDownload } = file ?? {};
|
|
13
14
|
const { protocol = IMG_PROTOCOL, port = IMG_PORT, hostname = IMG_DOMAIN } = baseUrl ?? {};
|
|
14
|
-
if (
|
|
15
|
+
if (hostname == null || hostname === "" || id == null || id === "")
|
|
16
|
+
return null;
|
|
15
17
|
try {
|
|
16
18
|
const url = new URL(`/assets/${id}/${filename_download ?? filenameDownload ?? ""}`, `${protocol}://${hostname}`);
|
|
17
|
-
if (port
|
|
18
|
-
|
|
19
|
+
if (port != null && port !== "")
|
|
20
|
+
url.port = port;
|
|
21
|
+
if (searchParams != null)
|
|
22
|
+
setSearchParams(url, searchParams);
|
|
19
23
|
return url;
|
|
20
24
|
} catch (error) {
|
|
21
25
|
logger.log("Couldn't create URL", "warn", { error });
|
|
@@ -24,9 +28,11 @@ function getDirectusUrl(file, baseUrl, searchParams) {
|
|
|
24
28
|
}
|
|
25
29
|
function getDirectusFile(file, baseUrl, searchParams) {
|
|
26
30
|
const { description, width, height, title, id, ...rest } = file ?? {};
|
|
27
|
-
if (
|
|
31
|
+
if (file == null || id == null || id === "")
|
|
32
|
+
return null;
|
|
28
33
|
const url = getDirectusUrl(file, baseUrl, searchParams);
|
|
29
|
-
if (
|
|
34
|
+
if (url == null)
|
|
35
|
+
return null;
|
|
30
36
|
return {
|
|
31
37
|
src: url.href,
|
|
32
38
|
alt: description ?? "",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Link = require("next/link
|
|
3
|
+
const Link = require("next/link");
|
|
4
4
|
const zod = require("zod");
|
|
5
5
|
const index = require("../getDirectusFile/index.js");
|
|
6
6
|
const index$1 = require("../getDirectusSearchParams/index.js");
|
|
@@ -11,7 +11,7 @@ const relativeUrlSchema = zod.z.string().regex(/^[/#?]/, {
|
|
|
11
11
|
const hrefSchema = zod.z.union([absoluteUrlSchema, relativeUrlSchema]).transform((value) => {
|
|
12
12
|
try {
|
|
13
13
|
return new URL(value);
|
|
14
|
-
} catch
|
|
14
|
+
} catch {
|
|
15
15
|
return new URL(value, "http://localhost");
|
|
16
16
|
}
|
|
17
17
|
});
|
|
@@ -22,7 +22,8 @@ function withSearchParams(url, searchParams) {
|
|
|
22
22
|
return url;
|
|
23
23
|
}
|
|
24
24
|
function getCompleteHref(href, params, type) {
|
|
25
|
-
if (
|
|
25
|
+
if (href == null || href === "")
|
|
26
|
+
return null;
|
|
26
27
|
const searchParams = index$1.getDirectusSearchParams(params);
|
|
27
28
|
const url = hrefSchema.parse(href);
|
|
28
29
|
const completeUrl = withSearchParams(url, searchParams);
|
|
@@ -46,9 +47,8 @@ function getFile(props) {
|
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
function getCollection(props) {
|
|
49
|
-
var _a, _b;
|
|
50
50
|
const { collection, target, params } = props;
|
|
51
|
-
const href = getCompleteHref(
|
|
51
|
+
const href = getCompleteHref(collection?.translations?.[0]?.path, params, "relative");
|
|
52
52
|
return {
|
|
53
53
|
href: href ?? void 0,
|
|
54
54
|
target: target ?? void 0
|
|
@@ -68,14 +68,12 @@ function getAnchor(props) {
|
|
|
68
68
|
return { href: href ?? void 0 };
|
|
69
69
|
}
|
|
70
70
|
const defaultPropsConfig = {
|
|
71
|
-
collection: getCollection,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
71
|
+
"collection": getCollection,
|
|
73
72
|
"external-link": getExternalLink,
|
|
74
|
-
file: getFile,
|
|
75
|
-
anchor: getAnchor
|
|
73
|
+
"file": getFile,
|
|
74
|
+
"anchor": getAnchor
|
|
76
75
|
};
|
|
77
76
|
function getDirectusLink(props) {
|
|
78
|
-
var _a;
|
|
79
77
|
const {
|
|
80
78
|
type,
|
|
81
79
|
label,
|
|
@@ -96,17 +94,19 @@ function getDirectusLink(props) {
|
|
|
96
94
|
params,
|
|
97
95
|
...rest
|
|
98
96
|
} = props;
|
|
99
|
-
if (
|
|
97
|
+
if (type == null || type === "")
|
|
98
|
+
return {};
|
|
100
99
|
const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
|
|
101
|
-
const linkProps =
|
|
100
|
+
const linkProps = finalConfig[type]?.(props) ?? {};
|
|
102
101
|
const { href, ...restOfLinkProps } = linkProps;
|
|
103
|
-
if (
|
|
102
|
+
if (href == null || href === "")
|
|
103
|
+
return {};
|
|
104
104
|
return {
|
|
105
105
|
...rest,
|
|
106
106
|
as,
|
|
107
|
-
...themeName ? { themeName } : {},
|
|
108
|
-
...customTheme ? { customTheme } : {},
|
|
109
|
-
...tokens ? { tokens } : {},
|
|
107
|
+
...themeName != null ? { themeName } : {},
|
|
108
|
+
...customTheme != null ? { customTheme } : {},
|
|
109
|
+
...tokens != null ? { tokens } : {},
|
|
110
110
|
nextLinkProps: {
|
|
111
111
|
href,
|
|
112
112
|
prefetch: prefetch ?? void 0,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Link from "next/link
|
|
1
|
+
import Link from "next/link";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { getDirectusFile } from "../getDirectusFile/index.mjs";
|
|
4
4
|
import { getDirectusSearchParams } from "../getDirectusSearchParams/index.mjs";
|
|
@@ -9,7 +9,7 @@ const relativeUrlSchema = z.string().regex(/^[/#?]/, {
|
|
|
9
9
|
const hrefSchema = z.union([absoluteUrlSchema, relativeUrlSchema]).transform((value) => {
|
|
10
10
|
try {
|
|
11
11
|
return new URL(value);
|
|
12
|
-
} catch
|
|
12
|
+
} catch {
|
|
13
13
|
return new URL(value, "http://localhost");
|
|
14
14
|
}
|
|
15
15
|
});
|
|
@@ -20,7 +20,8 @@ function withSearchParams(url, searchParams) {
|
|
|
20
20
|
return url;
|
|
21
21
|
}
|
|
22
22
|
function getCompleteHref(href, params, type) {
|
|
23
|
-
if (
|
|
23
|
+
if (href == null || href === "")
|
|
24
|
+
return null;
|
|
24
25
|
const searchParams = getDirectusSearchParams(params);
|
|
25
26
|
const url = hrefSchema.parse(href);
|
|
26
27
|
const completeUrl = withSearchParams(url, searchParams);
|
|
@@ -44,9 +45,8 @@ function getFile(props) {
|
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
function getCollection(props) {
|
|
47
|
-
var _a, _b;
|
|
48
48
|
const { collection, target, params } = props;
|
|
49
|
-
const href = getCompleteHref(
|
|
49
|
+
const href = getCompleteHref(collection?.translations?.[0]?.path, params, "relative");
|
|
50
50
|
return {
|
|
51
51
|
href: href ?? void 0,
|
|
52
52
|
target: target ?? void 0
|
|
@@ -66,14 +66,12 @@ function getAnchor(props) {
|
|
|
66
66
|
return { href: href ?? void 0 };
|
|
67
67
|
}
|
|
68
68
|
const defaultPropsConfig = {
|
|
69
|
-
collection: getCollection,
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
69
|
+
"collection": getCollection,
|
|
71
70
|
"external-link": getExternalLink,
|
|
72
|
-
file: getFile,
|
|
73
|
-
anchor: getAnchor
|
|
71
|
+
"file": getFile,
|
|
72
|
+
"anchor": getAnchor
|
|
74
73
|
};
|
|
75
74
|
function getDirectusLink(props) {
|
|
76
|
-
var _a;
|
|
77
75
|
const {
|
|
78
76
|
type,
|
|
79
77
|
label,
|
|
@@ -94,17 +92,19 @@ function getDirectusLink(props) {
|
|
|
94
92
|
params,
|
|
95
93
|
...rest
|
|
96
94
|
} = props;
|
|
97
|
-
if (
|
|
95
|
+
if (type == null || type === "")
|
|
96
|
+
return {};
|
|
98
97
|
const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
|
|
99
|
-
const linkProps =
|
|
98
|
+
const linkProps = finalConfig[type]?.(props) ?? {};
|
|
100
99
|
const { href, ...restOfLinkProps } = linkProps;
|
|
101
|
-
if (
|
|
100
|
+
if (href == null || href === "")
|
|
101
|
+
return {};
|
|
102
102
|
return {
|
|
103
103
|
...rest,
|
|
104
104
|
as,
|
|
105
|
-
...themeName ? { themeName } : {},
|
|
106
|
-
...customTheme ? { customTheme } : {},
|
|
107
|
-
...tokens ? { tokens } : {},
|
|
105
|
+
...themeName != null ? { themeName } : {},
|
|
106
|
+
...customTheme != null ? { customTheme } : {},
|
|
107
|
+
...tokens != null ? { tokens } : {},
|
|
108
108
|
nextLinkProps: {
|
|
109
109
|
href,
|
|
110
110
|
prefetch: prefetch ?? void 0,
|
|
@@ -4,7 +4,6 @@ import { Metadata } from 'next';
|
|
|
4
4
|
import { OpenGraph } from 'next/dist/lib/metadata/types/opengraph-types';
|
|
5
5
|
import { TDirectusFileProps } from '../../components/DirectusFile/interface';
|
|
6
6
|
import { TMetadataOptions } from '../../types/metadata';
|
|
7
|
-
|
|
8
7
|
export declare function getOpenGraphImage(image: Nullable<TDirectusFileProps>, options: TMetadataOptions): Nullable<Exclude<OpenGraph['images'], OpenGraph['images'][]>>;
|
|
9
8
|
export declare function getMetadata<TPageProps extends {
|
|
10
9
|
pageSettings: TPageSettings;
|
|
@@ -3,38 +3,39 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const radashi = require("radashi");
|
|
4
4
|
const index = require("../getDirectusFile/index.js");
|
|
5
5
|
function withFallbacks(pageProps, options) {
|
|
6
|
-
var _a, _b;
|
|
7
6
|
const { pageSettings } = pageProps ?? {};
|
|
8
|
-
const pageSettingsTranslation =
|
|
9
|
-
const itemTranslation =
|
|
10
|
-
const title =
|
|
11
|
-
const imageFragment =
|
|
7
|
+
const pageSettingsTranslation = pageSettings?.translations?.[0] ?? void 0;
|
|
8
|
+
const itemTranslation = pageSettings?.translations?.[0];
|
|
9
|
+
const title = pageSettingsTranslation?.title ?? itemTranslation?.title;
|
|
10
|
+
const imageFragment = pageSettingsTranslation?.og_image ?? (itemTranslation != null && "featured_image" in itemTranslation ? itemTranslation.featured_image : {});
|
|
12
11
|
const image = options.getFilesFragment(imageFragment);
|
|
13
12
|
return { title, image };
|
|
14
13
|
}
|
|
15
14
|
function limitOpenGraphImageDimensions(width, height, maxWidth, maxHeight) {
|
|
16
15
|
return {
|
|
17
|
-
width: radashi.min([parseInt(width.toString(), 10), maxWidth]),
|
|
18
|
-
height: radashi.min([parseInt(height.toString(), 10), maxHeight])
|
|
16
|
+
width: radashi.min([Number.parseInt(width.toString(), 10), maxWidth]),
|
|
17
|
+
height: radashi.min([Number.parseInt(height.toString(), 10), maxHeight])
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
function getOpenGraphImageFallback(fallbackImage, options) {
|
|
22
|
-
if (
|
|
21
|
+
if (fallbackImage == null)
|
|
22
|
+
return null;
|
|
23
23
|
const { width, height, src } = fallbackImage;
|
|
24
|
-
const dimensions = limitOpenGraphImageDimensions(width, height, options
|
|
24
|
+
const dimensions = limitOpenGraphImageDimensions(width, height, options?.ogImageMaxWidth, options?.ogImageMaxHeight);
|
|
25
25
|
return { ...fallbackImage, ...dimensions, url: src };
|
|
26
26
|
}
|
|
27
27
|
function getOpenGraphImage(image, options) {
|
|
28
28
|
const directusImage = index.getDirectusFile(image);
|
|
29
29
|
const { src, alt } = directusImage ?? {};
|
|
30
|
-
const { width: limitedWidth, height: limitedHeight } = (
|
|
30
|
+
const { width: limitedWidth, height: limitedHeight } = (directusImage?.width != null && directusImage.width !== 0 && directusImage?.height != null && directusImage.height !== 0 ? limitOpenGraphImageDimensions(
|
|
31
31
|
directusImage.width,
|
|
32
32
|
directusImage.height,
|
|
33
|
-
options
|
|
34
|
-
options
|
|
33
|
+
options?.ogImageMaxWidth,
|
|
34
|
+
options?.ogImageMaxHeight
|
|
35
35
|
) : null) ?? {};
|
|
36
|
-
if (
|
|
37
|
-
|
|
36
|
+
if (src == null || src === "" || directusImage?.width == null || directusImage.width === 0)
|
|
37
|
+
return null;
|
|
38
|
+
const imgHref = options?.imageLoader({
|
|
38
39
|
...image,
|
|
39
40
|
src,
|
|
40
41
|
width: limitedWidth,
|
|
@@ -42,23 +43,22 @@ function getOpenGraphImage(image, options) {
|
|
|
42
43
|
});
|
|
43
44
|
return {
|
|
44
45
|
alt,
|
|
45
|
-
type:
|
|
46
|
+
type: directusImage?.type ?? void 0,
|
|
46
47
|
width: limitedWidth,
|
|
47
48
|
height: limitedHeight,
|
|
48
49
|
url: imgHref
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
function getMetadata(pageProps, options, defaultProps) {
|
|
52
|
-
var _a;
|
|
53
53
|
const { title, image } = withFallbacks(pageProps, options);
|
|
54
54
|
const { pageSettings } = pageProps ?? {};
|
|
55
|
-
const translation =
|
|
56
|
-
const metaDescription =
|
|
57
|
-
const noFollow =
|
|
58
|
-
const noIndex =
|
|
55
|
+
const translation = pageSettings?.translations?.[0];
|
|
56
|
+
const metaDescription = defaultProps?.meta_description ?? translation?.meta_description;
|
|
57
|
+
const noFollow = defaultProps?.no_follow ?? translation?.no_follow;
|
|
58
|
+
const noIndex = defaultProps?.no_index ?? translation?.no_index;
|
|
59
59
|
const directusImage = index.getDirectusFile(image);
|
|
60
|
-
const openGraphImage = getOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options
|
|
61
|
-
const openGraphType = options.openGraphTypeConfig[
|
|
60
|
+
const openGraphImage = getOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options?.ogFallbackImage, options);
|
|
61
|
+
const openGraphType = options.openGraphTypeConfig[pageSettings?.belongs_to_collection ?? ""] ?? "website";
|
|
62
62
|
const alternates = options.createAlternateUrls(pageSettings);
|
|
63
63
|
const { canonical } = alternates;
|
|
64
64
|
const metadata = {
|
|
@@ -69,7 +69,7 @@ function getMetadata(pageProps, options, defaultProps) {
|
|
|
69
69
|
title: title ?? void 0,
|
|
70
70
|
description: metaDescription ?? void 0,
|
|
71
71
|
images: openGraphImage ?? void 0,
|
|
72
|
-
url: canonical
|
|
72
|
+
url: canonical?.toString(),
|
|
73
73
|
type: openGraphType
|
|
74
74
|
},
|
|
75
75
|
twitter: {
|
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
import { min } from "radashi";
|
|
2
2
|
import { getDirectusFile } from "../getDirectusFile/index.mjs";
|
|
3
3
|
function withFallbacks(pageProps, options) {
|
|
4
|
-
var _a, _b;
|
|
5
4
|
const { pageSettings } = pageProps ?? {};
|
|
6
|
-
const pageSettingsTranslation =
|
|
7
|
-
const itemTranslation =
|
|
8
|
-
const title =
|
|
9
|
-
const imageFragment =
|
|
5
|
+
const pageSettingsTranslation = pageSettings?.translations?.[0] ?? void 0;
|
|
6
|
+
const itemTranslation = pageSettings?.translations?.[0];
|
|
7
|
+
const title = pageSettingsTranslation?.title ?? itemTranslation?.title;
|
|
8
|
+
const imageFragment = pageSettingsTranslation?.og_image ?? (itemTranslation != null && "featured_image" in itemTranslation ? itemTranslation.featured_image : {});
|
|
10
9
|
const image = options.getFilesFragment(imageFragment);
|
|
11
10
|
return { title, image };
|
|
12
11
|
}
|
|
13
12
|
function limitOpenGraphImageDimensions(width, height, maxWidth, maxHeight) {
|
|
14
13
|
return {
|
|
15
|
-
width: min([parseInt(width.toString(), 10), maxWidth]),
|
|
16
|
-
height: min([parseInt(height.toString(), 10), maxHeight])
|
|
14
|
+
width: min([Number.parseInt(width.toString(), 10), maxWidth]),
|
|
15
|
+
height: min([Number.parseInt(height.toString(), 10), maxHeight])
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
18
|
function getOpenGraphImageFallback(fallbackImage, options) {
|
|
20
|
-
if (
|
|
19
|
+
if (fallbackImage == null)
|
|
20
|
+
return null;
|
|
21
21
|
const { width, height, src } = fallbackImage;
|
|
22
|
-
const dimensions = limitOpenGraphImageDimensions(width, height, options
|
|
22
|
+
const dimensions = limitOpenGraphImageDimensions(width, height, options?.ogImageMaxWidth, options?.ogImageMaxHeight);
|
|
23
23
|
return { ...fallbackImage, ...dimensions, url: src };
|
|
24
24
|
}
|
|
25
25
|
function getOpenGraphImage(image, options) {
|
|
26
26
|
const directusImage = getDirectusFile(image);
|
|
27
27
|
const { src, alt } = directusImage ?? {};
|
|
28
|
-
const { width: limitedWidth, height: limitedHeight } = (
|
|
28
|
+
const { width: limitedWidth, height: limitedHeight } = (directusImage?.width != null && directusImage.width !== 0 && directusImage?.height != null && directusImage.height !== 0 ? limitOpenGraphImageDimensions(
|
|
29
29
|
directusImage.width,
|
|
30
30
|
directusImage.height,
|
|
31
|
-
options
|
|
32
|
-
options
|
|
31
|
+
options?.ogImageMaxWidth,
|
|
32
|
+
options?.ogImageMaxHeight
|
|
33
33
|
) : null) ?? {};
|
|
34
|
-
if (
|
|
35
|
-
|
|
34
|
+
if (src == null || src === "" || directusImage?.width == null || directusImage.width === 0)
|
|
35
|
+
return null;
|
|
36
|
+
const imgHref = options?.imageLoader({
|
|
36
37
|
...image,
|
|
37
38
|
src,
|
|
38
39
|
width: limitedWidth,
|
|
@@ -40,23 +41,22 @@ function getOpenGraphImage(image, options) {
|
|
|
40
41
|
});
|
|
41
42
|
return {
|
|
42
43
|
alt,
|
|
43
|
-
type:
|
|
44
|
+
type: directusImage?.type ?? void 0,
|
|
44
45
|
width: limitedWidth,
|
|
45
46
|
height: limitedHeight,
|
|
46
47
|
url: imgHref
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
function getMetadata(pageProps, options, defaultProps) {
|
|
50
|
-
var _a;
|
|
51
51
|
const { title, image } = withFallbacks(pageProps, options);
|
|
52
52
|
const { pageSettings } = pageProps ?? {};
|
|
53
|
-
const translation =
|
|
54
|
-
const metaDescription =
|
|
55
|
-
const noFollow =
|
|
56
|
-
const noIndex =
|
|
53
|
+
const translation = pageSettings?.translations?.[0];
|
|
54
|
+
const metaDescription = defaultProps?.meta_description ?? translation?.meta_description;
|
|
55
|
+
const noFollow = defaultProps?.no_follow ?? translation?.no_follow;
|
|
56
|
+
const noIndex = defaultProps?.no_index ?? translation?.no_index;
|
|
57
57
|
const directusImage = getDirectusFile(image);
|
|
58
|
-
const openGraphImage = getOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options
|
|
59
|
-
const openGraphType = options.openGraphTypeConfig[
|
|
58
|
+
const openGraphImage = getOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options?.ogFallbackImage, options);
|
|
59
|
+
const openGraphType = options.openGraphTypeConfig[pageSettings?.belongs_to_collection ?? ""] ?? "website";
|
|
60
60
|
const alternates = options.createAlternateUrls(pageSettings);
|
|
61
61
|
const { canonical } = alternates;
|
|
62
62
|
const metadata = {
|
|
@@ -67,7 +67,7 @@ function getMetadata(pageProps, options, defaultProps) {
|
|
|
67
67
|
title: title ?? void 0,
|
|
68
68
|
description: metaDescription ?? void 0,
|
|
69
69
|
images: openGraphImage ?? void 0,
|
|
70
|
-
url: canonical
|
|
70
|
+
url: canonical?.toString(),
|
|
71
71
|
type: openGraphType
|
|
72
72
|
},
|
|
73
73
|
twitter: {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Nullable } from '@okam/stack-ui';
|
|
2
2
|
import { TSearchParams } from '../../types/links';
|
|
3
|
-
|
|
4
3
|
export declare function getDirectusSearchParams(params: Nullable<Nullable<TSearchParams>[]>): URLSearchParams;
|
|
5
4
|
/**
|
|
6
5
|
* @deprecated Use `getDirectusSearchParams` instead
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const radashi = require("radashi");
|
|
4
4
|
function getDirectusSearchParams(params) {
|
|
5
5
|
const searchParams = new URLSearchParams();
|
|
6
|
-
params
|
|
6
|
+
params?.forEach((param) => {
|
|
7
7
|
const { name, value } = param ?? {};
|
|
8
8
|
if (radashi.isEmpty(name) || radashi.isEmpty(value)) {
|
|
9
9
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isEmpty } from "radashi";
|
|
2
2
|
function getDirectusSearchParams(params) {
|
|
3
3
|
const searchParams = new URLSearchParams();
|
|
4
|
-
params
|
|
4
|
+
params?.forEach((param) => {
|
|
5
5
|
const { name, value } = param ?? {};
|
|
6
6
|
if (isEmpty(name) || isEmpty(value)) {
|
|
7
7
|
return;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Nullable } from '@okam/stack-ui';
|
|
2
2
|
import { TDirectusLinkProps } from '../../components/DirectusLink/interface';
|
|
3
3
|
import { TNavigationItems, TNavigationItemsTree } from '../../types/navigationItems';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
*
|
|
7
6
|
* @param navigationItems A tree of navigation items, with parents and children
|
|
8
7
|
* @param onNavigationItem Called when a navigation item is about to be added to the tree
|
|
9
8
|
* @returns A tree of navigation items with ready-to-use DirectusLink components
|
|
10
9
|
*/
|
|
11
|
-
export declare function getNavigationItems<Depth extends number, Link, Items extends TNavigationItems<Items, Link, Depth> = TNavigationItems<unknown, Link, Depth>>(items: Nullable<Nullable<TNavigationItems<Items, Link, Depth>>[]>, onNavigationItem: (
|
|
10
|
+
export declare function getNavigationItems<Depth extends number, Link, Items extends TNavigationItems<Items, Link, Depth> = TNavigationItems<unknown, Link, Depth>>(items: Nullable<Nullable<TNavigationItems<Items, Link, Depth>>[]>, onNavigationItem: (_item: Nullable<TNavigationItems<Items, Link, Depth>>) => Nullable<TDirectusLinkProps>): Nullable<Nullable<TNavigationItemsTree>[]>;
|
|
12
11
|
/**
|
|
13
12
|
* @deprecated Use `getNavigationItems` instead
|
|
14
13
|
*/
|
|
@@ -7,7 +7,7 @@ function createLinkProps(item, onNavigationItem) {
|
|
|
7
7
|
const link = onNavigationItem(item);
|
|
8
8
|
const linkTokens = {
|
|
9
9
|
...tokens,
|
|
10
|
-
...link
|
|
10
|
+
...link?.tokens,
|
|
11
11
|
type: variant
|
|
12
12
|
};
|
|
13
13
|
const linkProps = {
|
|
@@ -20,7 +20,8 @@ function createParentTree(item, onNavigationItem, depth = -1) {
|
|
|
20
20
|
const { parent } = item ?? {};
|
|
21
21
|
const linkProps = createLinkProps(item, onNavigationItem);
|
|
22
22
|
const { id } = linkProps ?? {};
|
|
23
|
-
if (!id)
|
|
23
|
+
if (!id)
|
|
24
|
+
return null;
|
|
24
25
|
return {
|
|
25
26
|
link: /* @__PURE__ */ jsxRuntime.jsx(index, { ...linkProps }),
|
|
26
27
|
linkProps,
|
|
@@ -32,20 +33,21 @@ function createChildrenTree(item, onNavigationItem, depth = 1) {
|
|
|
32
33
|
const { children } = item ?? {};
|
|
33
34
|
const linkProps = createLinkProps(item, onNavigationItem);
|
|
34
35
|
const { id } = linkProps ?? {};
|
|
35
|
-
if (!id)
|
|
36
|
+
if (!id)
|
|
37
|
+
return null;
|
|
36
38
|
return {
|
|
37
39
|
link: /* @__PURE__ */ jsxRuntime.jsx(index, { ...linkProps }),
|
|
38
40
|
linkProps,
|
|
39
|
-
children: children
|
|
41
|
+
children: children?.map((child) => createChildrenTree(child, onNavigationItem, depth + 1)),
|
|
40
42
|
depth
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
function getNavigationItems(items, onNavigationItem) {
|
|
44
|
-
const tree = items
|
|
46
|
+
const tree = items?.map((item) => {
|
|
45
47
|
const { children, parent } = item ?? {};
|
|
46
48
|
const linkProps = createLinkProps(item, onNavigationItem);
|
|
47
49
|
const parentTree = createParentTree(parent, onNavigationItem);
|
|
48
|
-
const childrenTree = children
|
|
50
|
+
const childrenTree = children?.map((child) => createChildrenTree(child, onNavigationItem));
|
|
49
51
|
return {
|
|
50
52
|
depth: 0,
|
|
51
53
|
parent: parentTree,
|
|
@@ -5,7 +5,7 @@ function createLinkProps(item, onNavigationItem) {
|
|
|
5
5
|
const link = onNavigationItem(item);
|
|
6
6
|
const linkTokens = {
|
|
7
7
|
...tokens,
|
|
8
|
-
...link
|
|
8
|
+
...link?.tokens,
|
|
9
9
|
type: variant
|
|
10
10
|
};
|
|
11
11
|
const linkProps = {
|
|
@@ -18,7 +18,8 @@ function createParentTree(item, onNavigationItem, depth = -1) {
|
|
|
18
18
|
const { parent } = item ?? {};
|
|
19
19
|
const linkProps = createLinkProps(item, onNavigationItem);
|
|
20
20
|
const { id } = linkProps ?? {};
|
|
21
|
-
if (!id)
|
|
21
|
+
if (!id)
|
|
22
|
+
return null;
|
|
22
23
|
return {
|
|
23
24
|
link: /* @__PURE__ */ jsx(DirectusLink, { ...linkProps }),
|
|
24
25
|
linkProps,
|
|
@@ -30,20 +31,21 @@ function createChildrenTree(item, onNavigationItem, depth = 1) {
|
|
|
30
31
|
const { children } = item ?? {};
|
|
31
32
|
const linkProps = createLinkProps(item, onNavigationItem);
|
|
32
33
|
const { id } = linkProps ?? {};
|
|
33
|
-
if (!id)
|
|
34
|
+
if (!id)
|
|
35
|
+
return null;
|
|
34
36
|
return {
|
|
35
37
|
link: /* @__PURE__ */ jsx(DirectusLink, { ...linkProps }),
|
|
36
38
|
linkProps,
|
|
37
|
-
children: children
|
|
39
|
+
children: children?.map((child) => createChildrenTree(child, onNavigationItem, depth + 1)),
|
|
38
40
|
depth
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
43
|
function getNavigationItems(items, onNavigationItem) {
|
|
42
|
-
const tree = items
|
|
44
|
+
const tree = items?.map((item) => {
|
|
43
45
|
const { children, parent } = item ?? {};
|
|
44
46
|
const linkProps = createLinkProps(item, onNavigationItem);
|
|
45
47
|
const parentTree = createParentTree(parent, onNavigationItem);
|
|
46
|
-
const childrenTree = children
|
|
48
|
+
const childrenTree = children?.map((child) => createChildrenTree(child, onNavigationItem));
|
|
47
49
|
return {
|
|
48
50
|
depth: 0,
|
|
49
51
|
parent: parentTree,
|