@okam/directus-block 1.4.0 → 1.5.1

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 ADDED
@@ -0,0 +1,108 @@
1
+ ## 1.4.0 (2024-10-04)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - updates & cleanup packages and dependancies ([#210](https://github.com/OKAMca/stack/pull/210))
7
+
8
+
9
+ ### ❤️ Thank You
10
+
11
+ - Marie-Maxime Tanguay @marie-maxime
12
+
13
+ ## 1.3.2 (2024-08-15)
14
+
15
+
16
+ ### 🩹 Fixes
17
+
18
+ - **directus-block:** exclude directus-query from bundling + export useBlock from /server ([6345390](https://github.com/OKAMca/stack/commit/6345390))
19
+
20
+
21
+ ### ❤️ Thank You
22
+
23
+ - Marie-Maxime Tanguay
24
+ - poclerson
25
+
26
+ ## 1.3.1 (2024-08-14)
27
+
28
+
29
+ ### 🩹 Fixes
30
+
31
+ - if a block has settings, doesnt mean it has data ([#180](https://github.com/OKAMca/stack/pull/180))
32
+
33
+
34
+ ### ❤️ Thank You
35
+
36
+ - Marie-Maxime Tanguay @marie-maxime
37
+ - mykimd
38
+ - Pierre-Olivier Clerson @poclerson
39
+ - poclerson
40
+ - Yan Morin
41
+ - yanmorinokamca @yanmorinokamca
42
+
43
+ ## 1.3.0 (2024-07-25)
44
+
45
+
46
+ ### 🚀 Features
47
+
48
+ - generator for block & component ([#161](https://github.com/OKAMca/stack/pull/161))
49
+
50
+ - directus link component + use nav items hook ([750fa5c](https://github.com/OKAMca/stack/commit/750fa5c))
51
+
52
+
53
+ ### ❤️ Thank You
54
+
55
+ - Jérôme Trottier
56
+ - Marie-Maxime Tanguay @marie-maxime
57
+ - Pierre-Olivier Clerson @poclerson
58
+ - yanmorinokamca @yanmorinokamca
59
+
60
+ ## 1.2.3 (2024-07-09)
61
+
62
+
63
+ ### 🩹 Fixes
64
+
65
+ - **directus-block:** export server components ([05f1a31](https://github.com/OKAMca/stack/commit/05f1a31))
66
+
67
+
68
+ ### ❤️ Thank You
69
+
70
+ - Jérôme Trottier
71
+
72
+ ## 1.2.2 (2024-07-08)
73
+
74
+
75
+ ### 🩹 Fixes
76
+
77
+ - **publish:** add building packages step to workflow ([c9ce442](https://github.com/OKAMca/stack/commit/c9ce442))
78
+
79
+
80
+ ### ❤️ Thank You
81
+
82
+ - Jérôme Trottier
83
+
84
+ ## 1.2.1 (2024-07-05)
85
+
86
+ This was a version bump only for directus-block to align it with other projects, there were no code changes.
87
+
88
+ ## 1.2.0 (2024-06-28)
89
+
90
+
91
+ ### 🚀 Features
92
+
93
+ - STACK-72-Lib-Create-directus-block ([#115](https://github.com/OKAMca/stack/pull/115))
94
+
95
+
96
+ ### 🩹 Fixes
97
+
98
+ - publishing for new libs ([#125](https://github.com/OKAMca/stack/pull/125))
99
+
100
+ - **directus-block:** update package version ([9f93408](https://github.com/OKAMca/stack/commit/9f93408))
101
+
102
+ - **block-directus:** add server only to get block props ([330e76f](https://github.com/OKAMca/stack/commit/330e76f))
103
+
104
+
105
+ ### ❤️ Thank You
106
+
107
+ - Marie-Maxime Tanguay @marie-maxime
108
+ - Pierre-Olivier Clerson @poclerson
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # directus-block
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build directus-block` to build the library.
8
+
9
+ ## Components
10
+
11
+ ### Dispatcher
12
+
13
+ #### Props
14
+
15
+ - config: Configuration the block dispatcher will use. This configuration will get merged with the base config of directus-block. In case of overrides, the passed configuration will always win over the directus-block configuration.
16
+ - blocks: Array of `TBlockSerializerProps` containing the actual blocks data. This is the prop that will be used by the block dispatcher to iterate through its children.
17
+ - block: In case you want to pass a single block
18
+ - children: Function receiving the current block `TBlockSerializerProps` as props. Will use BlockSerializer alone by default. This is useful in scenarios where you want every block to be wrapped in other components:
19
+
20
+ ```tsx
21
+ <BlockDispatcher config={baseBlockDispatcherConfig} blocks={blocks}>
22
+ {(block) => (
23
+ <Container tokens={{ isLowestContainerLevel: true }}>
24
+ <ErrorBoundary fallback={<ErrorFallback />}>
25
+ <BlockSerializer {...block} />
26
+ </ErrorBoundary>
27
+ </Container>
28
+ )}
29
+ </BlockDispatcher>
30
+ ```
31
+
32
+ This would allow to remove a lot of repetitive code accross blocks definitions, for example as they all need to be wrapped in a `Container` and an `ErrorBoundary`
33
+
34
+ ### Serializer
35
+
36
+ This component calls the good component in the configuration from the `collection` prop
37
+
38
+ #### Props
39
+
40
+ - item: The block's data. Can either contain just the block's `id`, be null (in that case, the `id` will need to be sent using the block's variables). If `item` only contains the id, it will be sent to the variables for making the query
41
+ - variables: The block's variables. Passing the id is necessary
42
+ - document: Can also be passed in the config. The document that will be used to make a query
43
+
44
+ ## Configuration
45
+
46
+ A configuration uses the `components` prop to map a key value, like so:
47
+
48
+ ```tsx
49
+ const config = {
50
+ components: {
51
+ block_wysiwyg: {
52
+ default: (props) => <BlockWysiwyg {...props} />,
53
+ document: BlockWysiwygDocument,
54
+ defaultVariant: 'reversed',
55
+ getVariant: (props) => props.settings.variants,
56
+ variants: {
57
+ reversed: (props) => (
58
+ <ReversedThemeProvider>
59
+ <BlockWysiwyg {...props} />
60
+ </ReversedThemeProvider>
61
+ )
62
+ }
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ ### Props
69
+
70
+ - default: The default component if no variants/invalid variants are used
71
+ - defaultVariant: Overrides the default use of the `default` prop, instead mapping the default component on a specific variant
72
+ - getVariant: Callback to specify a different variant path from the one in the block's settings
73
+ - variants: key-value mapping of `{[variant]: component}`
74
+ - document: The necessary document for querying the data. This prop can either be passed directly to the block or in the config. Since Stack blocks don't yet have their own documents, you can override them and add their document like so:
75
+
76
+ ```tsx
77
+ import { blockWysiwygConfig } from '@okam/directus-block'
78
+
79
+ const brandConfig = {
80
+ components: {
81
+ block_wysiwyg: {
82
+ document: BlockWysiwygDocument,
83
+ ...blockWysiwygConfig.block_wysiwyg,
84
+ },
85
+ block_image: {
86
+ default: (props) => <BrandBlockImage {...props} />
87
+ },
88
+ },
89
+ }
90
+
91
+ <BlockDispatcher config={brandConfig} />
92
+ ```
93
+
94
+ ### Overriding the configuration with brand blocks
95
+
96
+ To override the base block dispatcher configuration, you name a block component configuration with the same key as the ones in the configuration.
97
+
98
+ For example, if this is the base configuration:
99
+
100
+ ```tsx
101
+ const baseConfig = {
102
+ components: {
103
+ block_wysiwyg: {
104
+ default: (props) => <BlockWysiwyg {...props}>,
105
+ },
106
+ block_hero: {
107
+ default: (props) => <BlockHero {...props}>,
108
+ },
109
+ },
110
+ }
111
+ ```
112
+
113
+ But that you to call a branded wysiwyg component from the dispatcher configuration, you may pass the following configuration:
114
+
115
+ ```tsx
116
+ const brandConfig = {
117
+ components: {
118
+ block_wysiwyg: {
119
+ default: (props) => <BrandBlockWysiwyg {...props} />
120
+ },
121
+ block_image: {
122
+ default: (props) => <BrandBlockImage {...props} />
123
+ },
124
+ },
125
+ }
126
+
127
+ <BlockDispatcher config={brandConfig} />
128
+ ```
129
+
130
+ In this example, the BlockWysiwyg definition would be overriden. However, you would now also have access to the `block_image`, and still retain access to the `block_hero`
131
+
132
+ You could also re-use only a part of the base configuration while overriding another part
133
+
134
+ ```tsx
135
+ import { blockWysiwygConfig } from '@okam/directus-block'
136
+
137
+ const brandConfig = {
138
+ components: {
139
+ block_wysiwyg: {
140
+ default: (props) => <BrandBlockWysiwyg {...props} />,
141
+ variants: blockWysiwygConfig.block_wysiwyg.variants,
142
+ },
143
+ block_image: {
144
+ default: (props) => <BrandBlockImage {...props} />
145
+ },
146
+ },
147
+ }
148
+
149
+ <BlockDispatcher config={brandConfig} />
150
+ ```
151
+
152
+ ### Extending the configuration with stack blocks
153
+
154
+ Some blocks may be in the Stack without being in the base configuration. To use them, simply import their own configuration from the stack and spread them in yours
155
+
156
+ ```tsx
157
+ import { blockHeroConfig } from '@okam/directus-block'
158
+
159
+ const brandConfigWithStackBlocks = {
160
+ components: {
161
+ block_image: {
162
+ default: (props) => <BrandBlockImage {...props} />
163
+ },
164
+ ...blockHeroConfig,
165
+ }
166
+ }
167
+ ```
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  require("@okam/directus-query");
4
- require("radash");
4
+ require("radashi");
5
5
  const mergeConfigs = require("../../utils/merge-configs.js");
6
6
  const index = require("../BlockSerializer/index.js");
7
7
  const config = require("./config.js");
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import "@okam/directus-query";
3
- import "radash";
3
+ import "radashi";
4
4
  import mergeConfigs from "../../utils/merge-configs.mjs";
5
5
  import BlockSerializer from "../BlockSerializer/index.mjs";
6
6
  import baseConfig from "./config.mjs";
@@ -3,7 +3,7 @@ const jsxRuntime = require("react/jsx-runtime");
3
3
  const graphql = require("../../generated/graphql.js");
4
4
  const fragmentMasking = require("../../generated/fragment-masking.js");
5
5
  require("@okam/directus-query");
6
- require("radash");
6
+ require("radashi");
7
7
  const BlockSerializer = (props) => {
8
8
  var _a, _b, _c;
9
9
  const { item, collection, config, variables, defaultVariant, ...rest } = props;
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { BlockSettingsFragmentDoc } from "../../generated/graphql.mjs";
3
3
  import { useFragment } from "../../generated/fragment-masking.mjs";
4
4
  import "@okam/directus-query";
5
- import "radash";
5
+ import "radashi";
6
6
  const BlockSerializer = (props) => {
7
7
  var _a, _b, _c;
8
8
  const { item, collection, config, variables, defaultVariant, ...rest } = props;
package/hooks/useBlock.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
- const radash = require("radash");
2
+ const radashi = require("radashi");
3
3
  const graphql = require("../generated/graphql.js");
4
4
  const fragmentMasking = require("../generated/fragment-masking.js");
5
5
  const getBlockProps = require("../utils/get-block-props.js");
6
6
  async function useBlock(props, blockKey, doc) {
7
- const item = radash.get(props, "item");
8
- const document = doc ?? radash.get(props, "document");
9
- const variables = radash.get(props, "variables");
7
+ const item = radashi.get(props, "item");
8
+ const document = doc ?? radashi.get(props, "document");
9
+ const variables = radashi.get(props, "variables");
10
10
  const propsWithFallback = await getBlockProps({
11
11
  item,
12
12
  blockKey,
@@ -1,4 +1,4 @@
1
- import { get } from "radash";
1
+ import { get } from "radashi";
2
2
  import { BlockSettingsFragmentDoc } from "../generated/graphql.mjs";
3
3
  import { useFragment } from "../generated/fragment-masking.mjs";
4
4
  import getBlockProps from "../utils/get-block-props.mjs";
package/package.json CHANGED
@@ -1,16 +1,28 @@
1
1
  {
2
2
  "name": "@okam/directus-block",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./index.mjs",
9
- "require": "./index.js"
8
+ "import": {
9
+ "types": "./index.d.ts",
10
+ "default": "./index.mjs"
11
+ },
12
+ "require": {
13
+ "types": "./index.d.ts",
14
+ "default": "./index.mjs"
15
+ }
10
16
  },
11
17
  "./server": {
12
- "import": "./server.mjs",
13
- "require": "./server.js"
18
+ "import": {
19
+ "types": "./server.d.ts",
20
+ "default": "./server.mjs"
21
+ },
22
+ "require": {
23
+ "types": "./server.d.ts",
24
+ "default": "./server.mjs"
25
+ }
14
26
  }
15
27
  },
16
28
  "publishConfig": {
@@ -18,5 +30,14 @@
18
30
  },
19
31
  "repository": {
20
32
  "url": "https://github.com/OKAMca/stack.git"
33
+ },
34
+ "dependencies": {
35
+ "@graphql-typed-document-node/core": "3.2.0",
36
+ "@okam/directus-query": "1.4.1",
37
+ "@okam/stack-ui": "1.31.1",
38
+ "graphql": "^16.9.0",
39
+ "graphql-request": "^7.1.2",
40
+ "radashi": "^12.3.0",
41
+ "react": "18.3.1"
21
42
  }
22
43
  }
@@ -1,13 +1,13 @@
1
1
  "server-only";
2
2
  "use strict";
3
3
  const directusQuery = require("@okam/directus-query");
4
- const radash = require("radash");
4
+ const radashi = require("radashi");
5
5
  function isVariables(maybeVariables) {
6
6
  return !!maybeVariables;
7
7
  }
8
8
  function isItemEmpty(item) {
9
9
  const { id, settings, ...restOfItem } = item ?? {};
10
- return radash.isEmpty(restOfItem);
10
+ return radashi.isEmpty(restOfItem);
11
11
  }
12
12
  async function queryFromVariables(params) {
13
13
  const { document, blockKey, variables } = params;
@@ -1,6 +1,6 @@
1
1
  "server-only";
2
2
  import { queryGql } from "@okam/directus-query";
3
- import { isEmpty } from "radash";
3
+ import { isEmpty } from "radashi";
4
4
  function isVariables(maybeVariables) {
5
5
  return !!maybeVariables;
6
6
  }