@okam/directus-block 1.7.7 → 1.7.8
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 +7 -0
- package/blocks/BlockWysiwyg/config.d.ts +0 -1
- package/blocks/BlockWysiwyg/index.d.ts +1 -2
- package/blocks/BlockWysiwyg/index.js +23 -7
- package/blocks/BlockWysiwyg/index.mjs +7 -8
- package/blocks/BlockWysiwyg/interface.d.ts +0 -1
- package/components/BlockDispatcher/config.d.ts +0 -1
- package/components/BlockDispatcher/index.d.ts +1 -2
- package/components/BlockDispatcher/index.js +5 -8
- package/components/BlockDispatcher/index.mjs +5 -8
- package/components/BlockDispatcher/interface.d.ts +4 -5
- package/components/BlockSerializer/index.d.ts +1 -2
- package/components/BlockSerializer/index.js +14 -14
- package/components/BlockSerializer/index.mjs +14 -14
- package/components/BlockSerializer/interface.d.ts +4 -5
- package/generated/fragment-masking.d.ts +0 -1
- package/generated/graphql.d.ts +0 -1
- package/index.d.ts +5 -5
- package/index.js +2 -2
- package/index.mjs +1 -1
- package/package.json +14 -10
- package/types/block.d.ts +2 -3
- package/utils/getBlock.d.ts +5 -6
- package/utils/getBlock.js +1 -1
- package/utils/getBlock.mjs +1 -1
- package/utils/getBlockProps.d.ts +2 -3
- package/utils/getBlockProps.js +10 -5
- package/utils/getBlockProps.mjs +10 -5
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -2
- package/utils/index.mjs +0 -2
- package/utils/mergeConfigs.d.ts +0 -1
- package/utils/mergeConfigs.js +2 -1
- package/utils/mergeConfigs.mjs +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TBlockSerializerConfigComponent } from '../../components/BlockSerializer/interface';
|
|
2
2
|
import { BlockWysiwygFragment } from './interface';
|
|
3
|
-
|
|
4
3
|
declare const blockWysiwygConfig: TBlockSerializerConfigComponent<BlockWysiwygFragment>;
|
|
5
4
|
export default blockWysiwygConfig;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TBlockSerializerProps } from '../../components/BlockSerializer/interface';
|
|
2
2
|
import { BlockWysiwygFragment } from './interface';
|
|
3
|
-
|
|
4
|
-
declare const BlockWysiwyg: (props: TBlockSerializerProps<BlockWysiwygFragment>) => Promise<import("react/jsx-runtime").JSX.Element | null>;
|
|
3
|
+
declare function BlockWysiwyg(props: TBlockSerializerProps<BlockWysiwygFragment>): Promise<import("react/jsx-runtime").JSX.Element | null>;
|
|
5
4
|
export default BlockWysiwyg;
|
|
@@ -3,16 +3,32 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
3
3
|
const stackUi = require("@okam/stack-ui");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const getBlock = require("../../utils/getBlock.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== "default") {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: () => e[k]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
23
|
+
async function BlockWysiwyg(props) {
|
|
9
24
|
const key = "block_wysiwygs_by_id";
|
|
10
25
|
const { themeName = "wysiwyg", tokens } = props;
|
|
11
26
|
const { content, title, level, cmsTokens } = await getBlock.getBlock(props, key);
|
|
12
|
-
if (
|
|
27
|
+
if ((content == null || content === "") && !(title != null && title !== "" && (level != null && level !== "")))
|
|
28
|
+
return null;
|
|
13
29
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
14
|
-
title && level && /* @__PURE__ */ jsxRuntime.jsx(stackUi.Box, { as: "span", themeName, tokens: { ...tokens, ...cmsTokens }, children:
|
|
15
|
-
content && /* @__PURE__ */ jsxRuntime.jsx(stackUi.WysiwygBlock, { themeName, tokens: { ...tokens, ...cmsTokens }, content })
|
|
30
|
+
title != null && title !== "" && (level != null && level !== "") && /* @__PURE__ */ jsxRuntime.jsx(stackUi.Box, { as: "span", themeName, tokens: { ...tokens, ...cmsTokens }, children: React__namespace.createElement(level, {}, title) }),
|
|
31
|
+
content != null && content !== "" && /* @__PURE__ */ jsxRuntime.jsx(stackUi.WysiwygBlock, { themeName, tokens: { ...tokens, ...cmsTokens }, content })
|
|
16
32
|
] });
|
|
17
|
-
}
|
|
33
|
+
}
|
|
18
34
|
module.exports = BlockWysiwyg;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box, WysiwygBlock } from "@okam/stack-ui";
|
|
3
|
-
import React from "react";
|
|
3
|
+
import * as React from "react";
|
|
4
4
|
import { getBlock } from "../../utils/getBlock.mjs";
|
|
5
|
-
|
|
6
|
-
import "radashi";
|
|
7
|
-
const BlockWysiwyg = async (props) => {
|
|
5
|
+
async function BlockWysiwyg(props) {
|
|
8
6
|
const key = "block_wysiwygs_by_id";
|
|
9
7
|
const { themeName = "wysiwyg", tokens } = props;
|
|
10
8
|
const { content, title, level, cmsTokens } = await getBlock(props, key);
|
|
11
|
-
if (
|
|
9
|
+
if ((content == null || content === "") && !(title != null && title !== "" && (level != null && level !== "")))
|
|
10
|
+
return null;
|
|
12
11
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
13
|
-
title && level && /* @__PURE__ */ jsx(Box, { as: "span", themeName, tokens: { ...tokens, ...cmsTokens }, children: React.createElement(level, {}, title) }),
|
|
14
|
-
content && /* @__PURE__ */ jsx(WysiwygBlock, { themeName, tokens: { ...tokens, ...cmsTokens }, content })
|
|
12
|
+
title != null && title !== "" && (level != null && level !== "") && /* @__PURE__ */ jsx(Box, { as: "span", themeName, tokens: { ...tokens, ...cmsTokens }, children: React.createElement(level, {}, title) }),
|
|
13
|
+
content != null && content !== "" && /* @__PURE__ */ jsx(WysiwygBlock, { themeName, tokens: { ...tokens, ...cmsTokens }, content })
|
|
15
14
|
] });
|
|
16
|
-
}
|
|
15
|
+
}
|
|
17
16
|
export {
|
|
18
17
|
BlockWysiwyg as default
|
|
19
18
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { TBlockDispatcherProps } from './interface';
|
|
2
|
-
|
|
3
|
-
declare const BlockDispatcher: (props: TBlockDispatcherProps) => string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | (string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined)[] | null | undefined;
|
|
2
|
+
declare function BlockDispatcher(props: TBlockDispatcherProps): Promise<string | number | bigint | boolean | Iterable<import('react').ReactNode> | import("react/jsx-runtime").JSX.Element | Promise<Iterable<import('react').ReactNode> | import("react/jsx-runtime").JSX.Element | (string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined)>[] | null | undefined>;
|
|
4
3
|
export default BlockDispatcher;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
require("@okam/directus-query");
|
|
4
|
-
require("graphql-request");
|
|
5
|
-
require("radashi");
|
|
6
|
-
const mergeConfigs = require("../../utils/mergeConfigs.js");
|
|
7
3
|
const index = require("../BlockSerializer/index.js");
|
|
8
4
|
const config = require("./config.js");
|
|
9
|
-
const
|
|
5
|
+
const mergeConfigs = require("../../utils/mergeConfigs.js");
|
|
6
|
+
async function BlockDispatcher(props) {
|
|
10
7
|
const { children, config: config$1, ...rest } = props;
|
|
11
8
|
const finalConfig = mergeConfigs(config, config$1);
|
|
12
|
-
const renderBlock = (blockProps) => {
|
|
13
|
-
return children ? children({ ...rest, ...blockProps, config: finalConfig }) : /* @__PURE__ */ jsxRuntime.jsx(index, { ...rest, ...blockProps, config: finalConfig });
|
|
9
|
+
const renderBlock = async (blockProps) => {
|
|
10
|
+
return children != null ? children({ ...rest, ...blockProps, config: finalConfig }) : /* @__PURE__ */ jsxRuntime.jsx(index, { ...rest, ...blockProps, config: finalConfig });
|
|
14
11
|
};
|
|
15
12
|
if ("blocks" in props) {
|
|
16
13
|
const { blocks } = props;
|
|
@@ -18,5 +15,5 @@ const BlockDispatcher = (props) => {
|
|
|
18
15
|
}
|
|
19
16
|
const { block } = props;
|
|
20
17
|
return renderBlock(block);
|
|
21
|
-
}
|
|
18
|
+
}
|
|
22
19
|
module.exports = BlockDispatcher;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import "@okam/directus-query";
|
|
3
|
-
import "graphql-request";
|
|
4
|
-
import "radashi";
|
|
5
|
-
import mergeConfigs from "../../utils/mergeConfigs.mjs";
|
|
6
2
|
import BlockSerializer from "../BlockSerializer/index.mjs";
|
|
7
3
|
import baseConfig from "./config.mjs";
|
|
8
|
-
|
|
4
|
+
import mergeConfigs from "../../utils/mergeConfigs.mjs";
|
|
5
|
+
async function BlockDispatcher(props) {
|
|
9
6
|
const { children, config, ...rest } = props;
|
|
10
7
|
const finalConfig = mergeConfigs(baseConfig, config);
|
|
11
|
-
const renderBlock = (blockProps) => {
|
|
12
|
-
return children ? children({ ...rest, ...blockProps, config: finalConfig }) : /* @__PURE__ */ jsx(BlockSerializer, { ...rest, ...blockProps, config: finalConfig });
|
|
8
|
+
const renderBlock = async (blockProps) => {
|
|
9
|
+
return children != null ? children({ ...rest, ...blockProps, config: finalConfig }) : /* @__PURE__ */ jsx(BlockSerializer, { ...rest, ...blockProps, config: finalConfig });
|
|
13
10
|
};
|
|
14
11
|
if ("blocks" in props) {
|
|
15
12
|
const { blocks } = props;
|
|
@@ -17,7 +14,7 @@ const BlockDispatcher = (props) => {
|
|
|
17
14
|
}
|
|
18
15
|
const { block } = props;
|
|
19
16
|
return renderBlock(block);
|
|
20
|
-
}
|
|
17
|
+
}
|
|
21
18
|
export {
|
|
22
19
|
BlockDispatcher as default
|
|
23
20
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { default as React } from 'react';
|
|
1
|
+
import { Nullable, TDefaultComponent } from '@okam/stack-ui';
|
|
3
2
|
import { TAdditionalProps } from '../../types/block';
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { TBlockSerializerConfig, TBlockSerializerProps } from '../BlockSerializer/interface';
|
|
4
|
+
import type * as React from 'react';
|
|
6
5
|
interface TBaseBlockDispatcherProps<AdditionalProps extends TAdditionalProps = TAdditionalProps> extends Omit<TDefaultComponent, 'children'> {
|
|
7
6
|
config?: TBlockSerializerConfig;
|
|
8
7
|
defaultVariant?: string;
|
|
9
8
|
additionalProps?: AdditionalProps;
|
|
10
|
-
children?: (
|
|
9
|
+
children?: (_props: TBlockSerializerProps) => React.ReactNode;
|
|
11
10
|
}
|
|
12
11
|
export type TBlockDispatcherProps<AdditionalProps extends TAdditionalProps = TAdditionalProps> = (TBaseBlockDispatcherProps<AdditionalProps> & {
|
|
13
12
|
block: Nullable<TBlockSerializerProps>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { TBlockSerializerProps } from './interface';
|
|
2
|
-
|
|
3
|
-
declare const BlockSerializer: (props: TBlockSerializerProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
2
|
+
declare function BlockSerializer(props: TBlockSerializerProps): import("react/jsx-runtime").JSX.Element | null;
|
|
4
3
|
export default BlockSerializer;
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
3
|
const graphql = require("../../generated/graphql.js");
|
|
4
4
|
const fragmentMasking = require("../../generated/fragment-masking.js");
|
|
5
|
-
|
|
6
|
-
require("graphql-request");
|
|
7
|
-
require("radashi");
|
|
8
|
-
const BlockSerializer = (props) => {
|
|
9
|
-
var _a, _b, _c;
|
|
5
|
+
function BlockSerializer(props) {
|
|
10
6
|
const { item, collection, config, variables, defaultVariant, ...rest } = props;
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
if (collection == null || collection === "" || config == null)
|
|
8
|
+
return null;
|
|
9
|
+
const blockConfig = config?.components?.[collection];
|
|
10
|
+
if (blockConfig == null)
|
|
11
|
+
return null;
|
|
14
12
|
const { settings } = item ?? {};
|
|
15
|
-
const id =
|
|
16
|
-
if (
|
|
13
|
+
const id = item?.id ?? variables?.id;
|
|
14
|
+
if (id == null || id === "")
|
|
15
|
+
return null;
|
|
17
16
|
const { variant } = fragmentMasking.useFragment(graphql.BlockSettingsFragmentDoc, settings) ?? {};
|
|
18
|
-
const variantWithFallback =
|
|
17
|
+
const variantWithFallback = blockConfig.getVariant?.(props) ?? variant ?? defaultVariant;
|
|
19
18
|
const { default: defaultBlockComponent, document } = blockConfig;
|
|
20
|
-
const variantBlockComponent =
|
|
19
|
+
const variantBlockComponent = blockConfig.variants?.[variantWithFallback ?? ""];
|
|
21
20
|
const BlockComponent = variantBlockComponent ?? defaultBlockComponent;
|
|
22
|
-
if (
|
|
21
|
+
if (BlockComponent == null)
|
|
22
|
+
return null;
|
|
23
23
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
24
24
|
BlockComponent,
|
|
25
25
|
{
|
|
@@ -32,5 +32,5 @@ const BlockSerializer = (props) => {
|
|
|
32
32
|
},
|
|
33
33
|
id
|
|
34
34
|
);
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
module.exports = BlockSerializer;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { BlockSettingsFragmentDoc } from "../../generated/graphql.mjs";
|
|
3
3
|
import { useFragment } from "../../generated/fragment-masking.mjs";
|
|
4
|
-
|
|
5
|
-
import "graphql-request";
|
|
6
|
-
import "radashi";
|
|
7
|
-
const BlockSerializer = (props) => {
|
|
8
|
-
var _a, _b, _c;
|
|
4
|
+
function BlockSerializer(props) {
|
|
9
5
|
const { item, collection, config, variables, defaultVariant, ...rest } = props;
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
if (collection == null || collection === "" || config == null)
|
|
7
|
+
return null;
|
|
8
|
+
const blockConfig = config?.components?.[collection];
|
|
9
|
+
if (blockConfig == null)
|
|
10
|
+
return null;
|
|
13
11
|
const { settings } = item ?? {};
|
|
14
|
-
const id =
|
|
15
|
-
if (
|
|
12
|
+
const id = item?.id ?? variables?.id;
|
|
13
|
+
if (id == null || id === "")
|
|
14
|
+
return null;
|
|
16
15
|
const { variant } = useFragment(BlockSettingsFragmentDoc, settings) ?? {};
|
|
17
|
-
const variantWithFallback =
|
|
16
|
+
const variantWithFallback = blockConfig.getVariant?.(props) ?? variant ?? defaultVariant;
|
|
18
17
|
const { default: defaultBlockComponent, document } = blockConfig;
|
|
19
|
-
const variantBlockComponent =
|
|
18
|
+
const variantBlockComponent = blockConfig.variants?.[variantWithFallback ?? ""];
|
|
20
19
|
const BlockComponent = variantBlockComponent ?? defaultBlockComponent;
|
|
21
|
-
if (
|
|
20
|
+
if (BlockComponent == null)
|
|
21
|
+
return null;
|
|
22
22
|
return /* @__PURE__ */ jsx(
|
|
23
23
|
BlockComponent,
|
|
24
24
|
{
|
|
@@ -31,7 +31,7 @@ const BlockSerializer = (props) => {
|
|
|
31
31
|
},
|
|
32
32
|
id
|
|
33
33
|
);
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
export {
|
|
36
36
|
BlockSerializer as default
|
|
37
37
|
};
|
|
@@ -2,8 +2,7 @@ import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
|
2
2
|
import { Nullable, TDefaultComponent } from '@okam/stack-ui';
|
|
3
3
|
import { Variables as GraphQLVariables } from 'graphql-request';
|
|
4
4
|
import { FunctionComponent } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { TAdditionalProps, TBlockDocument, TBlockQuery, TBlockVariables, TCommonBlockFragment } from '../../types/block';
|
|
7
6
|
/**
|
|
8
7
|
* Base block data. See {@link TBlockSerializerProps} for actual props implementation.
|
|
9
8
|
*/
|
|
@@ -70,7 +69,7 @@ export type TBlockFunctionComponent<Fragment extends TCommonBlockFragment = TCom
|
|
|
70
69
|
* }
|
|
71
70
|
* ```
|
|
72
71
|
*/
|
|
73
|
-
export
|
|
72
|
+
export interface TBlockSerializerConfigComponent<Fragment extends TCommonBlockFragment = TCommonBlockFragment, Variables extends GraphQLVariables = TBlockVariables, AdditionalProps extends TAdditionalProps = TAdditionalProps> {
|
|
74
73
|
[blockKey: string]: {
|
|
75
74
|
default: TBlockFunctionComponent<Fragment, Variables, AdditionalProps>;
|
|
76
75
|
/**
|
|
@@ -84,12 +83,12 @@ export type TBlockSerializerConfigComponent<Fragment extends TCommonBlockFragmen
|
|
|
84
83
|
/**
|
|
85
84
|
* A callback to specify a different variant path from the one in the block's settings.
|
|
86
85
|
*/
|
|
87
|
-
getVariant?: (
|
|
86
|
+
getVariant?: (_props: TBlockSerializerProps<Fragment, Variables, AdditionalProps>) => Nullable<string>;
|
|
88
87
|
variants?: {
|
|
89
88
|
[blockVariant: string]: TBlockFunctionComponent<Fragment, Variables, AdditionalProps>;
|
|
90
89
|
};
|
|
91
90
|
};
|
|
92
|
-
}
|
|
91
|
+
}
|
|
93
92
|
/**
|
|
94
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.
|
|
95
94
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
2
|
import { Incremental } from './graphql';
|
|
3
|
-
|
|
4
3
|
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<infer TType, any> ? [TType] extends [{
|
|
5
4
|
' $fragmentName'?: infer TKey;
|
|
6
5
|
}] ? TKey extends string ? {
|
package/generated/graphql.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './utils';
|
|
2
|
-
export type { BlockSettingsFragment } from './generated/graphql';
|
|
3
|
-
export type { TBlockDispatcherProps } from './components/BlockDispatcher/interface';
|
|
4
|
-
export type { TBlockSerializerConfig, TBlockSerializerProps, TBlock, TBlockSerializerConfigComponent, } from './components/BlockSerializer/interface';
|
|
5
|
-
export type { TAdditionalProps, TCommonBlockFragment, TBlockQuery, TBlockDocument, TBlockVariables, } from './types/block';
|
|
6
1
|
export { default as BlockWysiwyg } from './blocks/BlockWysiwyg';
|
|
7
2
|
export { default as blockWysiwygConfig } from './blocks/BlockWysiwyg/config';
|
|
8
3
|
export { default as baseConfig } from './components/BlockDispatcher/config';
|
|
4
|
+
export type { TBlockDispatcherProps } from './components/BlockDispatcher/interface';
|
|
5
|
+
export type { TBlock, TBlockSerializerConfig, TBlockSerializerConfigComponent, TBlockSerializerProps, } from './components/BlockSerializer/interface';
|
|
6
|
+
export type { BlockSettingsFragment } from './generated/graphql';
|
|
7
|
+
export type { TAdditionalProps, TBlockDocument, TBlockQuery, TBlockVariables, TCommonBlockFragment, } from './types/block';
|
|
8
|
+
export * from './utils';
|
package/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const index$1 = require("./utils/index.js");
|
|
4
3
|
const index = require("./blocks/BlockWysiwyg/index.js");
|
|
5
4
|
const config = require("./blocks/BlockWysiwyg/config.js");
|
|
6
5
|
const config$1 = require("./components/BlockDispatcher/config.js");
|
|
6
|
+
const index$1 = require("./utils/index.js");
|
|
7
7
|
const getBlockProps = require("./utils/getBlockProps.js");
|
|
8
8
|
const mergeConfigs = require("./utils/mergeConfigs.js");
|
|
9
9
|
const fragmentMasking = require("./generated/fragment-masking.js");
|
|
10
10
|
const getBlock = require("./utils/getBlock.js");
|
|
11
|
-
exports.useBlock = index$1.useBlock;
|
|
12
11
|
exports.BlockWysiwyg = index;
|
|
13
12
|
exports.blockWysiwygConfig = config;
|
|
14
13
|
exports.baseConfig = config$1;
|
|
14
|
+
exports.useBlock = index$1.useBlock;
|
|
15
15
|
exports.getBlockProps = getBlockProps;
|
|
16
16
|
exports.mergeConfigs = mergeConfigs;
|
|
17
17
|
exports.getFragment = fragmentMasking.useFragment;
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useBlock } from "./utils/index.mjs";
|
|
2
1
|
import { default as default2 } from "./blocks/BlockWysiwyg/index.mjs";
|
|
3
2
|
import { default as default3 } from "./blocks/BlockWysiwyg/config.mjs";
|
|
4
3
|
import { default as default4 } from "./components/BlockDispatcher/config.mjs";
|
|
4
|
+
import { useBlock } from "./utils/index.mjs";
|
|
5
5
|
import { default as default5 } from "./utils/getBlockProps.mjs";
|
|
6
6
|
import { default as default6 } from "./utils/mergeConfigs.mjs";
|
|
7
7
|
import { useFragment } from "./generated/fragment-masking.mjs";
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okam/directus-block",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "1.7.8",
|
|
4
|
+
"repository": {
|
|
5
|
+
"url": "https://github.com/OKAMca/stack.git"
|
|
6
|
+
},
|
|
7
|
+
"sideEffects": false,
|
|
6
8
|
"exports": {
|
|
7
9
|
".": {
|
|
8
10
|
"import": {
|
|
@@ -25,23 +27,25 @@
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
},
|
|
30
|
+
"main": "./index.js",
|
|
31
|
+
"types": "./index.d.ts",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.19.0"
|
|
34
|
+
},
|
|
28
35
|
"publishConfig": {
|
|
29
36
|
"access": "public"
|
|
30
37
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
33
40
|
},
|
|
34
41
|
"dependencies": {
|
|
35
42
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
36
|
-
"@okam/directus-query": "1.5.
|
|
37
|
-
"@okam/stack-ui": "1.44.
|
|
43
|
+
"@okam/directus-query": "1.5.3",
|
|
44
|
+
"@okam/stack-ui": "1.44.4",
|
|
38
45
|
"graphql": "^16.9.0",
|
|
39
46
|
"graphql-request": "^7.1.2",
|
|
40
47
|
"radashi": "^12.3.0"
|
|
41
48
|
},
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
44
|
-
},
|
|
45
49
|
"devDependencies": {
|
|
46
50
|
"react": "^19.0.0"
|
|
47
51
|
}
|
package/types/block.d.ts
CHANGED
|
@@ -3,10 +3,9 @@ import { Nullable } from '@okam/stack-ui';
|
|
|
3
3
|
import { Variables } from 'graphql-request';
|
|
4
4
|
import { FragmentType } from '../generated/fragment-masking';
|
|
5
5
|
import { BlockSettingsFragment } from '../generated/graphql';
|
|
6
|
-
|
|
7
|
-
export type TAdditionalProps = {
|
|
6
|
+
export interface TAdditionalProps {
|
|
8
7
|
[key: string]: unknown;
|
|
9
|
-
}
|
|
8
|
+
}
|
|
10
9
|
type BlockSettings = FragmentType<DocumentTypeDecoration<BlockSettingsFragment, unknown>>;
|
|
11
10
|
export type TCommonBlockFragment = {
|
|
12
11
|
id?: Nullable<string>;
|
package/utils/getBlock.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { TToken } from '@okam/stack-ui';
|
|
2
|
-
import { GraphQLClient } from 'graphql-request';
|
|
3
2
|
import { TBlockSerializerProps } from '../components/BlockSerializer/interface';
|
|
4
3
|
import { TBlockDocument, TBlockVariables, TCommonBlockFragment } from '../types/block';
|
|
5
|
-
|
|
4
|
+
import { GraphQLClient } from 'graphql-request';
|
|
6
5
|
/**
|
|
7
6
|
* 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.
|
|
8
7
|
* @param props Props of the block component. Pass props directly from the block component.
|
|
@@ -20,17 +19,17 @@ import { TBlockDocument, TBlockVariables, TCommonBlockFragment } from '../types/
|
|
|
20
19
|
* }
|
|
21
20
|
* ```
|
|
22
21
|
*/
|
|
23
|
-
export declare function getBlock<Fragment extends TCommonBlockFragment, Variables extends TBlockVariables = TBlockVariables>(
|
|
22
|
+
export declare function getBlock<Fragment extends TCommonBlockFragment, Variables extends TBlockVariables = TBlockVariables>(_props: TBlockSerializerProps<Fragment, Variables>, _blockKey: string,
|
|
24
23
|
/**
|
|
25
24
|
* @default defaultGraphqlRequestClient
|
|
26
25
|
*/
|
|
27
|
-
|
|
26
|
+
_client?: GraphQLClient): Promise<Fragment & {
|
|
28
27
|
cmsTokens: TToken;
|
|
29
28
|
}>;
|
|
30
|
-
export declare function getBlock<Fragment extends TCommonBlockFragment, Variables extends TBlockVariables = TBlockVariables>(
|
|
29
|
+
export declare function getBlock<Fragment extends TCommonBlockFragment, Variables extends TBlockVariables = TBlockVariables>(_props: TBlockSerializerProps<Fragment, Variables>, _blockKey: string,
|
|
31
30
|
/**
|
|
32
31
|
* @deprecated Use props.document instead
|
|
33
32
|
*/
|
|
34
|
-
|
|
33
|
+
_doc?: TBlockDocument<Fragment, Variables>): Promise<Fragment & {
|
|
35
34
|
cmsTokens: TToken;
|
|
36
35
|
}>;
|
package/utils/getBlock.js
CHANGED
|
@@ -23,7 +23,7 @@ async function getBlock(props, blockKey, docOrClient = directusQuery.defaultGrap
|
|
|
23
23
|
},
|
|
24
24
|
isPropClient ? docOrClient : void 0
|
|
25
25
|
);
|
|
26
|
-
const { tokens } = fragmentMasking.useFragment(graphql.BlockSettingsFragmentDoc, propsWithFallback
|
|
26
|
+
const { tokens } = fragmentMasking.useFragment(graphql.BlockSettingsFragmentDoc, propsWithFallback?.settings) ?? {};
|
|
27
27
|
return { ...propsWithFallback, cmsTokens: tokens };
|
|
28
28
|
}
|
|
29
29
|
exports.getBlock = getBlock;
|
package/utils/getBlock.mjs
CHANGED
|
@@ -21,7 +21,7 @@ async function getBlock(props, blockKey, docOrClient = defaultGraphqlRequestClie
|
|
|
21
21
|
},
|
|
22
22
|
isPropClient ? docOrClient : void 0
|
|
23
23
|
);
|
|
24
|
-
const { tokens } = useFragment(BlockSettingsFragmentDoc, propsWithFallback
|
|
24
|
+
const { tokens } = useFragment(BlockSettingsFragmentDoc, propsWithFallback?.settings) ?? {};
|
|
25
25
|
return { ...propsWithFallback, cmsTokens: tokens };
|
|
26
26
|
}
|
|
27
27
|
export {
|
package/utils/getBlockProps.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Nullable } from '@okam/stack-ui';
|
|
2
2
|
import { Variables } from 'graphql-request';
|
|
3
3
|
import { TBlockDocument, TBlockQuery, TBlockVariables, TCommonBlockFragment } from '../types/block';
|
|
4
|
-
|
|
5
|
-
type TGetBlockPropsParams<BlockFragment extends TCommonBlockFragment, BlockVariables extends Variables = Variables> = {
|
|
4
|
+
interface TGetBlockPropsParams<BlockFragment extends TCommonBlockFragment, BlockVariables extends Variables = Variables> {
|
|
6
5
|
document?: TBlockDocument<BlockFragment, BlockVariables>;
|
|
7
6
|
item?: Nullable<NonNullable<NonNullable<TBlockQuery<BlockFragment>[string]>[' $fragmentRefs']>[string]>;
|
|
8
7
|
blockKey?: string;
|
|
9
8
|
variables?: TBlockVariables<BlockVariables>;
|
|
10
|
-
}
|
|
9
|
+
}
|
|
11
10
|
/**
|
|
12
11
|
* Returns the passed item if it is defined. Otherwise, queried its own block
|
|
13
12
|
* @param params.blockKey Key of the queried field
|
package/utils/getBlockProps.js
CHANGED
|
@@ -11,9 +11,11 @@ function isItemEmpty(item) {
|
|
|
11
11
|
}
|
|
12
12
|
async function queryFromVariables(params, client = directusQuery.defaultGraphqlRequestClient) {
|
|
13
13
|
const { document, blockKey, variables } = params;
|
|
14
|
-
if (
|
|
14
|
+
if (document == null || !isVariables(variables))
|
|
15
|
+
return null;
|
|
15
16
|
const queriedBlockProps = await directusQuery.queryGql(document, variables, client);
|
|
16
|
-
if (
|
|
17
|
+
if (queriedBlockProps == null || typeof queriedBlockProps !== "object" || blockKey == null)
|
|
18
|
+
return null;
|
|
17
19
|
const queriedBlockFragment = queriedBlockProps[blockKey];
|
|
18
20
|
return queriedBlockFragment;
|
|
19
21
|
}
|
|
@@ -24,15 +26,18 @@ async function getBlockProps(params, client = directusQuery.defaultGraphqlReques
|
|
|
24
26
|
return item;
|
|
25
27
|
}
|
|
26
28
|
const variablesWithFallback = { id: item.id, ...variables };
|
|
27
|
-
if (!isVariables(variablesWithFallback))
|
|
29
|
+
if (!isVariables(variablesWithFallback))
|
|
30
|
+
return null;
|
|
28
31
|
return queryFromVariables({
|
|
29
32
|
...params,
|
|
30
33
|
variables: variablesWithFallback
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
|
-
if (
|
|
36
|
+
if (document == null || !isVariables(variables))
|
|
37
|
+
return null;
|
|
34
38
|
const queriedBlockProps = await directusQuery.queryGql(document, variables, client);
|
|
35
|
-
if (
|
|
39
|
+
if (queriedBlockProps == null || typeof queriedBlockProps !== "object" || blockKey == null)
|
|
40
|
+
return null;
|
|
36
41
|
const queriedBlockFragment = queriedBlockProps[blockKey];
|
|
37
42
|
return queriedBlockFragment;
|
|
38
43
|
}
|
package/utils/getBlockProps.mjs
CHANGED
|
@@ -10,9 +10,11 @@ function isItemEmpty(item) {
|
|
|
10
10
|
}
|
|
11
11
|
async function queryFromVariables(params, client = defaultGraphqlRequestClient) {
|
|
12
12
|
const { document, blockKey, variables } = params;
|
|
13
|
-
if (
|
|
13
|
+
if (document == null || !isVariables(variables))
|
|
14
|
+
return null;
|
|
14
15
|
const queriedBlockProps = await queryGql(document, variables, client);
|
|
15
|
-
if (
|
|
16
|
+
if (queriedBlockProps == null || typeof queriedBlockProps !== "object" || blockKey == null)
|
|
17
|
+
return null;
|
|
16
18
|
const queriedBlockFragment = queriedBlockProps[blockKey];
|
|
17
19
|
return queriedBlockFragment;
|
|
18
20
|
}
|
|
@@ -23,15 +25,18 @@ async function getBlockProps(params, client = defaultGraphqlRequestClient) {
|
|
|
23
25
|
return item;
|
|
24
26
|
}
|
|
25
27
|
const variablesWithFallback = { id: item.id, ...variables };
|
|
26
|
-
if (!isVariables(variablesWithFallback))
|
|
28
|
+
if (!isVariables(variablesWithFallback))
|
|
29
|
+
return null;
|
|
27
30
|
return queryFromVariables({
|
|
28
31
|
...params,
|
|
29
32
|
variables: variablesWithFallback
|
|
30
33
|
});
|
|
31
34
|
}
|
|
32
|
-
if (
|
|
35
|
+
if (document == null || !isVariables(variables))
|
|
36
|
+
return null;
|
|
33
37
|
const queriedBlockProps = await queryGql(document, variables, client);
|
|
34
|
-
if (
|
|
38
|
+
if (queriedBlockProps == null || typeof queriedBlockProps !== "object" || blockKey == null)
|
|
39
|
+
return null;
|
|
35
40
|
const queriedBlockFragment = queriedBlockProps[blockKey];
|
|
36
41
|
return queriedBlockFragment;
|
|
37
42
|
}
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const getBlock = require("./getBlock.js");
|
|
4
|
-
require("@okam/directus-query");
|
|
5
|
-
require("radashi");
|
|
6
4
|
const useBlock = getBlock.getBlock;
|
|
7
5
|
exports.getBlock = getBlock.getBlock;
|
|
8
6
|
exports.useBlock = useBlock;
|
package/utils/index.mjs
CHANGED
package/utils/mergeConfigs.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Nullable } from '@okam/stack-ui';
|
|
2
2
|
import { TBlockSerializerConfig } from '../components/BlockSerializer/interface';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Merges multiple block dispatcher configs
|
|
6
5
|
* @param baseConfig The base configuration. Other configurations will be prioritized over this one, which acts as a fallback
|
package/utils/mergeConfigs.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
function mergeConfigs(baseConfig, ...configs) {
|
|
3
3
|
const finalConfig = configs.reduce((mergedConfig, config) => {
|
|
4
|
-
if (
|
|
4
|
+
if (config == null)
|
|
5
|
+
return mergedConfig;
|
|
5
6
|
return { components: { ...mergedConfig.components, ...config.components } };
|
|
6
7
|
}, baseConfig);
|
|
7
8
|
return finalConfig;
|
package/utils/mergeConfigs.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
function mergeConfigs(baseConfig, ...configs) {
|
|
2
2
|
const finalConfig = configs.reduce((mergedConfig, config) => {
|
|
3
|
-
if (
|
|
3
|
+
if (config == null)
|
|
4
|
+
return mergedConfig;
|
|
4
5
|
return { components: { ...mergedConfig.components, ...config.components } };
|
|
5
6
|
}, baseConfig);
|
|
6
7
|
return finalConfig;
|