@okam/directus-block 1.5.21 → 1.6.0
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 +43 -0
- package/components/BlockSerializer/interface.d.ts +78 -12
- package/hooks/useBlock.d.ts +19 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
## 1.6.0 (2025-10-17)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- bump ([ab924b9](https://github.com/OKAMca/stack/commit/ab924b9))
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **directus-block:** clean up useBlock type usage ([c7b198e](https://github.com/OKAMca/stack/commit/c7b198e))
|
|
10
|
+
- **directus-block:** always pass type params between block serializer types ([430e6db](https://github.com/OKAMca/stack/commit/430e6db))
|
|
11
|
+
- update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
|
|
12
|
+
- package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
|
|
13
|
+
- search field type export ([5ab6070](https://github.com/OKAMca/stack/commit/5ab6070))
|
|
14
|
+
- search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
|
|
15
|
+
|
|
16
|
+
### ❤️ Thank You
|
|
17
|
+
|
|
18
|
+
- Marie-Maxime Tanguay
|
|
19
|
+
- Pierre-Olivier Clerson @poclerson
|
|
20
|
+
- poclerson
|
|
21
|
+
|
|
22
|
+
## 1.5.22 (2025-10-17)
|
|
23
|
+
|
|
24
|
+
### 🚀 Features
|
|
25
|
+
|
|
26
|
+
- bump ([ab924b9](https://github.com/OKAMca/stack/commit/ab924b9))
|
|
27
|
+
|
|
28
|
+
### 🩹 Fixes
|
|
29
|
+
|
|
30
|
+
- update vite-plugin-dts to version 3 ([5d33c77](https://github.com/OKAMca/stack/commit/5d33c77))
|
|
31
|
+
- package deps error ([b665a45](https://github.com/OKAMca/stack/commit/b665a45))
|
|
32
|
+
- search field type export ([5ab6070](https://github.com/OKAMca/stack/commit/5ab6070))
|
|
33
|
+
- search field icon ([0850fde](https://github.com/OKAMca/stack/commit/0850fde))
|
|
34
|
+
|
|
35
|
+
### 🧱 Updated Dependencies
|
|
36
|
+
|
|
37
|
+
- Updated stack-ui to 1.42.3
|
|
38
|
+
|
|
39
|
+
### ❤️ Thank You
|
|
40
|
+
|
|
41
|
+
- Marie-Maxime Tanguay
|
|
42
|
+
- Pierre-Olivier Clerson @poclerson
|
|
43
|
+
|
|
1
44
|
## 1.5.21 (2025-10-14)
|
|
2
45
|
|
|
3
46
|
### 🚀 Features
|
|
@@ -1,31 +1,97 @@
|
|
|
1
1
|
import { type TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
2
|
import type { Nullable, TDefaultComponent } from '@okam/stack-ui';
|
|
3
|
-
import type { Variables } from 'graphql-request';
|
|
3
|
+
import type { Variables as GraphQLVariables } from 'graphql-request';
|
|
4
4
|
import type { FunctionComponent } from 'react';
|
|
5
5
|
import type { TCommonBlockFragment, TAdditionalProps, TBlockQuery, TBlockVariables, TBlockDocument } from '../../types/block';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Base block data. See {@link TBlockSerializerProps} for actual props implementation.
|
|
8
|
+
*/
|
|
9
|
+
export interface TBlock<Fragment extends TCommonBlockFragment = TCommonBlockFragment, Variables extends GraphQLVariables = TBlockVariables> {
|
|
10
|
+
/**
|
|
11
|
+
* Directus collection name of the block.
|
|
12
|
+
*/
|
|
7
13
|
collection?: Nullable<string>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The actual block's data. If only the id is passed, the block will be queried using the `variables` prop. Otherwise, the block will be passed as is.
|
|
16
|
+
*/
|
|
17
|
+
item?: Nullable<Fragment>;
|
|
18
|
+
variables?: TBlockVariables<Variables>;
|
|
19
|
+
document?: TypedDocumentNode<TBlockQuery<Fragment>, Variables>;
|
|
11
20
|
}
|
|
12
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The props of individual block components.
|
|
23
|
+
* @template Fragment - The GraphQL fragment type for the block data structure
|
|
24
|
+
* @template Variables - The GraphQL variables type for querying the block
|
|
25
|
+
* @template AdditionalProps - Additional props that can be passed to the block component
|
|
26
|
+
*/
|
|
27
|
+
export type TBlockSerializerProps<Fragment extends TCommonBlockFragment = TCommonBlockFragment, Variables extends GraphQLVariables = TBlockVariables, AdditionalProps extends TAdditionalProps = TAdditionalProps> = TBlock<Fragment, Variables> & TDefaultComponent & {
|
|
13
28
|
config?: TBlockSerializerConfig;
|
|
14
29
|
defaultVariant?: string;
|
|
15
30
|
additionalProps?: AdditionalProps;
|
|
16
31
|
};
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Wrapper for {@link TBlockSerializerProps} to be used as a component type
|
|
34
|
+
*/
|
|
35
|
+
export type TBlockFunctionComponent<Fragment extends TCommonBlockFragment = TCommonBlockFragment, Variables extends GraphQLVariables = TBlockVariables, AdditionalProps extends TAdditionalProps = TAdditionalProps> = FunctionComponent<TBlockSerializerProps<Fragment, Variables, AdditionalProps>>;
|
|
36
|
+
/**
|
|
37
|
+
* To make a component a part of the block serializer configuration, add its own key to the config object.
|
|
38
|
+
*
|
|
39
|
+
* ### Basic usage
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* const configComponent: TBlockSerializerConfigComponent = {
|
|
43
|
+
* block_wysiwygs: {
|
|
44
|
+
* default: (props) => <BlockWysiwygs {...props} />,
|
|
45
|
+
* },
|
|
46
|
+
* }
|
|
47
|
+
* const config = {
|
|
48
|
+
* components: {
|
|
49
|
+
* ...configComponent,
|
|
50
|
+
* },
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* ### Using variants with `variants`, `getVariant` and `defaultVariant`
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const configComponent: TBlockSerializerConfigComponent<BlockButtonsFragment> = {
|
|
58
|
+
* block_buttons: {
|
|
59
|
+
* // Default is always required even if `defaultVariant` is passed since it's the fallback component
|
|
60
|
+
* default: (props) => <BlockButtons {...props} />,
|
|
61
|
+
* defaultVariant: 'primary',
|
|
62
|
+
* // Some blocks may have a variant located elsewhere in the block data
|
|
63
|
+
* getVariant: (props) => props.item?.link?.variant,
|
|
64
|
+
* variants: {
|
|
65
|
+
* reversed: (props) => <BlockButtons theme="reversed" {...props} />,
|
|
66
|
+
* primary: (props) => <BlockButtons tokens={{ buttonStyle: 'primary' }} {...props} />,
|
|
67
|
+
* },
|
|
68
|
+
* },
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export type TBlockSerializerConfigComponent<Fragment extends TCommonBlockFragment = TCommonBlockFragment, Variables extends GraphQLVariables = TBlockVariables, AdditionalProps extends TAdditionalProps = TAdditionalProps> = {
|
|
19
73
|
[blockKey: string]: {
|
|
20
|
-
default: TBlockFunctionComponent<
|
|
21
|
-
|
|
74
|
+
default: TBlockFunctionComponent<Fragment, Variables, AdditionalProps>;
|
|
75
|
+
/**
|
|
76
|
+
* The necessary GraphQL document for querying the data. This prop can either be passed directly to the block or in the config.
|
|
77
|
+
*/
|
|
78
|
+
document?: TBlockDocument<Fragment, Variables>;
|
|
79
|
+
/**
|
|
80
|
+
* @default 'default'
|
|
81
|
+
*/
|
|
22
82
|
defaultVariant?: string;
|
|
23
|
-
|
|
83
|
+
/**
|
|
84
|
+
* A callback to specify a different variant path from the one in the block's settings.
|
|
85
|
+
*/
|
|
86
|
+
getVariant?: (props: TBlockSerializerProps<Fragment, Variables, AdditionalProps>) => Nullable<string>;
|
|
24
87
|
variants?: {
|
|
25
|
-
[blockVariant: string]: TBlockFunctionComponent<
|
|
88
|
+
[blockVariant: string]: TBlockFunctionComponent<Fragment, Variables, AdditionalProps>;
|
|
26
89
|
};
|
|
27
90
|
};
|
|
28
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* A configuration for the block serializer. Usually, it's a bad idea to define the config components directly in the main config since each config component needs its own type parameters.
|
|
94
|
+
*/
|
|
29
95
|
export interface TBlockSerializerConfig {
|
|
30
96
|
components: TBlockSerializerConfigComponent;
|
|
31
97
|
}
|
package/hooks/useBlock.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import type { TToken } from '@okam/stack-ui';
|
|
2
|
-
import type { TypedQueryDocumentNode } from 'graphql';
|
|
3
2
|
import type { TBlockSerializerProps } from '../components/BlockSerializer/interface';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
3
|
+
import type { TBlockDocument, TBlockVariables, TCommonBlockFragment } from '../types/block';
|
|
4
|
+
/**
|
|
5
|
+
* General function to fetch the block data and its settings. Features the decision-making logic of {@link getBlockProps} that allows blocks to work with both passed props and queried props.
|
|
6
|
+
* @param props Props of the block component. Pass props directly from the block component.
|
|
7
|
+
* @param blockKey Key of the block data in the GraphQL document. Allows mapping props regardless of the block's collection name. Usually the block's collection name with `_by_id` appended since most queries are made by id.
|
|
8
|
+
* @param doc Alternative for passing the GraphQL document to the block component. If not passed, the document will be retrieved from the block's props or config.
|
|
9
|
+
* @returns The block data and its settings.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const BlockButtons = (props: TBlockSerializerProps<BlockButtonsFragment>) => {
|
|
14
|
+
* const key = 'block_buttons_by_id'
|
|
15
|
+
* const { tokens } = props
|
|
16
|
+
* const { link, cmsTokens, variant } = await useBlock(props, key)
|
|
17
|
+
* return <Link {...link} tokens={{ ...tokens, ...cmsTokens, style: variant }} />
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export default function useBlock<Fragment extends TCommonBlockFragment, Variables extends TBlockVariables = TBlockVariables>(props: TBlockSerializerProps<Fragment, Variables>, blockKey: string, doc?: TBlockDocument<Fragment, Variables>): Promise<Fragment & {
|
|
6
22
|
cmsTokens: TToken;
|
|
7
23
|
}>;
|
|
8
|
-
export default useBlock;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-block",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
36
36
|
"@okam/directus-query": "1.4.2",
|
|
37
|
-
"@okam/stack-ui": "1.42.
|
|
37
|
+
"@okam/stack-ui": "1.42.3",
|
|
38
38
|
"graphql": "^16.9.0",
|
|
39
39
|
"graphql-request": "^7.1.2",
|
|
40
40
|
"radashi": "^12.3.0",
|