@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.
- package/CHANGELOG.md +55 -0
- package/README.md +1 -1
- package/components/DirectusFile/config.d.ts +3 -2
- package/components/DirectusFile/index.d.ts +2 -1
- package/components/DirectusFile/interface.d.ts +3 -2
- package/components/DirectusImg/index.d.ts +2 -1
- package/components/DirectusImg/index.js +2 -2
- package/components/DirectusImg/index.mjs +2 -2
- package/components/DirectusImg/interface.d.ts +2 -1
- package/components/DirectusLink/index.d.ts +2 -1
- package/components/DirectusLink/index.js +2 -2
- package/components/DirectusLink/index.mjs +2 -2
- package/components/DirectusLink/interface.d.ts +8 -7
- package/components/DirectusVideo/index.d.ts +2 -1
- package/components/DirectusVideo/index.js +2 -2
- package/components/DirectusVideo/index.mjs +2 -2
- package/components/DirectusVideo/interface.d.ts +3 -2
- package/index.d.ts +12 -11
- package/index.js +14 -10
- package/index.mjs +14 -10
- package/lib/directus-next-rewrite.d.ts +2 -2
- package/lib/withDirectus.d.ts +2 -1
- package/logger.d.ts +1 -1
- package/package.json +13 -7
- package/server.d.ts +4 -4
- package/server.js +12 -8
- package/server.mjs +12 -8
- package/types/index.d.ts +3 -0
- package/types/links.d.ts +5 -4
- package/types/metadata.d.ts +7 -6
- package/types/{navigation-items.d.ts → navigationItems.d.ts} +8 -7
- package/{hooks/directus-file.d.ts → utils/getDirectusFile/index.d.ts} +9 -3
- package/{hooks/directus-file.js → utils/getDirectusFile/index.js} +7 -3
- package/{hooks/directus-file.mjs → utils/getDirectusFile/index.mjs} +6 -3
- package/utils/getDirectusLink/index.d.ts +8 -0
- package/utils/getDirectusLink/index.js +123 -0
- package/utils/getDirectusLink/index.mjs +123 -0
- package/utils/getDirectusMetadata/index.d.ts +15 -0
- package/{hooks/directus-metadata.js → utils/getDirectusMetadata/index.js} +11 -12
- package/{hooks/directus-metadata.mjs → utils/getDirectusMetadata/index.mjs} +10 -12
- package/utils/getDirectusSearchParams/index.d.ts +8 -0
- package/{hooks/directus-search-params.js → utils/getDirectusSearchParams/index.js} +2 -1
- package/{hooks/directus-search-params.mjs → utils/getDirectusSearchParams/index.mjs} +1 -1
- package/utils/getNavigationItems/index.d.ts +15 -0
- package/{hooks/navigation-items.js → utils/getNavigationItems/index.js} +6 -3
- package/{hooks/navigation-items.mjs → utils/getNavigationItems/index.mjs} +5 -3
- package/hooks/directus-link.d.ts +0 -3
- package/hooks/directus-link.js +0 -94
- package/hooks/directus-link.mjs +0 -95
- package/hooks/directus-metadata.d.ts +0 -6
- package/hooks/directus-search-params.d.ts +0 -3
- package/hooks/navigation-items.d.ts +0 -10
package/hooks/directus-link.mjs
DELETED
|
@@ -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,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>[]>;
|