@okam/directus-block 1.2.1 → 1.2.2

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 (44) hide show
  1. package/blocks/BlockWysiwyg/config.d.ts +4 -0
  2. package/blocks/BlockWysiwyg/index.d.ts +4 -0
  3. package/blocks/BlockWysiwyg/interface.d.ts +17 -0
  4. package/components/BlockDispatcher/config.d.ts +3 -0
  5. package/components/BlockDispatcher/interface.d.ts +16 -0
  6. package/components/BlockSerializer/interface.d.ts +31 -0
  7. package/generated/fragment-masking.d.ts +15 -0
  8. package/generated/graphql.d.ts +64 -0
  9. package/index.d.ts +6 -0
  10. package/index.js +96 -0
  11. package/index.mjs +5966 -0
  12. package/package.json +1 -1
  13. package/style.css +1 -0
  14. package/types/block.d.ts +27 -0
  15. package/utils/get-block-props.d.ts +17 -0
  16. package/utils/index.d.ts +4 -0
  17. package/utils/merge-configs.d.ts +9 -0
  18. package/.eslintrc.js +0 -21
  19. package/.storybook/.eslintrc.js +0 -29
  20. package/.storybook/main.ts +0 -33
  21. package/.storybook/preview.ts +0 -0
  22. package/.storybook/tsconfig.json +0 -17
  23. package/CHANGELOG.md +0 -25
  24. package/README.md +0 -167
  25. package/project.json +0 -36
  26. package/src/blocks/BlockWysiwyg/config.tsx +0 -10
  27. package/src/blocks/BlockWysiwyg/index.tsx +0 -38
  28. package/src/blocks/BlockWysiwyg/interface.ts +0 -13
  29. package/src/components/BlockDispatcher/config.ts +0 -10
  30. package/src/components/BlockDispatcher/index.tsx +0 -30
  31. package/src/components/BlockDispatcher/interface.ts +0 -17
  32. package/src/components/BlockSerializer/index.tsx +0 -43
  33. package/src/components/BlockSerializer/interface.ts +0 -51
  34. package/src/generated/fragment-masking.ts +0 -66
  35. package/src/generated/graphql.ts +0 -31
  36. package/src/index.ts +0 -22
  37. package/src/server.ts +0 -6
  38. package/src/types/block.ts +0 -40
  39. package/src/utils/get-block-props.ts +0 -81
  40. package/src/utils/index.ts +0 -5
  41. package/src/utils/merge-configs.ts +0 -21
  42. package/tsconfig.json +0 -17
  43. package/tsconfig.lib.json +0 -23
  44. package/vite.config.ts +0 -51
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@okam/directus-block",
3
3
  "main": "./index.js",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
package/style.css ADDED
@@ -0,0 +1 @@
1
+ @font-face{font-family:swiper-icons;src:url(data:application/font-woff;charset=utf-8;base64,\ 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);font-weight:400;font-style:normal}:root{--swiper-theme-color: #007aff}:host{position:relative;display:block;margin-left:auto;margin-right:auto;z-index:1}.swiper{margin-left:auto;margin-right:auto;position:relative;overflow:hidden;list-style:none;padding:0;z-index:1;display:block}.swiper-vertical>.swiper-wrapper{flex-direction:column}.swiper-wrapper{position:relative;width:100%;height:100%;z-index:1;display:flex;transition-property:transform;transition-timing-function:var(--swiper-wrapper-transition-timing-function, initial);box-sizing:content-box}.swiper-android .swiper-slide,.swiper-ios .swiper-slide,.swiper-wrapper{transform:translateZ(0)}.swiper-horizontal{touch-action:pan-y}.swiper-vertical{touch-action:pan-x}.swiper-slide{flex-shrink:0;width:100%;height:100%;position:relative;transition-property:transform;display:block}.swiper-slide-invisible-blank{visibility:hidden}.swiper-autoheight,.swiper-autoheight .swiper-slide{height:auto}.swiper-autoheight .swiper-wrapper{align-items:flex-start;transition-property:transform,height}.swiper-backface-hidden .swiper-slide{transform:translateZ(0);-webkit-backface-visibility:hidden;backface-visibility:hidden}.swiper-3d.swiper-css-mode .swiper-wrapper{perspective:1200px}.swiper-3d .swiper-wrapper{transform-style:preserve-3d}.swiper-3d{perspective:1200px}.swiper-3d .swiper-slide,.swiper-3d .swiper-cube-shadow{transform-style:preserve-3d}.swiper-css-mode>.swiper-wrapper{overflow:auto;scrollbar-width:none;-ms-overflow-style:none}.swiper-css-mode>.swiper-wrapper::-webkit-scrollbar{display:none}.swiper-css-mode>.swiper-wrapper>.swiper-slide{scroll-snap-align:start start}.swiper-css-mode.swiper-horizontal>.swiper-wrapper{scroll-snap-type:x mandatory}.swiper-css-mode.swiper-vertical>.swiper-wrapper{scroll-snap-type:y mandatory}.swiper-css-mode.swiper-free-mode>.swiper-wrapper{scroll-snap-type:none}.swiper-css-mode.swiper-free-mode>.swiper-wrapper>.swiper-slide{scroll-snap-align:none}.swiper-css-mode.swiper-centered>.swiper-wrapper:before{content:"";flex-shrink:0;order:9999}.swiper-css-mode.swiper-centered>.swiper-wrapper>.swiper-slide{scroll-snap-align:center center;scroll-snap-stop:always}.swiper-css-mode.swiper-centered.swiper-horizontal>.swiper-wrapper>.swiper-slide:first-child{margin-inline-start:var(--swiper-centered-offset-before)}.swiper-css-mode.swiper-centered.swiper-horizontal>.swiper-wrapper:before{height:100%;min-height:1px;width:var(--swiper-centered-offset-after)}.swiper-css-mode.swiper-centered.swiper-vertical>.swiper-wrapper>.swiper-slide:first-child{margin-block-start:var(--swiper-centered-offset-before)}.swiper-css-mode.swiper-centered.swiper-vertical>.swiper-wrapper:before{width:100%;min-width:1px;height:var(--swiper-centered-offset-after)}.swiper-3d .swiper-slide-shadow,.swiper-3d .swiper-slide-shadow-left,.swiper-3d .swiper-slide-shadow-right,.swiper-3d .swiper-slide-shadow-top,.swiper-3d .swiper-slide-shadow-bottom{position:absolute;left:0;top:0;width:100%;height:100%;pointer-events:none;z-index:10}.swiper-3d .swiper-slide-shadow{background:#00000026}.swiper-3d .swiper-slide-shadow-left{background-image:linear-gradient(to left,#00000080,#0000)}.swiper-3d .swiper-slide-shadow-right{background-image:linear-gradient(to right,#00000080,#0000)}.swiper-3d .swiper-slide-shadow-top{background-image:linear-gradient(to top,#00000080,#0000)}.swiper-3d .swiper-slide-shadow-bottom{background-image:linear-gradient(to bottom,#00000080,#0000)}.swiper-lazy-preloader{width:42px;height:42px;position:absolute;left:50%;top:50%;margin-left:-21px;margin-top:-21px;z-index:10;transform-origin:50%;box-sizing:border-box;border:4px solid var(--swiper-preloader-color, var(--swiper-theme-color));border-radius:50%;border-top-color:transparent}.swiper:not(.swiper-watch-progress) .swiper-lazy-preloader,.swiper-watch-progress .swiper-slide-visible .swiper-lazy-preloader{animation:swiper-preloader-spin 1s infinite linear}.swiper-lazy-preloader-white{--swiper-preloader-color: #fff}.swiper-lazy-preloader-black{--swiper-preloader-color: #000}@keyframes swiper-preloader-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.swiper-pagination{position:absolute;text-align:center;transition:.3s opacity;transform:translateZ(0);z-index:10}.swiper-pagination.swiper-pagination-hidden{opacity:0}.swiper-pagination-disabled>.swiper-pagination,.swiper-pagination.swiper-pagination-disabled{display:none!important}.swiper-pagination-fraction,.swiper-pagination-custom,.swiper-horizontal>.swiper-pagination-bullets,.swiper-pagination-bullets.swiper-pagination-horizontal{bottom:var(--swiper-pagination-bottom, 8px);top:var(--swiper-pagination-top, auto);left:0;width:100%}.swiper-pagination-bullets-dynamic{overflow:hidden;font-size:0}.swiper-pagination-bullets-dynamic .swiper-pagination-bullet{transform:scale(.33);position:relative}.swiper-pagination-bullets-dynamic .swiper-pagination-bullet-active,.swiper-pagination-bullets-dynamic .swiper-pagination-bullet-active-main{transform:scale(1)}.swiper-pagination-bullets-dynamic .swiper-pagination-bullet-active-prev{transform:scale(.66)}.swiper-pagination-bullets-dynamic .swiper-pagination-bullet-active-prev-prev{transform:scale(.33)}.swiper-pagination-bullets-dynamic .swiper-pagination-bullet-active-next{transform:scale(.66)}.swiper-pagination-bullets-dynamic .swiper-pagination-bullet-active-next-next{transform:scale(.33)}.swiper-pagination-bullet{width:var(--swiper-pagination-bullet-width, var(--swiper-pagination-bullet-size, 8px));height:var(--swiper-pagination-bullet-height, var(--swiper-pagination-bullet-size, 8px));display:inline-block;border-radius:var(--swiper-pagination-bullet-border-radius, 50%);background:var(--swiper-pagination-bullet-inactive-color, #000);opacity:var(--swiper-pagination-bullet-inactive-opacity, .2)}button.swiper-pagination-bullet{border:none;margin:0;padding:0;box-shadow:none;-webkit-appearance:none;-moz-appearance:none;appearance:none}.swiper-pagination-clickable .swiper-pagination-bullet{cursor:pointer}.swiper-pagination-bullet:only-child{display:none!important}.swiper-pagination-bullet-active{opacity:var(--swiper-pagination-bullet-opacity, 1);background:var(--swiper-pagination-color, var(--swiper-theme-color))}.swiper-vertical>.swiper-pagination-bullets,.swiper-pagination-vertical.swiper-pagination-bullets{right:var(--swiper-pagination-right, 8px);left:var(--swiper-pagination-left, auto);top:50%;transform:translate3d(0,-50%,0)}.swiper-vertical>.swiper-pagination-bullets .swiper-pagination-bullet,.swiper-pagination-vertical.swiper-pagination-bullets .swiper-pagination-bullet{margin:var(--swiper-pagination-bullet-vertical-gap, 6px) 0;display:block}.swiper-vertical>.swiper-pagination-bullets.swiper-pagination-bullets-dynamic,.swiper-pagination-vertical.swiper-pagination-bullets.swiper-pagination-bullets-dynamic{top:50%;transform:translateY(-50%);width:8px}.swiper-vertical>.swiper-pagination-bullets.swiper-pagination-bullets-dynamic .swiper-pagination-bullet,.swiper-pagination-vertical.swiper-pagination-bullets.swiper-pagination-bullets-dynamic .swiper-pagination-bullet{display:inline-block;transition:.2s transform,.2s top}.swiper-horizontal>.swiper-pagination-bullets .swiper-pagination-bullet,.swiper-pagination-horizontal.swiper-pagination-bullets .swiper-pagination-bullet{margin:0 var(--swiper-pagination-bullet-horizontal-gap, 4px)}.swiper-horizontal>.swiper-pagination-bullets.swiper-pagination-bullets-dynamic,.swiper-pagination-horizontal.swiper-pagination-bullets.swiper-pagination-bullets-dynamic{left:50%;transform:translate(-50%);white-space:nowrap}.swiper-horizontal>.swiper-pagination-bullets.swiper-pagination-bullets-dynamic .swiper-pagination-bullet,.swiper-pagination-horizontal.swiper-pagination-bullets.swiper-pagination-bullets-dynamic .swiper-pagination-bullet{transition:.2s transform,.2s left}.swiper-horizontal.swiper-rtl>.swiper-pagination-bullets-dynamic .swiper-pagination-bullet{transition:.2s transform,.2s right}.swiper-pagination-fraction{color:var(--swiper-pagination-fraction-color, inherit)}.swiper-pagination-progressbar{background:var(--swiper-pagination-progressbar-bg-color, rgba(0, 0, 0, .25));position:absolute}.swiper-pagination-progressbar .swiper-pagination-progressbar-fill{background:var(--swiper-pagination-color, var(--swiper-theme-color));position:absolute;left:0;top:0;width:100%;height:100%;transform:scale(0);transform-origin:left top}.swiper-rtl .swiper-pagination-progressbar .swiper-pagination-progressbar-fill{transform-origin:right top}.swiper-horizontal>.swiper-pagination-progressbar,.swiper-pagination-progressbar.swiper-pagination-horizontal,.swiper-vertical>.swiper-pagination-progressbar.swiper-pagination-progressbar-opposite,.swiper-pagination-progressbar.swiper-pagination-vertical.swiper-pagination-progressbar-opposite{width:100%;height:var(--swiper-pagination-progressbar-size, 4px);left:0;top:0}.swiper-vertical>.swiper-pagination-progressbar,.swiper-pagination-progressbar.swiper-pagination-vertical,.swiper-horizontal>.swiper-pagination-progressbar.swiper-pagination-progressbar-opposite,.swiper-pagination-progressbar.swiper-pagination-horizontal.swiper-pagination-progressbar-opposite{width:var(--swiper-pagination-progressbar-size, 4px);height:100%;left:0;top:0}.swiper-pagination-lock{display:none}
@@ -0,0 +1,27 @@
1
+ import type { DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
2
+ import type { Nullable } from '@okam/stack-ui';
3
+ import type { Variables } from 'graphql-request';
4
+ import type { FragmentType } from '../generated/fragment-masking';
5
+ import type { BlockSettingsFragment } from '../generated/graphql';
6
+ export type TAdditionalProps = {
7
+ [key: string]: unknown;
8
+ };
9
+ type BlockSettings = FragmentType<DocumentTypeDecoration<BlockSettingsFragment, unknown>>;
10
+ export type TCommonBlockFragment = {
11
+ id?: Nullable<string>;
12
+ settings?: Nullable<BlockSettings>;
13
+ } & Record<string, unknown>;
14
+ export type TBlockQuery<BlockFragment extends TCommonBlockFragment> = {
15
+ __typename?: 'Query';
16
+ } & {
17
+ [blockKey: string]: {
18
+ ' $fragmentRefs'?: {
19
+ [blockFragmentKey: string]: BlockFragment;
20
+ } | null | undefined;
21
+ } | null | undefined;
22
+ };
23
+ export type TBlockVariables<BlockVariables extends Variables = Variables> = {
24
+ id: string;
25
+ } & BlockVariables;
26
+ export type TBlockDocument<BlockFragment extends TCommonBlockFragment, BlockVariables extends Variables = Variables> = TypedDocumentNode<TBlockQuery<BlockFragment>, TBlockVariables<BlockVariables>>;
27
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Nullable } from '@okam/stack-ui';
2
+ import type { Variables } from 'graphql-request';
3
+ import type { TBlockDocument, TBlockQuery, TBlockVariables, TCommonBlockFragment } from '../types/block';
4
+ type TGetBlockPropsParams<BlockFragment extends TCommonBlockFragment, BlockVariables extends Variables = Variables> = {
5
+ document?: TBlockDocument<BlockFragment, BlockVariables>;
6
+ item?: Nullable<NonNullable<NonNullable<TBlockQuery<BlockFragment>[string]>[' $fragmentRefs']>[string]>;
7
+ blockKey?: string;
8
+ variables?: TBlockVariables<BlockVariables>;
9
+ };
10
+ /**
11
+ * Returns the passed item if it is defined. Otherwise, queried its own block
12
+ * @param params.blockKey Key of the queried field
13
+ * @param params.item Item of the block. If null or only contains the block's id, the function will make a query
14
+ * @returns The block data
15
+ */
16
+ export default function getBlockProps<BlockFragment extends TCommonBlockFragment, BlockVariables extends Variables = Variables>(params: TGetBlockPropsParams<BlockFragment, BlockVariables>): Promise<BlockFragment | null | undefined>;
17
+ export {};
@@ -0,0 +1,4 @@
1
+ import { useFragment } from '../generated/fragment-masking';
2
+ export { default as getBlockProps } from './get-block-props';
3
+ export { default as mergeConfigs } from './merge-configs';
4
+ export { useFragment as getFragment };
@@ -0,0 +1,9 @@
1
+ import type { Nullable } from '@okam/stack-ui';
2
+ import type { TBlockSerializerConfig } from '../components/BlockSerializer/interface';
3
+ /**
4
+ * Merges multiple block dispatcher configs
5
+ * @param baseConfig The base configuration. Other configurations will be prioritized over this one, which acts as a fallback
6
+ * @param configs Array of block dispatcher serializers to merge. Later elements will always be prioritized over first elements
7
+ * @returns Merged config
8
+ */
9
+ export default function mergeConfigs(baseConfig: TBlockSerializerConfig, ...configs: Nullable<TBlockSerializerConfig>[]): TBlockSerializerConfig;
package/.eslintrc.js DELETED
@@ -1,21 +0,0 @@
1
- const { getDefaultIgnorePatterns } = require("../../../linter/helpers");
2
-
3
- module.exports = {
4
- extends: ['plugin:@nx/react', '../../../.eslintrc.js', '../../../linter/bases/typescript', '../../../linter/bases/regexp', '../../../linter/bases/jest', '../../../linter/bases/rtl', '../../../linter/bases/react', '../../../linter/bases/prettier'],
5
- ignorePatterns: ['!**/*', ...getDefaultIgnorePatterns()],
6
- overrides: [
7
- {
8
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
9
- // We set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting
10
- parserOptions: {
11
- project: `${__dirname}/tsconfig.*?.json`,
12
- },
13
- rules: {
14
- "@nx/dependency-checks": "error"
15
- }
16
- },
17
- ],
18
- rules: {
19
- 'react/react-in-jsx-scope': 'off',
20
- },
21
- }
@@ -1,29 +0,0 @@
1
- const { getDefaultIgnorePatterns } = require('../../../../linter/helpers')
2
-
3
- module.exports = {
4
- extends: [
5
- 'plugin:@nx/react',
6
- '../../../../.eslintrc.js',
7
- '../../../../linter/bases/typescript',
8
- '../../../../linter/bases/regexp',
9
- '../../../../linter/bases/jest',
10
- '../../../../linter/bases/rtl',
11
- '../../../../linter/bases/storybook',
12
- '../../../../linter/bases/react',
13
- '../../../../linter/bases/prettier',
14
- 'plugin:storybook/recommended',
15
- ],
16
- ignorePatterns: ['!**/*', ...getDefaultIgnorePatterns()],
17
- overrides: [
18
- {
19
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
20
- // We set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting
21
- parserOptions: {
22
- project: `${__dirname}/tsconfig.*?.json`,
23
- },
24
- },
25
- ],
26
- rules: {
27
- 'react/react-in-jsx-scope': 'off',
28
- },
29
- }
@@ -1,33 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- import type { StorybookConfig } from '@storybook/nextjs'
3
-
4
- const config: StorybookConfig = {
5
- stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
6
- addons: [
7
- '@storybook/addon-a11y',
8
- '@storybook/addon-links',
9
- '@storybook/addon-essentials',
10
- '@storybook/addon-interactions',
11
- {
12
- name: '@storybook/addon-styling',
13
- options: {
14
- // Check out https://github.com/storybookjs/addon-styling/blob/main/docs/api.md
15
- // For more details on this addon's options.
16
- postCss: true,
17
- },
18
- },
19
- ],
20
- framework: {
21
- name: '@storybook/nextjs',
22
- options: {},
23
- },
24
- docs: {
25
- autodocs: 'tag',
26
- },
27
- }
28
-
29
- export default config
30
-
31
- // To customize your Vite configuration you can use the viteFinal field.
32
- // Check https://storybook.js.org/docs/react/builders/vite#configuration
33
- // and https://nx.dev/packages/storybook/documents/custom-builder-configs
File without changes
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "emitDecoratorMetadata": true
5
- },
6
-
7
- "exclude": ["../**/*.spec.ts"],
8
- "include": [
9
- "../src/**/*.stories.ts",
10
- "../src/**/*.stories.js",
11
- "../src/**/*.stories.jsx",
12
- "../src/**/*.stories.tsx",
13
- "../src/**/*.stories.mdx",
14
- "*.ts",
15
- "*.js"
16
- ]
17
- }
package/CHANGELOG.md DELETED
@@ -1,25 +0,0 @@
1
- ## 1.2.1 (2024-07-05)
2
-
3
- This was a version bump only for directus-block to align it with other projects, there were no code changes.
4
-
5
- ## 1.2.0 (2024-06-28)
6
-
7
-
8
- ### 🚀 Features
9
-
10
- - STACK-72-Lib-Create-directus-block ([#115](https://github.com/OKAMca/stack/pull/115))
11
-
12
-
13
- ### 🩹 Fixes
14
-
15
- - publishing for new libs ([#125](https://github.com/OKAMca/stack/pull/125))
16
-
17
- - **directus-block:** update package version ([9f93408](https://github.com/OKAMca/stack/commit/9f93408))
18
-
19
- - **block-directus:** add server only to get block props ([330e76f](https://github.com/OKAMca/stack/commit/330e76f))
20
-
21
-
22
- ### ❤️ Thank You
23
-
24
- - Marie-Maxime Tanguay @marie-maxime
25
- - Pierre-Olivier Clerson @poclerson
package/README.md DELETED
@@ -1,167 +0,0 @@
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
- ```
package/project.json DELETED
@@ -1,36 +0,0 @@
1
- {
2
- "name": "directus-block",
3
- "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/directus/directus-block/src",
5
- "projectType": "library",
6
- "tags": [],
7
- "targets": {
8
- "lint": {
9
- "executor": "@nx/linter:eslint",
10
- "outputs": ["{options.outputFile}"],
11
- "options": {
12
- "lintFilePatterns": ["libs/directus/directus-block/**/*.{ts,tsx,js,jsx}"]
13
- }
14
- },
15
- "build": {
16
- "executor": "@nx/rollup:rollup",
17
- "outputs": ["{options.outputPath}"],
18
- "options": {
19
- "outputPath": "dist/libs/directus/directus-block",
20
- "tsConfig": "libs/directus/directus-block/tsconfig.lib.json",
21
- "project": "libs/directus/directus-block/package.json",
22
- "entryFile": "libs/directus/directus-block/src/index.ts",
23
- "external": "all",
24
- "rollupConfig": "@nx/react/plugins/bundle-rollup",
25
- "compiler": "swc",
26
- "assets": [
27
- {
28
- "glob": "libs/directus/directus-next-component/README.md",
29
- "input": ".",
30
- "output": "."
31
- }
32
- ]
33
- }
34
- }
35
- }
36
- }
@@ -1,10 +0,0 @@
1
- import type { TBlockSerializerConfigComponent } from '../../components/BlockSerializer/interface'
2
- import BlockWysiwyg from '.'
3
-
4
- const blockWysiwygConfig: TBlockSerializerConfigComponent = {
5
- block_wysiwyg: {
6
- default: (props) => <BlockWysiwyg {...props} />,
7
- },
8
- }
9
-
10
- export default blockWysiwygConfig
@@ -1,38 +0,0 @@
1
- import { Box, WysiwygBlock } from '@okam/stack-ui'
2
- import React from 'react'
3
- import type { TBlockSerializerProps } from '../../components/BlockSerializer/interface'
4
- import { BlockSettingsFragmentDoc } from '../../generated/graphql'
5
- import { getBlockProps, getFragment } from '../../utils'
6
- import type { BlockWysiwygFragment } from './interface'
7
-
8
- const BlockWysiwyg = async (props: TBlockSerializerProps<BlockWysiwygFragment>) => {
9
- const { variables, themeName = 'wysiwyg', tokens, item, document } = props
10
-
11
- const propsWithFallback = await getBlockProps({
12
- item,
13
- blockKey: 'block_wysiwyg_by_id',
14
- document,
15
- variables,
16
- })
17
-
18
- if (!propsWithFallback) return null
19
-
20
- const { content, title, level, settings } = propsWithFallback
21
-
22
- const { tokens: cmsTokens } = getFragment(BlockSettingsFragmentDoc, settings) ?? {}
23
-
24
- if (!content && !(title && level)) return null
25
-
26
- return (
27
- <>
28
- {title && level && (
29
- <Box as="span" themeName={themeName} tokens={{ ...tokens, ...cmsTokens }}>
30
- {React.createElement(level, {}, title)}
31
- </Box>
32
- )}
33
- {content && <WysiwygBlock themeName={themeName} tokens={{ ...tokens, ...cmsTokens }} content={content} />}
34
- </>
35
- )
36
- }
37
-
38
- export default BlockWysiwyg
@@ -1,13 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import type { BlockSettingsFragment } from '../../generated/graphql'
3
-
4
- export type BlockWysiwygFragment = {
5
- __typename?: 'block_wysiwyg'
6
- title?: string | null
7
- content?: string | null
8
- level?: string | null
9
- variant?: string | null
10
- settings?:
11
- | ({ __typename?: 'block_settings' } & { ' $fragmentRefs'?: { BlockSettingsFragment: BlockSettingsFragment } })
12
- | null
13
- } & { ' $fragmentName'?: 'BlockWysiwygFragment' }
@@ -1,10 +0,0 @@
1
- import blockWysiwygConfig from '../../blocks/BlockWysiwyg/config'
2
- import type { TBlockSerializerConfig } from '../BlockSerializer/interface'
3
-
4
- const baseConfig: TBlockSerializerConfig = {
5
- components: {
6
- ...blockWysiwygConfig,
7
- },
8
- }
9
-
10
- export default baseConfig
@@ -1,30 +0,0 @@
1
- import type { Nullable } from '@okam/stack-ui'
2
- import { mergeConfigs } from '../../utils'
3
- import BlockSerializer from '../BlockSerializer'
4
- import type { TBlockSerializerProps } from '../BlockSerializer/interface'
5
- import baseConfig from './config'
6
- import type { TBlockDispatcherProps } from './interface'
7
-
8
- const BlockDispatcher = (props: TBlockDispatcherProps) => {
9
- const { children, config, ...rest } = props
10
-
11
- const finalConfig = mergeConfigs(baseConfig, config)
12
-
13
- const renderBlock = (blockProps: Nullable<TBlockSerializerProps>) => {
14
- return children ? (
15
- children({ ...rest, ...blockProps, config: finalConfig })
16
- ) : (
17
- <BlockSerializer {...rest} {...blockProps} config={finalConfig} />
18
- )
19
- }
20
-
21
- if ('blocks' in props) {
22
- const { blocks } = props
23
- return blocks.map(renderBlock)
24
- }
25
-
26
- const { block } = props
27
- return renderBlock(block)
28
- }
29
-
30
- export default BlockDispatcher
@@ -1,17 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import type { TDefaultComponent, Nullable } from '@okam/stack-ui'
3
- import type React from 'react'
4
- import type { TAdditionalProps } from '../../types/block'
5
- import type { TBlockSerializerProps, TBlockSerializerConfig } from '../BlockSerializer/interface'
6
-
7
- interface TBaseBlockDispatcherProps<AdditionalProps extends TAdditionalProps = TAdditionalProps>
8
- extends Omit<TDefaultComponent, 'children'> {
9
- config?: TBlockSerializerConfig
10
- defaultVariant?: string
11
- additionalProps?: AdditionalProps
12
- children?: (props: TBlockSerializerProps) => React.ReactNode
13
- }
14
-
15
- export type TBlockDispatcherProps<AdditionalProps extends TAdditionalProps = TAdditionalProps> =
16
- | (TBaseBlockDispatcherProps<AdditionalProps> & { block: Nullable<TBlockSerializerProps> })
17
- | (TBaseBlockDispatcherProps<AdditionalProps> & { blocks: Nullable<TBlockSerializerProps>[] })
@@ -1,43 +0,0 @@
1
- import { BlockSettingsFragmentDoc } from '../../generated/graphql'
2
- import { getFragment } from '../../utils'
3
- import type { TBlockSerializerProps } from './interface'
4
-
5
- const BlockSerializer = (props: TBlockSerializerProps) => {
6
- const { item, collection, config, variables, defaultVariant, ...rest } = props
7
-
8
- if (!collection || !config) return null
9
-
10
- const blockConfig = config?.components?.[collection]
11
-
12
- if (!blockConfig) return null
13
-
14
- const { settings } = item ?? {}
15
- const id = item?.id ?? variables?.id
16
-
17
- if (!id) return null
18
-
19
- const { variant } = getFragment(BlockSettingsFragmentDoc, settings) ?? {}
20
-
21
- const variantWithFallback = blockConfig.getVariant?.(props) ?? variant ?? defaultVariant
22
-
23
- const { default: defaultBlockComponent, document } = blockConfig
24
-
25
- const variantBlockComponent = blockConfig.variants?.[variantWithFallback ?? '']
26
- const BlockComponent = variantBlockComponent ?? defaultBlockComponent
27
-
28
- if (!BlockComponent) return null
29
-
30
- return (
31
- <BlockComponent
32
- key={id}
33
- document={document}
34
- config={config}
35
- collection={collection}
36
- item={item}
37
- {...(id ? { variables: { ...variables, id } } : { variables })}
38
- {...rest}
39
- />
40
- )
41
- }
42
-
43
- export default BlockSerializer
@@ -1,51 +0,0 @@
1
- import { type TypedDocumentNode } from '@graphql-typed-document-node/core'
2
- import type { Nullable, TDefaultComponent } from '@okam/stack-ui'
3
- import type { Variables } from 'graphql-request'
4
- import type { FunctionComponent } from 'react'
5
- import type {
6
- TCommonBlockFragment,
7
- TAdditionalProps,
8
- TBlockQuery,
9
- TBlockVariables,
10
- TBlockDocument,
11
- } from '../../types/block'
12
-
13
- export interface TBlock<
14
- BlockFragment extends TCommonBlockFragment = TCommonBlockFragment,
15
- BlockVariables extends Variables = Variables,
16
- > {
17
- collection?: Nullable<string>
18
- item?: Nullable<BlockFragment>
19
- variables?: TBlockVariables<BlockVariables>
20
- document?: TypedDocumentNode<TBlockQuery<BlockFragment>, BlockVariables>
21
- }
22
-
23
- export type TBlockSerializerProps<
24
- BlockFragment extends TCommonBlockFragment = TCommonBlockFragment,
25
- BlockVariables extends Variables = TBlockVariables,
26
- AdditionalProps extends TAdditionalProps = TAdditionalProps,
27
- > = TBlock<BlockFragment, BlockVariables> &
28
- TDefaultComponent & {
29
- config?: TBlockSerializerConfig
30
- defaultVariant?: string
31
- additionalProps?: AdditionalProps
32
- }
33
-
34
- export type TBlockFunctionComponent<BlockFragment extends TCommonBlockFragment = TCommonBlockFragment> =
35
- FunctionComponent<TBlockSerializerProps<BlockFragment>>
36
-
37
- export type TBlockSerializerConfigComponent<BlockFragment extends TCommonBlockFragment = TCommonBlockFragment> = {
38
- [blockKey: string]: {
39
- default: TBlockFunctionComponent<BlockFragment>
40
- document?: TBlockDocument<BlockFragment>
41
- defaultVariant?: string
42
- getVariant?: (props: TBlockSerializerProps<BlockFragment>) => Nullable<string>
43
- variants?: {
44
- [blockVariant: string]: TBlockFunctionComponent<BlockFragment>
45
- }
46
- }
47
- }
48
-
49
- export interface TBlockSerializerConfig {
50
- components: TBlockSerializerConfigComponent
51
- }