@okam/directus-next-component 1.7.28 → 1.7.29

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 CHANGED
@@ -1,3 +1,24 @@
1
+ ## 1.7.29 (2025-10-31)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **directus-next-component:** directus link supports search params ([21a3e46](https://github.com/OKAMca/stack/commit/21a3e46))
6
+
7
+ ### 🩹 Fixes
8
+
9
+ - **directus-next:** bump version ([e9441ad](https://github.com/OKAMca/stack/commit/e9441ad))
10
+ - **directus-next-component:** core-lib in externals deps ([9b04ca0](https://github.com/OKAMca/stack/commit/9b04ca0))
11
+ - update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
12
+
13
+ ### 🧱 Updated Dependencies
14
+
15
+ - Updated directus-next to 1.2.5
16
+
17
+ ### ❤️ Thank You
18
+
19
+ - Pierre-Olivier Clerson @poclerson
20
+ - poclerson
21
+
1
22
  ## 1.7.28 (2025-10-17)
2
23
 
3
24
  ### 🩹 Fixes
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  const Link = require("next/link.js");
3
+ const logger = require("../logger.js");
3
4
  const directusFile = require("./directus-file.js");
5
+ const directusSearchParams = require("./directus-search-params.js");
4
6
  function useFile(props) {
5
7
  const { file } = props;
6
8
  const { filename_download: filenameDownload } = file ?? {};
@@ -55,13 +57,23 @@ function useDirectusLink(props) {
55
57
  external_link: externalLink,
56
58
  file,
57
59
  id,
60
+ params,
58
61
  ...rest
59
62
  } = props;
63
+ const searchParams = directusSearchParams(params);
60
64
  if (!type) return {};
61
65
  const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
62
66
  const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
63
67
  const { href, ...restOfLinkProps } = linkProps;
64
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
+ });
65
77
  return {
66
78
  ...rest,
67
79
  as,
@@ -69,12 +81,12 @@ function useDirectusLink(props) {
69
81
  ...customTheme ? { customTheme } : {},
70
82
  ...tokens ? { tokens } : {},
71
83
  nextLinkProps: {
72
- href,
84
+ href: hrefUrl.toString(),
73
85
  prefetch: prefetch ?? void 0,
74
86
  scroll: scroll ?? void 0,
75
87
  replace: replace ?? void 0
76
88
  },
77
- href,
89
+ href: hrefUrl.toString(),
78
90
  children: label,
79
91
  ...restOfLinkProps
80
92
  };
@@ -1,5 +1,7 @@
1
1
  import Link from "next/link.js";
2
+ import { logger } from "../logger.mjs";
2
3
  import useDirectusFile from "./directus-file.mjs";
4
+ import getDirectusSearchParams from "./directus-search-params.mjs";
3
5
  function useFile(props) {
4
6
  const { file } = props;
5
7
  const { filename_download: filenameDownload } = file ?? {};
@@ -54,13 +56,23 @@ function useDirectusLink(props) {
54
56
  external_link: externalLink,
55
57
  file,
56
58
  id,
59
+ params,
57
60
  ...rest
58
61
  } = props;
62
+ const searchParams = getDirectusSearchParams(params);
59
63
  if (!type) return {};
60
64
  const finalConfig = { ...defaultPropsConfig, ...propsConfig ?? {} };
61
65
  const linkProps = ((_a = finalConfig[type]) == null ? void 0 : _a.call(finalConfig, props)) ?? {};
62
66
  const { href, ...restOfLinkProps } = linkProps;
63
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
+ });
64
76
  return {
65
77
  ...rest,
66
78
  as,
@@ -68,12 +80,12 @@ function useDirectusLink(props) {
68
80
  ...customTheme ? { customTheme } : {},
69
81
  ...tokens ? { tokens } : {},
70
82
  nextLinkProps: {
71
- href,
83
+ href: hrefUrl.toString(),
72
84
  prefetch: prefetch ?? void 0,
73
85
  scroll: scroll ?? void 0,
74
86
  replace: replace ?? void 0
75
87
  },
76
- href,
88
+ href: hrefUrl.toString(),
77
89
  children: label,
78
90
  ...restOfLinkProps
79
91
  };
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ const radashi = require("radashi");
3
+ function getDirectusSearchParams(params) {
4
+ const searchParams = new URLSearchParams();
5
+ params == null ? void 0 : params.forEach((param) => {
6
+ const { name, value } = param ?? {};
7
+ if (radashi.isEmpty(name) || radashi.isEmpty(value)) {
8
+ return;
9
+ }
10
+ searchParams.set(name, value);
11
+ });
12
+ return searchParams;
13
+ }
14
+ module.exports = getDirectusSearchParams;
@@ -0,0 +1,15 @@
1
+ import { isEmpty } from "radashi";
2
+ function getDirectusSearchParams(params) {
3
+ const searchParams = new URLSearchParams();
4
+ params == null ? void 0 : params.forEach((param) => {
5
+ const { name, value } = param ?? {};
6
+ if (isEmpty(name) || isEmpty(value)) {
7
+ return;
8
+ }
9
+ searchParams.set(name, value);
10
+ });
11
+ return searchParams;
12
+ }
13
+ export {
14
+ getDirectusSearchParams as default
15
+ };
package/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { default as DirectusVideo } from './components/DirectusVideo';
4
4
  export { default as DirectusFile } from './components/DirectusFile';
5
5
  export { default as useDirectusFile } from './hooks/directus-file';
6
6
  export { default as useDirectusLink } from './hooks/directus-link';
7
+ export { default as getDirectusSearchParams } from './hooks/directus-search-params';
7
8
  export { default as useNavigationItems } from './hooks/navigation-items';
8
9
  export { default as useMetadata } from './hooks/directus-metadata';
9
10
  export { logger as DirectusNextComponent } from './logger';
@@ -17,6 +18,6 @@ export type {
17
18
  * @deprecated Import from `@okam/directus-next` instead
18
19
  */ TPageSettings, } from '@okam/directus-next';
19
20
  export type { TNavigationItems, TNavigationItemsTree } from './types/navigation-items';
20
- export type { TLinks } from './types/links';
21
+ export type { TLinks, SearchParams } from './types/links';
21
22
  export type { TDirectusLinkProps, TUseDirectusLink, TDirectusLink, TDirectusLinkPropsConfig, TDirectusLinkComponentsConfig, } from './components/DirectusLink/interface';
22
23
  export type { TMetadataOptions } from './types/metadata';
package/index.js CHANGED
@@ -6,6 +6,7 @@ const index$2 = require("./components/DirectusVideo/index.js");
6
6
  const index$3 = require("./components/DirectusFile/index.js");
7
7
  const directusFile = require("./hooks/directus-file.js");
8
8
  const directusLink = require("./hooks/directus-link.js");
9
+ const directusSearchParams = require("./hooks/directus-search-params.js");
9
10
  const navigationItems = require("./hooks/navigation-items.js");
10
11
  const directusMetadata = require("./hooks/directus-metadata.js");
11
12
  const logger = require("./logger.js");
@@ -15,6 +16,7 @@ exports.DirectusVideo = index$2;
15
16
  exports.DirectusFile = index$3;
16
17
  exports.useDirectusFile = directusFile;
17
18
  exports.useDirectusLink = directusLink;
19
+ exports.getDirectusSearchParams = directusSearchParams;
18
20
  exports.useNavigationItems = navigationItems;
19
21
  exports.useMetadata = directusMetadata;
20
22
  exports.DirectusNextComponent = logger.logger;
package/index.mjs CHANGED
@@ -4,8 +4,9 @@ import { default as default4 } from "./components/DirectusVideo/index.mjs";
4
4
  import { default as default5 } from "./components/DirectusFile/index.mjs";
5
5
  import { default as default6 } from "./hooks/directus-file.mjs";
6
6
  import { default as default7 } from "./hooks/directus-link.mjs";
7
- import { default as default8 } from "./hooks/navigation-items.mjs";
8
- import { default as default9 } from "./hooks/directus-metadata.mjs";
7
+ import { default as default8 } from "./hooks/directus-search-params.mjs";
8
+ import { default as default9 } from "./hooks/navigation-items.mjs";
9
+ import { default as default10 } from "./hooks/directus-metadata.mjs";
9
10
  import { logger } from "./logger.mjs";
10
11
  export {
11
12
  default5 as DirectusFile,
@@ -13,8 +14,9 @@ export {
13
14
  default2 as DirectusLink,
14
15
  logger as DirectusNextComponent,
15
16
  default4 as DirectusVideo,
17
+ default8 as getDirectusSearchParams,
16
18
  default6 as useDirectusFile,
17
19
  default7 as useDirectusLink,
18
- default9 as useMetadata,
19
- default8 as useNavigationItems
20
+ default10 as useMetadata,
21
+ default9 as useNavigationItems
20
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/directus-next-component",
3
- "version": "1.7.28",
3
+ "version": "1.7.29",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -40,6 +40,6 @@
40
40
  "radashi": "^12.3.0",
41
41
  "react": "18.3.1",
42
42
  "unlazy": "^0.12.1",
43
- "@okam/directus-next": "1.2.4"
43
+ "@okam/directus-next": "1.2.5"
44
44
  }
45
45
  }
package/types/links.d.ts CHANGED
@@ -1,17 +1,25 @@
1
1
  import type { TPageSettings, TFiles } from '@okam/directus-next';
2
+ import type { Nullable } from '@okam/stack-ui';
2
3
  /**
3
4
  * Represent the directus `links` collection, not the props of the DirectusLink component
4
5
  */
5
- export type TLinks = {
6
- anchor?: string | null;
7
- external_link?: string | null;
6
+ export interface TLinks {
7
+ anchor?: Nullable<string>;
8
+ external_link?: Nullable<string>;
8
9
  id?: string;
9
- label?: string | null;
10
- prefetch?: boolean | null;
11
- replace?: boolean | null;
12
- scroll?: boolean | null;
13
- target?: string | null;
14
- type?: string | null;
15
- collection?: TPageSettings | null;
16
- file?: TFiles | null;
17
- };
10
+ label?: Nullable<string>;
11
+ prefetch?: Nullable<boolean>;
12
+ replace?: Nullable<boolean>;
13
+ scroll?: Nullable<boolean>;
14
+ target?: Nullable<string>;
15
+ type?: Nullable<string>;
16
+ collection?: Nullable<TPageSettings>;
17
+ file?: Nullable<TFiles>;
18
+ params?: Nullable<Nullable<SearchParams>[]>;
19
+ }
20
+ export interface SearchParams {
21
+ id?: string;
22
+ name?: Nullable<string>;
23
+ value?: Nullable<string>;
24
+ link?: Nullable<TLinks>;
25
+ }