@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,95 +0,0 @@
1
- import Link from "next/link.js";
2
- import { logger } from "../logger.mjs";
3
- import useDirectusFile from "./directus-file.mjs";
4
- import getDirectusSearchParams from "./directus-search-params.mjs";
5
- function useFile(props) {
6
- const { file } = props;
7
- const { filename_download: filenameDownload } = file ?? {};
8
- const { src } = useDirectusFile(file) ?? {};
9
- return {
10
- href: src,
11
- download: filenameDownload ?? true
12
- };
13
- }
14
- function useCollection(props) {
15
- var _a, _b;
16
- const { collection, target } = props;
17
- return {
18
- href: ((_b = (_a = collection == null ? void 0 : collection.translations) == null ? void 0 : _a[0]) == null ? void 0 : _b.path) ?? void 0,
19
- target: target ?? void 0
20
- };
21
- }
22
- function useExternalLink(props) {
23
- const { external_link: externalLink, target } = props;
24
- return {
25
- href: externalLink ?? void 0,
26
- target: target ?? void 0
27
- };
28
- }
29
- function useAnchor(props) {
30
- const { anchor } = props;
31
- return { href: anchor ?? void 0 };
32
- }
33
- const defaultPropsConfig = {
34
- collection: useCollection,
35
- // eslint-disable-next-line @typescript-eslint/naming-convention
36
- "external-link": useExternalLink,
37
- file: useFile,
38
- anchor: useAnchor
39
- };
40
- function useDirectusLink(props) {
41
- var _a;
42
- const {
43
- type,
44
- label,
45
- prefetch,
46
- replace,
47
- scroll,
48
- tokens,
49
- themeName,
50
- customTheme,
51
- propsConfig,
52
- as = Link,
53
- target,
54
- anchor,
55
- collection,
56
- external_link: externalLink,
57
- file,
58
- id,
59
- params,
60
- ...rest
61
- } = props;
62
- const searchParams = getDirectusSearchParams(params);
63
- if (!type) return {};
64
- const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
65
- const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
66
- const { href, ...restOfLinkProps } = linkProps;
67
- if (!href) return {};
68
- if (!URL.canParse(href)) {
69
- logger.log("Invalid href", "error", { href });
70
- return {};
71
- }
72
- const hrefUrl = new URL(href);
73
- searchParams.forEach((value, name) => {
74
- hrefUrl.searchParams.append(name, value);
75
- });
76
- return {
77
- ...rest,
78
- as,
79
- ...themeName ? { themeName } : {},
80
- ...customTheme ? { customTheme } : {},
81
- ...tokens ? { tokens } : {},
82
- nextLinkProps: {
83
- href: hrefUrl.toString(),
84
- prefetch: prefetch ?? void 0,
85
- scroll: scroll ?? void 0,
86
- replace: replace ?? void 0
87
- },
88
- href: hrefUrl.toString(),
89
- children: label,
90
- ...restOfLinkProps
91
- };
92
- }
93
- export {
94
- useDirectusLink as default
95
- };
@@ -1,6 +0,0 @@
1
- import type { TPageSettings, TPageSettingsTranslation } from '@okam/directus-next';
2
- import type { Metadata } from 'next';
3
- import type { TMetadataOptions } from '../types/metadata';
4
- export default function useMetadata<TPageProps extends {
5
- pageSettings: TPageSettings;
6
- }>(pageProps: TPageProps, options: TMetadataOptions, defaultProps?: Partial<TPageSettingsTranslation>): Metadata;
@@ -1,3 +0,0 @@
1
- import type { Nullable } from '@okam/stack-ui';
2
- import type { SearchParams } from '../types/links';
3
- export default function getDirectusSearchParams(params: Nullable<Nullable<SearchParams>[]>): URLSearchParams;
@@ -1,10 +0,0 @@
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>[]>;