@okam/directus-next-component 1.7.35 → 1.7.37

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/components/DirectusFile/config.d.ts +3 -2
  4. package/components/DirectusFile/index.d.ts +2 -1
  5. package/components/DirectusFile/interface.d.ts +3 -2
  6. package/components/DirectusImg/index.d.ts +2 -1
  7. package/components/DirectusImg/index.js +2 -2
  8. package/components/DirectusImg/index.mjs +2 -2
  9. package/components/DirectusImg/interface.d.ts +2 -1
  10. package/components/DirectusLink/index.d.ts +2 -1
  11. package/components/DirectusLink/index.js +2 -2
  12. package/components/DirectusLink/index.mjs +2 -2
  13. package/components/DirectusLink/interface.d.ts +8 -7
  14. package/components/DirectusVideo/index.d.ts +2 -1
  15. package/components/DirectusVideo/index.js +2 -2
  16. package/components/DirectusVideo/index.mjs +2 -2
  17. package/components/DirectusVideo/interface.d.ts +3 -2
  18. package/index.d.ts +12 -11
  19. package/index.js +14 -10
  20. package/index.mjs +14 -10
  21. package/lib/directus-next-rewrite.d.ts +2 -2
  22. package/lib/withDirectus.d.ts +2 -1
  23. package/logger.d.ts +1 -1
  24. package/package.json +13 -7
  25. package/server.d.ts +4 -4
  26. package/server.js +12 -8
  27. package/server.mjs +12 -8
  28. package/types/index.d.ts +3 -0
  29. package/types/links.d.ts +5 -4
  30. package/types/metadata.d.ts +7 -6
  31. package/types/{navigation-items.d.ts → navigationItems.d.ts} +8 -7
  32. package/{hooks/directus-file.d.ts → utils/getDirectusFile/index.d.ts} +9 -3
  33. package/{hooks/directus-file.js → utils/getDirectusFile/index.js} +7 -3
  34. package/{hooks/directus-file.mjs → utils/getDirectusFile/index.mjs} +6 -3
  35. package/utils/getDirectusLink/index.d.ts +8 -0
  36. package/utils/getDirectusLink/index.js +123 -0
  37. package/utils/getDirectusLink/index.mjs +123 -0
  38. package/utils/getDirectusMetadata/index.d.ts +15 -0
  39. package/{hooks/directus-metadata.js → utils/getDirectusMetadata/index.js} +11 -12
  40. package/{hooks/directus-metadata.mjs → utils/getDirectusMetadata/index.mjs} +10 -12
  41. package/utils/getDirectusSearchParams/index.d.ts +8 -0
  42. package/{hooks/directus-search-params.js → utils/getDirectusSearchParams/index.js} +2 -1
  43. package/{hooks/directus-search-params.mjs → utils/getDirectusSearchParams/index.mjs} +1 -1
  44. package/utils/getNavigationItems/index.d.ts +15 -0
  45. package/{hooks/navigation-items.js → utils/getNavigationItems/index.js} +6 -3
  46. package/{hooks/navigation-items.mjs → utils/getNavigationItems/index.mjs} +5 -3
  47. package/hooks/directus-link.d.ts +0 -3
  48. package/hooks/directus-link.js +0 -94
  49. package/hooks/directus-link.mjs +0 -95
  50. package/hooks/directus-metadata.d.ts +0 -6
  51. package/hooks/directus-search-params.d.ts +0 -3
  52. package/hooks/navigation-items.d.ts +0 -10
@@ -1,4 +1,4 @@
1
- import { logger } from "../logger.mjs";
1
+ import { logger } from "../../logger.mjs";
2
2
  const IMG_DOMAIN = process.env.NEXT_PUBLIC_IMG_DOMAIN;
3
3
  const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
4
4
  const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
@@ -22,7 +22,7 @@ function getDirectusUrl(file, baseUrl, searchParams) {
22
22
  return null;
23
23
  }
24
24
  }
25
- function useDirectusFile(file, baseUrl, searchParams) {
25
+ function getDirectusFile(file, baseUrl, searchParams) {
26
26
  const { description, width, height, title, id, ...rest } = file ?? {};
27
27
  if (!file || !id) return null;
28
28
  const url = getDirectusUrl(file, baseUrl, searchParams);
@@ -37,6 +37,9 @@ function useDirectusFile(file, baseUrl, searchParams) {
37
37
  ...rest
38
38
  };
39
39
  }
40
+ const useDirectusFile = getDirectusFile;
40
41
  export {
41
- useDirectusFile as default
42
+ getDirectusFile,
43
+ getDirectusUrl,
44
+ useDirectusFile
42
45
  };
@@ -0,0 +1,8 @@
1
+ import { TAnchorProps } from '../../../../../stack/stack-ui/src/index.ts';
2
+ import { TGetDirectusLink } from '../../components/DirectusLink/interface';
3
+
4
+ export declare function getDirectusLink(props: TGetDirectusLink): TAnchorProps;
5
+ /**
6
+ * @deprecated Use `getDirectusLink` instead
7
+ */
8
+ export declare const useDirectusLink: typeof getDirectusLink;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const Link = require("next/link.js");
4
+ const zod = require("zod");
5
+ const index = require("../getDirectusFile/index.js");
6
+ const index$1 = require("../getDirectusSearchParams/index.js");
7
+ const absoluteUrlSchema = zod.z.url({ protocol: /^(https?|mailto|tel)$/ });
8
+ const relativeUrlSchema = zod.z.string().regex(/^[/#?]/, {
9
+ error: (error) => `Invalid href ${error.input}. Must be a valid absolute URL or start with /, # or ?`
10
+ });
11
+ const hrefSchema = zod.z.union([absoluteUrlSchema, relativeUrlSchema]).transform((value) => {
12
+ try {
13
+ return new URL(value);
14
+ } catch (error) {
15
+ return new URL(value, "http://localhost");
16
+ }
17
+ });
18
+ function withSearchParams(url, searchParams) {
19
+ searchParams.forEach((value, name) => {
20
+ url.searchParams.append(name, value);
21
+ });
22
+ return url;
23
+ }
24
+ function getCompleteHref(href, params, type) {
25
+ if (!href) return null;
26
+ const searchParams = index$1.getDirectusSearchParams(params);
27
+ const url = hrefSchema.parse(href);
28
+ const completeUrl = withSearchParams(url, searchParams);
29
+ if (type === "relative") {
30
+ const { origin } = completeUrl;
31
+ if (href.startsWith("#")) {
32
+ return completeUrl.href.replace(origin, "").substring(1);
33
+ }
34
+ return completeUrl.href.replace(origin, "");
35
+ }
36
+ return completeUrl.href;
37
+ }
38
+ function getFile(props) {
39
+ const { file, params } = props;
40
+ const { filename_download: filenameDownload } = file ?? {};
41
+ const { src } = index.getDirectusFile(file) ?? {};
42
+ const href = getCompleteHref(src, params, "absolute");
43
+ return {
44
+ href: href ?? void 0,
45
+ download: filenameDownload ?? true
46
+ };
47
+ }
48
+ function getCollection(props) {
49
+ var _a, _b;
50
+ const { collection, target, params } = props;
51
+ const href = getCompleteHref((_b = (_a = collection == null ? void 0 : collection.translations) == null ? void 0 : _a[0]) == null ? void 0 : _b.path, params, "relative");
52
+ return {
53
+ href: href ?? void 0,
54
+ target: target ?? void 0
55
+ };
56
+ }
57
+ function getExternalLink(props) {
58
+ const { external_link: externalLink, target, params } = props;
59
+ const href = getCompleteHref(externalLink, params, "absolute");
60
+ return {
61
+ href: href ?? void 0,
62
+ target: target ?? void 0
63
+ };
64
+ }
65
+ function getAnchor(props) {
66
+ const { anchor, params } = props;
67
+ const href = getCompleteHref(anchor, params, "relative");
68
+ return { href: href ?? void 0 };
69
+ }
70
+ const defaultPropsConfig = {
71
+ collection: getCollection,
72
+ // eslint-disable-next-line @typescript-eslint/naming-convention
73
+ "external-link": getExternalLink,
74
+ file: getFile,
75
+ anchor: getAnchor
76
+ };
77
+ function getDirectusLink(props) {
78
+ var _a;
79
+ const {
80
+ type,
81
+ label,
82
+ prefetch,
83
+ replace,
84
+ scroll,
85
+ tokens,
86
+ themeName,
87
+ customTheme,
88
+ propsConfig,
89
+ as = Link,
90
+ target,
91
+ anchor,
92
+ collection,
93
+ external_link: externalLink,
94
+ file,
95
+ id,
96
+ params,
97
+ ...rest
98
+ } = props;
99
+ if (!type) return {};
100
+ const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
101
+ const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
102
+ const { href, ...restOfLinkProps } = linkProps;
103
+ if (!href) return {};
104
+ return {
105
+ ...rest,
106
+ as,
107
+ ...themeName ? { themeName } : {},
108
+ ...customTheme ? { customTheme } : {},
109
+ ...tokens ? { tokens } : {},
110
+ nextLinkProps: {
111
+ href,
112
+ prefetch: prefetch ?? void 0,
113
+ scroll: scroll ?? void 0,
114
+ replace: replace ?? void 0
115
+ },
116
+ href,
117
+ children: label,
118
+ ...restOfLinkProps
119
+ };
120
+ }
121
+ const useDirectusLink = getDirectusLink;
122
+ exports.getDirectusLink = getDirectusLink;
123
+ exports.useDirectusLink = useDirectusLink;
@@ -0,0 +1,123 @@
1
+ import Link from "next/link.js";
2
+ import { z } from "zod";
3
+ import { getDirectusFile } from "../getDirectusFile/index.mjs";
4
+ import { getDirectusSearchParams } from "../getDirectusSearchParams/index.mjs";
5
+ const absoluteUrlSchema = z.url({ protocol: /^(https?|mailto|tel)$/ });
6
+ const relativeUrlSchema = z.string().regex(/^[/#?]/, {
7
+ error: (error) => `Invalid href ${error.input}. Must be a valid absolute URL or start with /, # or ?`
8
+ });
9
+ const hrefSchema = z.union([absoluteUrlSchema, relativeUrlSchema]).transform((value) => {
10
+ try {
11
+ return new URL(value);
12
+ } catch (error) {
13
+ return new URL(value, "http://localhost");
14
+ }
15
+ });
16
+ function withSearchParams(url, searchParams) {
17
+ searchParams.forEach((value, name) => {
18
+ url.searchParams.append(name, value);
19
+ });
20
+ return url;
21
+ }
22
+ function getCompleteHref(href, params, type) {
23
+ if (!href) return null;
24
+ const searchParams = getDirectusSearchParams(params);
25
+ const url = hrefSchema.parse(href);
26
+ const completeUrl = withSearchParams(url, searchParams);
27
+ if (type === "relative") {
28
+ const { origin } = completeUrl;
29
+ if (href.startsWith("#")) {
30
+ return completeUrl.href.replace(origin, "").substring(1);
31
+ }
32
+ return completeUrl.href.replace(origin, "");
33
+ }
34
+ return completeUrl.href;
35
+ }
36
+ function getFile(props) {
37
+ const { file, params } = props;
38
+ const { filename_download: filenameDownload } = file ?? {};
39
+ const { src } = getDirectusFile(file) ?? {};
40
+ const href = getCompleteHref(src, params, "absolute");
41
+ return {
42
+ href: href ?? void 0,
43
+ download: filenameDownload ?? true
44
+ };
45
+ }
46
+ function getCollection(props) {
47
+ var _a, _b;
48
+ const { collection, target, params } = props;
49
+ const href = getCompleteHref((_b = (_a = collection == null ? void 0 : collection.translations) == null ? void 0 : _a[0]) == null ? void 0 : _b.path, params, "relative");
50
+ return {
51
+ href: href ?? void 0,
52
+ target: target ?? void 0
53
+ };
54
+ }
55
+ function getExternalLink(props) {
56
+ const { external_link: externalLink, target, params } = props;
57
+ const href = getCompleteHref(externalLink, params, "absolute");
58
+ return {
59
+ href: href ?? void 0,
60
+ target: target ?? void 0
61
+ };
62
+ }
63
+ function getAnchor(props) {
64
+ const { anchor, params } = props;
65
+ const href = getCompleteHref(anchor, params, "relative");
66
+ return { href: href ?? void 0 };
67
+ }
68
+ const defaultPropsConfig = {
69
+ collection: getCollection,
70
+ // eslint-disable-next-line @typescript-eslint/naming-convention
71
+ "external-link": getExternalLink,
72
+ file: getFile,
73
+ anchor: getAnchor
74
+ };
75
+ function getDirectusLink(props) {
76
+ var _a;
77
+ const {
78
+ type,
79
+ label,
80
+ prefetch,
81
+ replace,
82
+ scroll,
83
+ tokens,
84
+ themeName,
85
+ customTheme,
86
+ propsConfig,
87
+ as = Link,
88
+ target,
89
+ anchor,
90
+ collection,
91
+ external_link: externalLink,
92
+ file,
93
+ id,
94
+ params,
95
+ ...rest
96
+ } = props;
97
+ if (!type) return {};
98
+ const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
99
+ const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
100
+ const { href, ...restOfLinkProps } = linkProps;
101
+ if (!href) return {};
102
+ return {
103
+ ...rest,
104
+ as,
105
+ ...themeName ? { themeName } : {},
106
+ ...customTheme ? { customTheme } : {},
107
+ ...tokens ? { tokens } : {},
108
+ nextLinkProps: {
109
+ href,
110
+ prefetch: prefetch ?? void 0,
111
+ scroll: scroll ?? void 0,
112
+ replace: replace ?? void 0
113
+ },
114
+ href,
115
+ children: label,
116
+ ...restOfLinkProps
117
+ };
118
+ }
119
+ const useDirectusLink = getDirectusLink;
120
+ export {
121
+ getDirectusLink,
122
+ useDirectusLink
123
+ };
@@ -0,0 +1,15 @@
1
+ import { TPageSettings, TPageSettingsTranslation } from '../../../../directus-next/src/index.ts';
2
+ import { Nullable } from '../../../../../stack/stack-ui/src/index.ts';
3
+ import { Metadata } from 'next';
4
+ import { OpenGraph } from 'next/dist/lib/metadata/types/opengraph-types';
5
+ import { TDirectusFileProps } from '../../components/DirectusFile/interface';
6
+ import { TMetadataOptions } from '../../types/metadata';
7
+
8
+ export declare function getOpenGraphImage(image: Nullable<TDirectusFileProps>, options: TMetadataOptions): Nullable<Exclude<OpenGraph['images'], OpenGraph['images'][]>>;
9
+ export declare function getMetadata<TPageProps extends {
10
+ pageSettings: TPageSettings;
11
+ }>(pageProps: TPageProps, options: TMetadataOptions, defaultProps?: Partial<TPageSettingsTranslation>): Metadata;
12
+ /**
13
+ * @deprecated Use `getMetadata` instead
14
+ */
15
+ export declare const useMetadata: typeof getMetadata;
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- require("react/jsx-runtime");
3
- require("@okam/next-component");
4
- const directusFile = require("./directus-file.js");
5
- require("@okam/stack-ui");
6
- require("next/link.js");
7
- require("../logger.js");
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
3
  const radashi = require("radashi");
4
+ const index = require("../getDirectusFile/index.js");
9
5
  function withFallbacks(pageProps, options) {
10
6
  var _a, _b;
11
7
  const { pageSettings } = pageProps ?? {};
@@ -28,8 +24,8 @@ function getOpenGraphImageFallback(fallbackImage, options) {
28
24
  const dimensions = limitOpenGraphImageDimensions(width, height, options == null ? void 0 : options.ogImageMaxWidth, options == null ? void 0 : options.ogImageMaxHeight);
29
25
  return { ...fallbackImage, ...dimensions, url: src };
30
26
  }
31
- function useOpenGraphImage(image, options) {
32
- const directusImage = directusFile(image);
27
+ function getOpenGraphImage(image, options) {
28
+ const directusImage = index.getDirectusFile(image);
33
29
  const { src, alt } = directusImage ?? {};
34
30
  const { width: limitedWidth, height: limitedHeight } = ((directusImage == null ? void 0 : directusImage.width) && (directusImage == null ? void 0 : directusImage.height) ? limitOpenGraphImageDimensions(
35
31
  directusImage.width,
@@ -52,7 +48,7 @@ function useOpenGraphImage(image, options) {
52
48
  url: imgHref
53
49
  };
54
50
  }
55
- function useMetadata(pageProps, options, defaultProps) {
51
+ function getMetadata(pageProps, options, defaultProps) {
56
52
  var _a;
57
53
  const { title, image } = withFallbacks(pageProps, options);
58
54
  const { pageSettings } = pageProps ?? {};
@@ -60,8 +56,8 @@ function useMetadata(pageProps, options, defaultProps) {
60
56
  const metaDescription = (defaultProps == null ? void 0 : defaultProps.meta_description) ?? (translation == null ? void 0 : translation.meta_description);
61
57
  const noFollow = (defaultProps == null ? void 0 : defaultProps.no_follow) ?? (translation == null ? void 0 : translation.no_follow);
62
58
  const noIndex = (defaultProps == null ? void 0 : defaultProps.no_index) ?? (translation == null ? void 0 : translation.no_index);
63
- const directusImage = directusFile(image);
64
- const openGraphImage = useOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options == null ? void 0 : options.ogFallbackImage, options);
59
+ const directusImage = index.getDirectusFile(image);
60
+ const openGraphImage = getOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options == null ? void 0 : options.ogFallbackImage, options);
65
61
  const openGraphType = options.openGraphTypeConfig[(pageSettings == null ? void 0 : pageSettings.belongs_to_collection) ?? ""] ?? "website";
66
62
  const alternates = options.createAlternateUrls(pageSettings);
67
63
  const { canonical } = alternates;
@@ -89,4 +85,7 @@ function useMetadata(pageProps, options, defaultProps) {
89
85
  };
90
86
  return metadata;
91
87
  }
92
- module.exports = useMetadata;
88
+ const useMetadata = getMetadata;
89
+ exports.getMetadata = getMetadata;
90
+ exports.getOpenGraphImage = getOpenGraphImage;
91
+ exports.useMetadata = useMetadata;
@@ -1,10 +1,5 @@
1
- import "react/jsx-runtime";
2
- import "@okam/next-component";
3
- import useDirectusFile from "./directus-file.mjs";
4
- import "@okam/stack-ui";
5
- import "next/link.js";
6
- import "../logger.mjs";
7
1
  import { min } from "radashi";
2
+ import { getDirectusFile } from "../getDirectusFile/index.mjs";
8
3
  function withFallbacks(pageProps, options) {
9
4
  var _a, _b;
10
5
  const { pageSettings } = pageProps ?? {};
@@ -27,8 +22,8 @@ function getOpenGraphImageFallback(fallbackImage, options) {
27
22
  const dimensions = limitOpenGraphImageDimensions(width, height, options == null ? void 0 : options.ogImageMaxWidth, options == null ? void 0 : options.ogImageMaxHeight);
28
23
  return { ...fallbackImage, ...dimensions, url: src };
29
24
  }
30
- function useOpenGraphImage(image, options) {
31
- const directusImage = useDirectusFile(image);
25
+ function getOpenGraphImage(image, options) {
26
+ const directusImage = getDirectusFile(image);
32
27
  const { src, alt } = directusImage ?? {};
33
28
  const { width: limitedWidth, height: limitedHeight } = ((directusImage == null ? void 0 : directusImage.width) && (directusImage == null ? void 0 : directusImage.height) ? limitOpenGraphImageDimensions(
34
29
  directusImage.width,
@@ -51,7 +46,7 @@ function useOpenGraphImage(image, options) {
51
46
  url: imgHref
52
47
  };
53
48
  }
54
- function useMetadata(pageProps, options, defaultProps) {
49
+ function getMetadata(pageProps, options, defaultProps) {
55
50
  var _a;
56
51
  const { title, image } = withFallbacks(pageProps, options);
57
52
  const { pageSettings } = pageProps ?? {};
@@ -59,8 +54,8 @@ function useMetadata(pageProps, options, defaultProps) {
59
54
  const metaDescription = (defaultProps == null ? void 0 : defaultProps.meta_description) ?? (translation == null ? void 0 : translation.meta_description);
60
55
  const noFollow = (defaultProps == null ? void 0 : defaultProps.no_follow) ?? (translation == null ? void 0 : translation.no_follow);
61
56
  const noIndex = (defaultProps == null ? void 0 : defaultProps.no_index) ?? (translation == null ? void 0 : translation.no_index);
62
- const directusImage = useDirectusFile(image);
63
- const openGraphImage = useOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options == null ? void 0 : options.ogFallbackImage, options);
57
+ const directusImage = getDirectusFile(image);
58
+ const openGraphImage = getOpenGraphImage(directusImage, options) ?? getOpenGraphImageFallback(options == null ? void 0 : options.ogFallbackImage, options);
64
59
  const openGraphType = options.openGraphTypeConfig[(pageSettings == null ? void 0 : pageSettings.belongs_to_collection) ?? ""] ?? "website";
65
60
  const alternates = options.createAlternateUrls(pageSettings);
66
61
  const { canonical } = alternates;
@@ -88,6 +83,9 @@ function useMetadata(pageProps, options, defaultProps) {
88
83
  };
89
84
  return metadata;
90
85
  }
86
+ const useMetadata = getMetadata;
91
87
  export {
92
- useMetadata as default
88
+ getMetadata,
89
+ getOpenGraphImage,
90
+ useMetadata
93
91
  };
@@ -0,0 +1,8 @@
1
+ import { Nullable } from '../../../../../stack/stack-ui/src/index.ts';
2
+ import { TSearchParams } from '../../types/links';
3
+
4
+ export declare function getDirectusSearchParams(params: Nullable<Nullable<TSearchParams>[]>): URLSearchParams;
5
+ /**
6
+ * @deprecated Use `getDirectusSearchParams` instead
7
+ */
8
+ export declare const useDirectusSearchParams: typeof getDirectusSearchParams;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
3
  const radashi = require("radashi");
3
4
  function getDirectusSearchParams(params) {
4
5
  const searchParams = new URLSearchParams();
@@ -11,4 +12,4 @@ function getDirectusSearchParams(params) {
11
12
  });
12
13
  return searchParams;
13
14
  }
14
- module.exports = getDirectusSearchParams;
15
+ exports.getDirectusSearchParams = getDirectusSearchParams;
@@ -11,5 +11,5 @@ function getDirectusSearchParams(params) {
11
11
  return searchParams;
12
12
  }
13
13
  export {
14
- getDirectusSearchParams as default
14
+ getDirectusSearchParams
15
15
  };
@@ -0,0 +1,15 @@
1
+ import { Nullable } from '../../../../../stack/stack-ui/src/index.ts';
2
+ import { TDirectusLinkProps } from '../../components/DirectusLink/interface';
3
+ import { TNavigationItems, TNavigationItemsTree } from '../../types/navigationItems';
4
+
5
+ /**
6
+ *
7
+ * @param navigationItems A tree of navigation items, with parents and children
8
+ * @param onNavigationItem Called when a navigation item is about to be added to the tree
9
+ * @returns A tree of navigation items with ready-to-use DirectusLink components
10
+ */
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: (item: Nullable<TNavigationItems<Items, Link, Depth>>) => Nullable<TDirectusLinkProps>): Nullable<Nullable<TNavigationItemsTree>[]>;
12
+ /**
13
+ * @deprecated Use `getNavigationItems` instead
14
+ */
15
+ export declare const useNavigationItems: typeof getNavigationItems;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
3
  const jsxRuntime = require("react/jsx-runtime");
3
- const index = require("../components/DirectusLink/index.js");
4
+ const index = require("../../components/DirectusLink/index.js");
4
5
  function createLinkProps(item, onNavigationItem) {
5
6
  const { tokens, variant } = item ?? {};
6
7
  const link = onNavigationItem(item);
@@ -39,7 +40,7 @@ function createChildrenTree(item, onNavigationItem, depth = 1) {
39
40
  depth
40
41
  };
41
42
  }
42
- function useNavigationItems(items, onNavigationItem) {
43
+ function getNavigationItems(items, onNavigationItem) {
43
44
  const tree = items == null ? void 0 : items.map((item) => {
44
45
  const { children, parent } = item ?? {};
45
46
  const linkProps = createLinkProps(item, onNavigationItem);
@@ -55,4 +56,6 @@ function useNavigationItems(items, onNavigationItem) {
55
56
  });
56
57
  return tree;
57
58
  }
58
- module.exports = useNavigationItems;
59
+ const useNavigationItems = getNavigationItems;
60
+ exports.getNavigationItems = getNavigationItems;
61
+ exports.useNavigationItems = useNavigationItems;
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import DirectusLink from "../components/DirectusLink/index.mjs";
2
+ import DirectusLink from "../../components/DirectusLink/index.mjs";
3
3
  function createLinkProps(item, onNavigationItem) {
4
4
  const { tokens, variant } = item ?? {};
5
5
  const link = onNavigationItem(item);
@@ -38,7 +38,7 @@ function createChildrenTree(item, onNavigationItem, depth = 1) {
38
38
  depth
39
39
  };
40
40
  }
41
- function useNavigationItems(items, onNavigationItem) {
41
+ function getNavigationItems(items, onNavigationItem) {
42
42
  const tree = items == null ? void 0 : items.map((item) => {
43
43
  const { children, parent } = item ?? {};
44
44
  const linkProps = createLinkProps(item, onNavigationItem);
@@ -54,6 +54,8 @@ function useNavigationItems(items, onNavigationItem) {
54
54
  });
55
55
  return tree;
56
56
  }
57
+ const useNavigationItems = getNavigationItems;
57
58
  export {
58
- useNavigationItems as default
59
+ getNavigationItems,
60
+ useNavigationItems
59
61
  };
@@ -1,3 +0,0 @@
1
- import type { TAnchorProps } from '@okam/stack-ui';
2
- import type { TUseDirectusLink } from '../components/DirectusLink/interface';
3
- export default function useDirectusLink(props: TUseDirectusLink): TAnchorProps;
@@ -1,94 +0,0 @@
1
- "use strict";
2
- const Link = require("next/link.js");
3
- const logger = require("../logger.js");
4
- const directusFile = require("./directus-file.js");
5
- const directusSearchParams = require("./directus-search-params.js");
6
- function useFile(props) {
7
- const { file } = props;
8
- const { filename_download: filenameDownload } = file ?? {};
9
- const { src } = directusFile(file) ?? {};
10
- return {
11
- href: src,
12
- download: filenameDownload ?? true
13
- };
14
- }
15
- function useCollection(props) {
16
- var _a, _b;
17
- const { collection, target } = props;
18
- return {
19
- href: ((_b = (_a = collection == null ? void 0 : collection.translations) == null ? void 0 : _a[0]) == null ? void 0 : _b.path) ?? void 0,
20
- target: target ?? void 0
21
- };
22
- }
23
- function useExternalLink(props) {
24
- const { external_link: externalLink, target } = props;
25
- return {
26
- href: externalLink ?? void 0,
27
- target: target ?? void 0
28
- };
29
- }
30
- function useAnchor(props) {
31
- const { anchor } = props;
32
- return { href: anchor ?? void 0 };
33
- }
34
- const defaultPropsConfig = {
35
- collection: useCollection,
36
- // eslint-disable-next-line @typescript-eslint/naming-convention
37
- "external-link": useExternalLink,
38
- file: useFile,
39
- anchor: useAnchor
40
- };
41
- function useDirectusLink(props) {
42
- var _a;
43
- const {
44
- type,
45
- label,
46
- prefetch,
47
- replace,
48
- scroll,
49
- tokens,
50
- themeName,
51
- customTheme,
52
- propsConfig,
53
- as = Link,
54
- target,
55
- anchor,
56
- collection,
57
- external_link: externalLink,
58
- file,
59
- id,
60
- params,
61
- ...rest
62
- } = props;
63
- const searchParams = directusSearchParams(params);
64
- if (!type) return {};
65
- const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
66
- const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
67
- const { href, ...restOfLinkProps } = linkProps;
68
- if (!href) return {};
69
- if (!URL.canParse(href)) {
70
- logger.logger.log("Invalid href", "error", { href });
71
- return {};
72
- }
73
- const hrefUrl = new URL(href);
74
- searchParams.forEach((value, name) => {
75
- hrefUrl.searchParams.append(name, value);
76
- });
77
- return {
78
- ...rest,
79
- as,
80
- ...themeName ? { themeName } : {},
81
- ...customTheme ? { customTheme } : {},
82
- ...tokens ? { tokens } : {},
83
- nextLinkProps: {
84
- href: hrefUrl.toString(),
85
- prefetch: prefetch ?? void 0,
86
- scroll: scroll ?? void 0,
87
- replace: replace ?? void 0
88
- },
89
- href: hrefUrl.toString(),
90
- children: label,
91
- ...restOfLinkProps
92
- };
93
- }
94
- module.exports = useDirectusLink;