@okam/directus-block 1.2.2 → 1.3.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.
Files changed (39) hide show
  1. package/components/BlockDispatcher/index.d.ts +5 -0
  2. package/components/BlockSerializer/index.d.ts +3 -0
  3. package/directus-block/src/blocks/BlockWysiwyg/config.js +9 -0
  4. package/directus-block/src/blocks/BlockWysiwyg/config.mjs +10 -0
  5. package/directus-block/src/blocks/BlockWysiwyg/index.js +16 -0
  6. package/directus-block/src/blocks/BlockWysiwyg/index.mjs +17 -0
  7. package/directus-block/src/components/BlockDispatcher/config.js +8 -0
  8. package/directus-block/src/components/BlockDispatcher/config.mjs +9 -0
  9. package/directus-block/src/components/BlockDispatcher/index.js +24 -0
  10. package/directus-block/src/components/BlockDispatcher/index.mjs +25 -0
  11. package/directus-block/src/components/BlockSerializer/index.js +38 -0
  12. package/directus-block/src/components/BlockSerializer/index.mjs +39 -0
  13. package/directus-block/src/generated/fragment-masking.js +6 -0
  14. package/directus-block/src/generated/fragment-masking.mjs +6 -0
  15. package/directus-block/src/generated/graphql.js +4 -0
  16. package/directus-block/src/generated/graphql.mjs +4 -0
  17. package/directus-block/src/hooks/useBlock.js +19 -0
  18. package/directus-block/src/hooks/useBlock.mjs +20 -0
  19. package/directus-block/src/index.js +10 -0
  20. package/directus-block/src/index.mjs +10 -0
  21. package/directus-block/src/server.js +11 -0
  22. package/directus-block/src/server.mjs +11 -0
  23. package/directus-block/src/utils/get-block-props.js +42 -0
  24. package/directus-block/src/utils/get-block-props.mjs +43 -0
  25. package/directus-block/src/utils/merge-configs.js +9 -0
  26. package/directus-block/src/utils/merge-configs.mjs +10 -0
  27. package/directus-query/src/lib/config.js +3 -0
  28. package/directus-query/src/lib/config.mjs +2 -0
  29. package/directus-query/src/lib/query.js +10 -0
  30. package/directus-query/src/lib/query.mjs +10 -0
  31. package/directus-query/src/lib/request.js +38 -0
  32. package/directus-query/src/lib/request.mjs +38 -0
  33. package/hooks/useBlock.d.ts +8 -0
  34. package/index.d.ts +2 -0
  35. package/package.json +5 -1
  36. package/server.d.ts +4 -0
  37. package/index.js +0 -96
  38. package/index.mjs +0 -5966
  39. package/style.css +0 -1
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="react/experimental" />
3
+ import type { TBlockDispatcherProps } from './interface';
4
+ declare const BlockDispatcher: (props: TBlockDispatcherProps) => string | number | boolean | Iterable<import("react").ReactNode> | import("react").PromiseLikeOfReactNode | import("react/jsx-runtime").JSX.Element | (string | number | boolean | Iterable<import("react").ReactNode> | import("react").PromiseLikeOfReactNode | import("react/jsx-runtime").JSX.Element | null | undefined)[] | null | undefined;
5
+ export default BlockDispatcher;
@@ -0,0 +1,3 @@
1
+ import type { TBlockSerializerProps } from './interface';
2
+ declare const BlockSerializer: (props: TBlockSerializerProps) => import("react/jsx-runtime").JSX.Element | null;
3
+ export default BlockSerializer;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const index = require("./index.js");
4
+ const blockWysiwygConfig = {
5
+ block_wysiwyg: {
6
+ default: (props) => /* @__PURE__ */ jsxRuntime.jsx(index, { ...props })
7
+ }
8
+ };
9
+ module.exports = blockWysiwygConfig;
@@ -0,0 +1,10 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import BlockWysiwyg from "./index.mjs";
3
+ const blockWysiwygConfig = {
4
+ block_wysiwyg: {
5
+ default: (props) => /* @__PURE__ */ jsx(BlockWysiwyg, { ...props })
6
+ }
7
+ };
8
+ export {
9
+ blockWysiwygConfig as default
10
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const stackUi = require("@okam/stack-ui");
4
+ const React = require("react");
5
+ const useBlock = require("../../hooks/useBlock.js");
6
+ const BlockWysiwyg = async (props) => {
7
+ const key = "block_wysiwyg_by_id";
8
+ const { themeName = "wysiwyg", tokens } = props;
9
+ const { content, title, level, cmsTokens } = await useBlock(props, key);
10
+ if (!content && !(title && level)) return null;
11
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
12
+ title && level && /* @__PURE__ */ jsxRuntime.jsx(stackUi.Box, { as: "span", themeName, tokens: { ...tokens, ...cmsTokens }, children: React.createElement(level, {}, title) }),
13
+ content && /* @__PURE__ */ jsxRuntime.jsx(stackUi.WysiwygBlock, { themeName, tokens: { ...tokens, ...cmsTokens }, content })
14
+ ] });
15
+ };
16
+ module.exports = BlockWysiwyg;
@@ -0,0 +1,17 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { Box, WysiwygBlock } from "@okam/stack-ui";
3
+ import React from "react";
4
+ import useBlock from "../../hooks/useBlock.mjs";
5
+ const BlockWysiwyg = async (props) => {
6
+ const key = "block_wysiwyg_by_id";
7
+ const { themeName = "wysiwyg", tokens } = props;
8
+ const { content, title, level, cmsTokens } = await useBlock(props, key);
9
+ if (!content && !(title && level)) return null;
10
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
11
+ title && level && /* @__PURE__ */ jsx(Box, { as: "span", themeName, tokens: { ...tokens, ...cmsTokens }, children: React.createElement(level, {}, title) }),
12
+ content && /* @__PURE__ */ jsx(WysiwygBlock, { themeName, tokens: { ...tokens, ...cmsTokens }, content })
13
+ ] });
14
+ };
15
+ export {
16
+ BlockWysiwyg as default
17
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ const config = require("../../blocks/BlockWysiwyg/config.js");
3
+ const baseConfig = {
4
+ components: {
5
+ ...config
6
+ }
7
+ };
8
+ module.exports = baseConfig;
@@ -0,0 +1,9 @@
1
+ import blockWysiwygConfig from "../../blocks/BlockWysiwyg/config.mjs";
2
+ const baseConfig = {
3
+ components: {
4
+ ...blockWysiwygConfig
5
+ }
6
+ };
7
+ export {
8
+ baseConfig as default
9
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ require("@tanstack/react-query");
4
+ require("radash");
5
+ require("../../../../directus-query/src/lib/request.js");
6
+ require("graphql-request");
7
+ require("../../../../directus-query/src/lib/config.js");
8
+ const mergeConfigs = require("../../utils/merge-configs.js");
9
+ const index = require("../BlockSerializer/index.js");
10
+ const config = require("./config.js");
11
+ const BlockDispatcher = (props) => {
12
+ const { children, config: config$1, ...rest } = props;
13
+ const finalConfig = mergeConfigs(config, config$1);
14
+ const renderBlock = (blockProps) => {
15
+ return children ? children({ ...rest, ...blockProps, config: finalConfig }) : /* @__PURE__ */ jsxRuntime.jsx(index, { ...rest, ...blockProps, config: finalConfig });
16
+ };
17
+ if ("blocks" in props) {
18
+ const { blocks } = props;
19
+ return blocks.map(renderBlock);
20
+ }
21
+ const { block } = props;
22
+ return renderBlock(block);
23
+ };
24
+ module.exports = BlockDispatcher;
@@ -0,0 +1,25 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "@tanstack/react-query";
3
+ import "radash";
4
+ import "../../../../directus-query/src/lib/request.mjs";
5
+ import "graphql-request";
6
+ import "../../../../directus-query/src/lib/config.mjs";
7
+ import mergeConfigs from "../../utils/merge-configs.mjs";
8
+ import BlockSerializer from "../BlockSerializer/index.mjs";
9
+ import baseConfig from "./config.mjs";
10
+ const BlockDispatcher = (props) => {
11
+ const { children, config, ...rest } = props;
12
+ const finalConfig = mergeConfigs(baseConfig, config);
13
+ const renderBlock = (blockProps) => {
14
+ return children ? children({ ...rest, ...blockProps, config: finalConfig }) : /* @__PURE__ */ jsx(BlockSerializer, { ...rest, ...blockProps, config: finalConfig });
15
+ };
16
+ if ("blocks" in props) {
17
+ const { blocks } = props;
18
+ return blocks.map(renderBlock);
19
+ }
20
+ const { block } = props;
21
+ return renderBlock(block);
22
+ };
23
+ export {
24
+ BlockDispatcher as default
25
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const graphql = require("../../generated/graphql.js");
4
+ const fragmentMasking = require("../../generated/fragment-masking.js");
5
+ require("@tanstack/react-query");
6
+ require("radash");
7
+ require("../../../../directus-query/src/lib/request.js");
8
+ require("graphql-request");
9
+ require("../../../../directus-query/src/lib/config.js");
10
+ const BlockSerializer = (props) => {
11
+ var _a, _b, _c;
12
+ const { item, collection, config, variables, defaultVariant, ...rest } = props;
13
+ if (!collection || !config) return null;
14
+ const blockConfig = (_a = config == null ? void 0 : config.components) == null ? void 0 : _a[collection];
15
+ if (!blockConfig) return null;
16
+ const { settings } = item ?? {};
17
+ const id = (item == null ? void 0 : item.id) ?? (variables == null ? void 0 : variables.id);
18
+ if (!id) return null;
19
+ const { variant } = fragmentMasking.useFragment(graphql.BlockSettingsFragmentDoc, settings) ?? {};
20
+ const variantWithFallback = ((_b = blockConfig.getVariant) == null ? void 0 : _b.call(blockConfig, props)) ?? variant ?? defaultVariant;
21
+ const { default: defaultBlockComponent, document } = blockConfig;
22
+ const variantBlockComponent = (_c = blockConfig.variants) == null ? void 0 : _c[variantWithFallback ?? ""];
23
+ const BlockComponent = variantBlockComponent ?? defaultBlockComponent;
24
+ if (!BlockComponent) return null;
25
+ return /* @__PURE__ */ jsxRuntime.jsx(
26
+ BlockComponent,
27
+ {
28
+ document,
29
+ config,
30
+ collection,
31
+ item,
32
+ ...id ? { variables: { ...variables, id } } : { variables },
33
+ ...rest
34
+ },
35
+ id
36
+ );
37
+ };
38
+ module.exports = BlockSerializer;
@@ -0,0 +1,39 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { BlockSettingsFragmentDoc } from "../../generated/graphql.mjs";
3
+ import { useFragment } from "../../generated/fragment-masking.mjs";
4
+ import "@tanstack/react-query";
5
+ import "radash";
6
+ import "../../../../directus-query/src/lib/request.mjs";
7
+ import "graphql-request";
8
+ import "../../../../directus-query/src/lib/config.mjs";
9
+ const BlockSerializer = (props) => {
10
+ var _a, _b, _c;
11
+ const { item, collection, config, variables, defaultVariant, ...rest } = props;
12
+ if (!collection || !config) return null;
13
+ const blockConfig = (_a = config == null ? void 0 : config.components) == null ? void 0 : _a[collection];
14
+ if (!blockConfig) return null;
15
+ const { settings } = item ?? {};
16
+ const id = (item == null ? void 0 : item.id) ?? (variables == null ? void 0 : variables.id);
17
+ if (!id) return null;
18
+ const { variant } = useFragment(BlockSettingsFragmentDoc, settings) ?? {};
19
+ const variantWithFallback = ((_b = blockConfig.getVariant) == null ? void 0 : _b.call(blockConfig, props)) ?? variant ?? defaultVariant;
20
+ const { default: defaultBlockComponent, document } = blockConfig;
21
+ const variantBlockComponent = (_c = blockConfig.variants) == null ? void 0 : _c[variantWithFallback ?? ""];
22
+ const BlockComponent = variantBlockComponent ?? defaultBlockComponent;
23
+ if (!BlockComponent) return null;
24
+ return /* @__PURE__ */ jsx(
25
+ BlockComponent,
26
+ {
27
+ document,
28
+ config,
29
+ collection,
30
+ item,
31
+ ...id ? { variables: { ...variables, id } } : { variables },
32
+ ...rest
33
+ },
34
+ id
35
+ );
36
+ };
37
+ export {
38
+ BlockSerializer as default
39
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function useFragment(_documentNode, fragmentType) {
4
+ return fragmentType;
5
+ }
6
+ exports.useFragment = useFragment;
@@ -0,0 +1,6 @@
1
+ function useFragment(_documentNode, fragmentType) {
2
+ return fragmentType;
3
+ }
4
+ export {
5
+ useFragment
6
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const BlockSettingsFragmentDoc = { "kind": "Document", "definitions": [{ "kind": "FragmentDefinition", "name": { "kind": "Name", "value": "BlockSettings" }, "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "block_settings" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "tokens" } }, { "kind": "Field", "name": { "kind": "Name", "value": "variant" } }] } }] };
4
+ exports.BlockSettingsFragmentDoc = BlockSettingsFragmentDoc;
@@ -0,0 +1,4 @@
1
+ const BlockSettingsFragmentDoc = { "kind": "Document", "definitions": [{ "kind": "FragmentDefinition", "name": { "kind": "Name", "value": "BlockSettings" }, "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "block_settings" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "tokens" } }, { "kind": "Field", "name": { "kind": "Name", "value": "variant" } }] } }] };
2
+ export {
3
+ BlockSettingsFragmentDoc
4
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ const radash = require("radash");
3
+ const graphql = require("../generated/graphql.js");
4
+ const fragmentMasking = require("../generated/fragment-masking.js");
5
+ const getBlockProps = require("../utils/get-block-props.js");
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");
10
+ const propsWithFallback = await getBlockProps({
11
+ item,
12
+ blockKey,
13
+ document,
14
+ variables
15
+ });
16
+ const { tokens } = fragmentMasking.useFragment(graphql.BlockSettingsFragmentDoc, propsWithFallback == null ? void 0 : propsWithFallback.settings) ?? {};
17
+ return { ...propsWithFallback, cmsTokens: tokens };
18
+ }
19
+ module.exports = useBlock;
@@ -0,0 +1,20 @@
1
+ import { get } from "radash";
2
+ import { BlockSettingsFragmentDoc } from "../generated/graphql.mjs";
3
+ import { useFragment } from "../generated/fragment-masking.mjs";
4
+ import getBlockProps from "../utils/get-block-props.mjs";
5
+ async function useBlock(props, blockKey, doc) {
6
+ const item = get(props, "item");
7
+ const document = doc ?? get(props, "document");
8
+ const variables = get(props, "variables");
9
+ const propsWithFallback = await getBlockProps({
10
+ item,
11
+ blockKey,
12
+ document,
13
+ variables
14
+ });
15
+ const { tokens } = useFragment(BlockSettingsFragmentDoc, propsWithFallback == null ? void 0 : propsWithFallback.settings) ?? {};
16
+ return { ...propsWithFallback, cmsTokens: tokens };
17
+ }
18
+ export {
19
+ useBlock as default
20
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("./blocks/BlockWysiwyg/index.js");
4
+ const useBlock = require("./hooks/useBlock.js");
5
+ const config = require("./blocks/BlockWysiwyg/config.js");
6
+ const config$1 = require("./components/BlockDispatcher/config.js");
7
+ exports.BlockWysiwyg = index;
8
+ exports.useBlock = useBlock;
9
+ exports.blockWysiwygConfig = config;
10
+ exports.baseConfig = config$1;
@@ -0,0 +1,10 @@
1
+ import { default as default2 } from "./blocks/BlockWysiwyg/index.mjs";
2
+ import { default as default3 } from "./hooks/useBlock.mjs";
3
+ import { default as default4 } from "./blocks/BlockWysiwyg/config.mjs";
4
+ import { default as default5 } from "./components/BlockDispatcher/config.mjs";
5
+ export {
6
+ default2 as BlockWysiwyg,
7
+ default5 as baseConfig,
8
+ default4 as blockWysiwygConfig,
9
+ default3 as useBlock
10
+ };
@@ -0,0 +1,11 @@
1
+ "server-only";
2
+ "use strict";
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const index = require("./components/BlockDispatcher/index.js");
5
+ const index$1 = require("./components/BlockSerializer/index.js");
6
+ const getBlockProps = require("./utils/get-block-props.js");
7
+ const mergeConfigs = require("./utils/merge-configs.js");
8
+ exports.BlockDispatcher = index;
9
+ exports.BlockSerializer = index$1;
10
+ exports.getBlockProps = getBlockProps;
11
+ exports.mergeConfigs = mergeConfigs;
@@ -0,0 +1,11 @@
1
+ "server-only";
2
+ import { default as default2 } from "./components/BlockDispatcher/index.mjs";
3
+ import { default as default3 } from "./components/BlockSerializer/index.mjs";
4
+ import { default as default4 } from "./utils/get-block-props.mjs";
5
+ import { default as default5 } from "./utils/merge-configs.mjs";
6
+ export {
7
+ default2 as BlockDispatcher,
8
+ default3 as BlockSerializer,
9
+ default4 as getBlockProps,
10
+ default5 as mergeConfigs
11
+ };
@@ -0,0 +1,42 @@
1
+ "server-only";
2
+ "use strict";
3
+ require("@tanstack/react-query");
4
+ const query = require("../../../directus-query/src/lib/query.js");
5
+ require("../../../directus-query/src/lib/request.js");
6
+ require("graphql-request");
7
+ require("../../../directus-query/src/lib/config.js");
8
+ const radash = require("radash");
9
+ function isVariables(maybeVariables) {
10
+ return !!maybeVariables;
11
+ }
12
+ function isOnlyIdInItem(item) {
13
+ return !radash.isEmpty(item) && Object.keys(item).length === 1 && Object.keys(item)[0] === "id" && !!item.id;
14
+ }
15
+ async function queryFromVariables(params) {
16
+ const { document, blockKey, variables } = params;
17
+ if (!document || !isVariables(variables)) return null;
18
+ const queriedBlockProps = await query.queryGql(document, variables);
19
+ if (!queriedBlockProps || typeof queriedBlockProps !== "object" || !blockKey) return null;
20
+ const queriedBlockFragment = queriedBlockProps[blockKey];
21
+ return queriedBlockFragment;
22
+ }
23
+ async function getBlockProps(params) {
24
+ const { document, item, blockKey, variables } = params;
25
+ if (item) {
26
+ if (!isOnlyIdInItem(item)) {
27
+ return item;
28
+ }
29
+ const variablesWithFallback = { id: item.id, ...variables };
30
+ if (!isVariables(variablesWithFallback)) return null;
31
+ return queryFromVariables({
32
+ ...params,
33
+ variables: variablesWithFallback
34
+ });
35
+ }
36
+ if (!document || !isVariables(variables)) return null;
37
+ const queriedBlockProps = await query.queryGql(document, variables);
38
+ if (!queriedBlockProps || typeof queriedBlockProps !== "object" || !blockKey) return null;
39
+ const queriedBlockFragment = queriedBlockProps[blockKey];
40
+ return queriedBlockFragment;
41
+ }
42
+ module.exports = getBlockProps;
@@ -0,0 +1,43 @@
1
+ "server-only";
2
+ import "@tanstack/react-query";
3
+ import { queryGql } from "../../../directus-query/src/lib/query.mjs";
4
+ import "../../../directus-query/src/lib/request.mjs";
5
+ import "graphql-request";
6
+ import "../../../directus-query/src/lib/config.mjs";
7
+ import { isEmpty } from "radash";
8
+ function isVariables(maybeVariables) {
9
+ return !!maybeVariables;
10
+ }
11
+ function isOnlyIdInItem(item) {
12
+ return !isEmpty(item) && Object.keys(item).length === 1 && Object.keys(item)[0] === "id" && !!item.id;
13
+ }
14
+ async function queryFromVariables(params) {
15
+ const { document, blockKey, variables } = params;
16
+ if (!document || !isVariables(variables)) return null;
17
+ const queriedBlockProps = await queryGql(document, variables);
18
+ if (!queriedBlockProps || typeof queriedBlockProps !== "object" || !blockKey) return null;
19
+ const queriedBlockFragment = queriedBlockProps[blockKey];
20
+ return queriedBlockFragment;
21
+ }
22
+ async function getBlockProps(params) {
23
+ const { document, item, blockKey, variables } = params;
24
+ if (item) {
25
+ if (!isOnlyIdInItem(item)) {
26
+ return item;
27
+ }
28
+ const variablesWithFallback = { id: item.id, ...variables };
29
+ if (!isVariables(variablesWithFallback)) return null;
30
+ return queryFromVariables({
31
+ ...params,
32
+ variables: variablesWithFallback
33
+ });
34
+ }
35
+ if (!document || !isVariables(variables)) return null;
36
+ const queriedBlockProps = await queryGql(document, variables);
37
+ if (!queriedBlockProps || typeof queriedBlockProps !== "object" || !blockKey) return null;
38
+ const queriedBlockFragment = queriedBlockProps[blockKey];
39
+ return queriedBlockFragment;
40
+ }
41
+ export {
42
+ getBlockProps as default
43
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ function mergeConfigs(baseConfig, ...configs) {
3
+ const finalConfig = configs.reduce((mergedConfig, config) => {
4
+ if (!config) return mergedConfig;
5
+ return { components: { ...mergedConfig.components, ...config.components } };
6
+ }, baseConfig);
7
+ return finalConfig;
8
+ }
9
+ module.exports = mergeConfigs;
@@ -0,0 +1,10 @@
1
+ function mergeConfigs(baseConfig, ...configs) {
2
+ const finalConfig = configs.reduce((mergedConfig, config) => {
3
+ if (!config) return mergedConfig;
4
+ return { components: { ...mergedConfig.components, ...config.components } };
5
+ }, baseConfig);
6
+ return finalConfig;
7
+ }
8
+ export {
9
+ mergeConfigs as default
10
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ process.env.NEXT_PUBLIC_GRAPHQL_URL;
3
+ process.env.NEXT_PUBLIC_API_TOKEN;
@@ -0,0 +1,2 @@
1
+ process.env.NEXT_PUBLIC_GRAPHQL_URL;
2
+ process.env.NEXT_PUBLIC_API_TOKEN;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("radash");
4
+ const request = require("./request.js");
5
+ function queryGql(document, queryKey, client = request.graphqlRequestClient) {
6
+ return client.request(document, {
7
+ ...queryKey
8
+ });
9
+ }
10
+ exports.queryGql = queryGql;
@@ -0,0 +1,10 @@
1
+ import "radash";
2
+ import { graphqlRequestClient } from "./request.mjs";
3
+ function queryGql(document, queryKey, client = graphqlRequestClient) {
4
+ return client.request(document, {
5
+ ...queryKey
6
+ });
7
+ }
8
+ export {
9
+ queryGql
10
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const reactQuery = require("@tanstack/react-query");
4
+ const graphqlRequest = require("graphql-request");
5
+ const GRAPHQL_ENDPOINT = process.env.NEXT_PUBLIC_GRAPHQL_URL;
6
+ const GRAPHQL_ENDPOINT_ADMIN = process.env.NEXT_GRAPHQL_URL_ADMIN;
7
+ const AUTH_TOKEN = process.env.NEXT_PUBLIC_API_TOKEN ?? "";
8
+ const AUTH_TOKEN_ADMIN = process.env.NEXT_PUBLIC_API_TOKEN;
9
+ const graphqlRequestClient = new graphqlRequest.GraphQLClient(GRAPHQL_ENDPOINT, {
10
+ credentials: "include",
11
+ mode: "cors",
12
+ fetch,
13
+ headers: {
14
+ Authorization: `Bearer ${AUTH_TOKEN}`
15
+ }
16
+ });
17
+ new graphqlRequest.GraphQLClient(GRAPHQL_ENDPOINT_ADMIN, {
18
+ credentials: "include",
19
+ mode: "cors",
20
+ fetch,
21
+ headers: {
22
+ Authorization: `Bearer ${AUTH_TOKEN_ADMIN}`
23
+ }
24
+ });
25
+ new reactQuery.QueryClient({
26
+ queryCache: new reactQuery.QueryCache({
27
+ onError: (error) => {
28
+ console.error(error);
29
+ }
30
+ }),
31
+ defaultOptions: {
32
+ queries: {
33
+ staleTime: 5 * 1e3
34
+ }
35
+ }
36
+ });
37
+ exports.default = graphqlRequestClient;
38
+ exports.graphqlRequestClient = graphqlRequestClient;
@@ -0,0 +1,38 @@
1
+ import { QueryClient, QueryCache } from "@tanstack/react-query";
2
+ import { GraphQLClient } from "graphql-request";
3
+ const GRAPHQL_ENDPOINT = process.env.NEXT_PUBLIC_GRAPHQL_URL;
4
+ const GRAPHQL_ENDPOINT_ADMIN = process.env.NEXT_GRAPHQL_URL_ADMIN;
5
+ const AUTH_TOKEN = process.env.NEXT_PUBLIC_API_TOKEN ?? "";
6
+ const AUTH_TOKEN_ADMIN = process.env.NEXT_PUBLIC_API_TOKEN;
7
+ const graphqlRequestClient = new GraphQLClient(GRAPHQL_ENDPOINT, {
8
+ credentials: "include",
9
+ mode: "cors",
10
+ fetch,
11
+ headers: {
12
+ Authorization: `Bearer ${AUTH_TOKEN}`
13
+ }
14
+ });
15
+ new GraphQLClient(GRAPHQL_ENDPOINT_ADMIN, {
16
+ credentials: "include",
17
+ mode: "cors",
18
+ fetch,
19
+ headers: {
20
+ Authorization: `Bearer ${AUTH_TOKEN_ADMIN}`
21
+ }
22
+ });
23
+ new QueryClient({
24
+ queryCache: new QueryCache({
25
+ onError: (error) => {
26
+ console.error(error);
27
+ }
28
+ }),
29
+ defaultOptions: {
30
+ queries: {
31
+ staleTime: 5 * 1e3
32
+ }
33
+ }
34
+ });
35
+ export {
36
+ graphqlRequestClient as default,
37
+ graphqlRequestClient
38
+ };
@@ -0,0 +1,8 @@
1
+ import type { TToken } from '@okam/stack-ui';
2
+ import type { TypedQueryDocumentNode } from 'graphql';
3
+ import type { TBlockSerializerProps } from '../components/BlockSerializer/interface';
4
+ import type { TBlockQuery, TBlockVariables, TCommonBlockFragment } from '../types/block';
5
+ declare function useBlock<T extends TCommonBlockFragment>(props: TBlockSerializerProps<T>, blockKey: string, doc?: TypedQueryDocumentNode<TBlockQuery<T>, TBlockVariables>): Promise<T & {
6
+ cmsTokens: TToken;
7
+ }>;
8
+ export default useBlock;
package/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
+ export type { BlockSettingsFragment } from './generated/graphql';
1
2
  export type { TBlockDispatcherProps } from './components/BlockDispatcher/interface';
2
3
  export type { TBlockSerializerConfig, TBlockSerializerProps, TBlock, TBlockSerializerConfigComponent, } from './components/BlockSerializer/interface';
3
4
  export type { TAdditionalProps, TCommonBlockFragment, TBlockQuery, TBlockDocument, TBlockVariables, } from './types/block';
4
5
  export { default as BlockWysiwyg } from './blocks/BlockWysiwyg';
6
+ export { default as useBlock } from './hooks/useBlock';
5
7
  export { default as blockWysiwygConfig } from './blocks/BlockWysiwyg/config';
6
8
  export { default as baseConfig } from './components/BlockDispatcher/config';
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@okam/directus-block",
3
+ "version": "1.3.0",
3
4
  "main": "./index.js",
4
- "version": "1.2.2",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./index.mjs",
9
9
  "require": "./index.js"
10
+ },
11
+ "./server": {
12
+ "import": "./server.mjs",
13
+ "require": "./server.js"
10
14
  }
11
15
  },
12
16
  "publishConfig": {
package/server.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as BlockDispatcher } from './components/BlockDispatcher';
2
+ export { default as BlockSerializer } from './components/BlockSerializer';
3
+ export { default as getBlockProps } from './utils/get-block-props';
4
+ export { default as mergeConfigs } from './utils/merge-configs';