react-datocms 7.2.1 → 7.2.3
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/dist/cjs/StructuredText/index.js +5 -5
- package/dist/cjs/StructuredText/index.js.map +1 -1
- package/dist/esm/StructuredText/index.js +11 -6
- package/dist/esm/StructuredText/index.js.map +1 -1
- package/dist/types/StructuredText/index.d.ts +19 -10
- package/package.json +3 -3
- package/src/StructuredText/__tests__/__snapshots__/index.test.tsx.snap +2 -0
- package/src/StructuredText/__tests__/index.test.tsx +5 -2
- package/src/StructuredText/index.tsx +52 -20
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.renderRule = exports.StructuredText = exports.appendKeyToValidElement = exports.defaultAdapter = exports.RenderError = exports.renderMarkRule = exports.renderNodeRule = void 0;
|
|
27
27
|
const datocms_structured_text_generic_html_renderer_1 = require("datocms-structured-text-generic-html-renderer");
|
|
28
28
|
Object.defineProperty(exports, "renderMarkRule", { enumerable: true, get: function () { return datocms_structured_text_generic_html_renderer_1.renderMarkRule; } });
|
|
29
29
|
Object.defineProperty(exports, "renderNodeRule", { enumerable: true, get: function () { return datocms_structured_text_generic_html_renderer_1.renderNodeRule; } });
|
|
@@ -105,12 +105,12 @@ function StructuredText({ data, renderInlineRecord, renderLinkToRecord, renderBl
|
|
|
105
105
|
if (!renderInlineBlock) {
|
|
106
106
|
throw new datocms_structured_text_utils_1.RenderError(`The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`, node);
|
|
107
107
|
}
|
|
108
|
-
if (!((0, datocms_structured_text_utils_1.isStructuredText)(data) && data.
|
|
109
|
-
throw new datocms_structured_text_utils_1.RenderError(`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.
|
|
108
|
+
if (!((0, datocms_structured_text_utils_1.isStructuredText)(data) && data.inlineBlocks)) {
|
|
109
|
+
throw new datocms_structured_text_utils_1.RenderError(`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.inlineBlocks is not present!`, node);
|
|
110
110
|
}
|
|
111
|
-
const item = data.
|
|
111
|
+
const item = data.inlineBlocks.find((item) => item.id === node.item);
|
|
112
112
|
if (!item) {
|
|
113
|
-
throw new datocms_structured_text_utils_1.RenderError(`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.
|
|
113
|
+
throw new datocms_structured_text_utils_1.RenderError(`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.inlineBlocks!`, node);
|
|
114
114
|
}
|
|
115
115
|
return appendKeyToValidElement(renderInlineBlock({ record: item }), key);
|
|
116
116
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAQuD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAQuD;AAqB9B,+FAvBvB,8DAAc,OAuBuB;AAA9B,+FAtBP,8DAAc,OAsBO;AAkRI,2FAxSzB,8DAAc,OAwSqB;AAtSrC,iFAiBuC;AAGE,4FAlBvC,2CAAW,OAkBuC;AAFpD,+CAA+E;AAalE,QAAA,cAAc,GAAG;IAC5B,UAAU,EAAE,eAAK,CAAC,aAAgD;IAClE,cAAc,EAAE,CACd,QAA+B,EAC/B,GAAW,EACI,EAAE,CAAC,8BAAC,eAAK,CAAC,QAAQ,IAAC,GAAG,EAAE,GAAG,IAAG,QAAQ,CAAkB;IACzE,UAAU,EAAE,CAAC,IAAY,EAAE,GAAW,EAAiB,EAAE,CAAC,IAAI;C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ED,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;gBAErE,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,IAAI,2CAAW,CACnB,iGAAiG,IAAI,CAAC,IAAI,4BAA4B,EACtI,IAAI,CACL,CAAC;gBACJ,CAAC;gBAED,OAAO,uBAAuB,CAC5B,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EACnC,GAAG,CACJ,CAAC;YACJ,CAAC,CAAC;YACF,GAAG,CAAC,eAAe,IAAI,WAAW,IAAI,EAAE,CAAC;SAC1C;KACF,CAAC,CAAC;IAEH,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,8DAAG,MAAM,CAAI,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC;AArKD,wCAqKC"}
|
|
@@ -2,8 +2,6 @@ import { defaultMetaTransformer, render, renderMarkRule, renderNodeRule, } from
|
|
|
2
2
|
import { RenderError, isBlock, isInlineBlock, isInlineItem, isItemLink, isStructuredText, } from 'datocms-structured-text-utils';
|
|
3
3
|
import React, { cloneElement, isValidElement } from 'react';
|
|
4
4
|
export { renderNodeRule, renderMarkRule, RenderError };
|
|
5
|
-
// deprecated
|
|
6
|
-
export { renderNodeRule as renderRule };
|
|
7
5
|
export const defaultAdapter = {
|
|
8
6
|
renderNode: React.createElement,
|
|
9
7
|
renderFragment: (children, key) => React.createElement(React.Fragment, { key: key }, children),
|
|
@@ -77,12 +75,12 @@ export function StructuredText({ data, renderInlineRecord, renderLinkToRecord, r
|
|
|
77
75
|
if (!renderInlineBlock) {
|
|
78
76
|
throw new RenderError(`The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`, node);
|
|
79
77
|
}
|
|
80
|
-
if (!(isStructuredText(data) && data.
|
|
81
|
-
throw new RenderError(`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.
|
|
78
|
+
if (!(isStructuredText(data) && data.inlineBlocks)) {
|
|
79
|
+
throw new RenderError(`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.inlineBlocks is not present!`, node);
|
|
82
80
|
}
|
|
83
|
-
const item = data.
|
|
81
|
+
const item = data.inlineBlocks.find((item) => item.id === node.item);
|
|
84
82
|
if (!item) {
|
|
85
|
-
throw new RenderError(`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.
|
|
83
|
+
throw new RenderError(`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.inlineBlocks!`, node);
|
|
86
84
|
}
|
|
87
85
|
return appendKeyToValidElement(renderInlineBlock({ record: item }), key);
|
|
88
86
|
}),
|
|
@@ -94,4 +92,11 @@ export function StructuredText({ data, renderInlineRecord, renderLinkToRecord, r
|
|
|
94
92
|
}
|
|
95
93
|
return result || null;
|
|
96
94
|
}
|
|
95
|
+
// ============================================================================
|
|
96
|
+
// DEPRECATED EXPORTS - kept for backward compatibility
|
|
97
|
+
// ============================================================================
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated Use renderNodeRule instead
|
|
100
|
+
*/
|
|
101
|
+
export { renderNodeRule as renderRule };
|
|
97
102
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,sBAAsB,EACtB,MAAM,EACN,cAAc,EACd,cAAc,GACf,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAEL,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,sBAAsB,EACtB,MAAM,EACN,cAAc,EACd,c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ule, type TransformMetaFn, type TransformedMeta, renderMarkRule, renderNodeRule } from 'datocms-structured-text-generic-html-renderer';
|
|
2
|
-
import { type Node, RenderError, type RenderResult, type RenderRule, type Document as StructuredTextDocument, type StructuredText as StructuredTextGraphQlResponse, type Record as StructuredTextGraphQlResponseRecord, type TypesafeStructuredText as TypesafeStructuredTextGraphQlResponse } from 'datocms-structured-text-utils';
|
|
2
|
+
import { type Node, RenderError, type RenderResult, type RenderRule, type Document as StructuredTextDocument, type CdaStructuredTextValue, type CdaStructuredTextRecord, type TypesafeCdaStructuredTextValue, type StructuredText as StructuredTextGraphQlResponse, type Record as StructuredTextGraphQlResponseRecord, type TypesafeStructuredText as TypesafeStructuredTextGraphQlResponse } from 'datocms-structured-text-utils';
|
|
3
3
|
import { type ReactElement } from 'react';
|
|
4
4
|
export { renderNodeRule, renderMarkRule, RenderError };
|
|
5
|
-
export {
|
|
6
|
-
export type { StructuredTextGraphQlResponse, TypesafeStructuredTextGraphQlResponse, StructuredTextDocument, StructuredTextGraphQlResponseRecord, };
|
|
5
|
+
export type { StructuredTextDocument, CdaStructuredTextValue, TypesafeCdaStructuredTextValue, CdaStructuredTextRecord, };
|
|
7
6
|
type AdapterReturn = ReactElement | string | null;
|
|
8
7
|
export declare const defaultAdapter: {
|
|
9
8
|
renderNode: (...args: any) => AdapterReturn;
|
|
@@ -25,21 +24,21 @@ export type RenderRecordLinkContext<R extends StructuredTextGraphQlResponseRecor
|
|
|
25
24
|
export type RenderBlockContext<R extends StructuredTextGraphQlResponseRecord> = {
|
|
26
25
|
record: R;
|
|
27
26
|
};
|
|
28
|
-
export type StructuredTextPropTypes<
|
|
27
|
+
export type StructuredTextPropTypes<BlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, LinkRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, InlineBlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord> = {
|
|
29
28
|
/** The actual field value you get from DatoCMS **/
|
|
30
|
-
data: StructuredTextGraphQlResponse<
|
|
29
|
+
data: StructuredTextGraphQlResponse<BlockRecord, LinkRecord, InlineBlockRecord> | StructuredTextDocument | Node | null | undefined;
|
|
31
30
|
/** A set of additional rules to convert nodes to JSX **/
|
|
32
31
|
customNodeRules?: RenderRule<H, T, F>[];
|
|
33
32
|
/** A set of additional rules to convert marks to JSX **/
|
|
34
33
|
customMarkRules?: RenderMarkRule<H, T, F>[];
|
|
35
34
|
/** Fuction that converts an 'inlineItem' node into React **/
|
|
36
|
-
renderInlineRecord?: (context: RenderInlineRecordContext<
|
|
35
|
+
renderInlineRecord?: (context: RenderInlineRecordContext<LinkRecord>) => ReactElement | null;
|
|
37
36
|
/** Fuction that converts an 'itemLink' node into React **/
|
|
38
|
-
renderLinkToRecord?: (context: RenderRecordLinkContext<
|
|
37
|
+
renderLinkToRecord?: (context: RenderRecordLinkContext<LinkRecord>) => ReactElement | null;
|
|
39
38
|
/** Fuction that converts a 'block' node into React **/
|
|
40
|
-
renderBlock?: (context: RenderBlockContext<
|
|
39
|
+
renderBlock?: (context: RenderBlockContext<BlockRecord>) => ReactElement | null;
|
|
41
40
|
/** Fuction that converts an 'inlineBlock' node into React **/
|
|
42
|
-
renderInlineBlock?: (context: RenderBlockContext<
|
|
41
|
+
renderInlineBlock?: (context: RenderBlockContext<InlineBlockRecord>) => ReactElement | null;
|
|
43
42
|
/** Function that converts 'link' and 'itemLink' `meta` into HTML props */
|
|
44
43
|
metaTransformer?: TransformMetaFn;
|
|
45
44
|
/** Fuction that converts a simple string text into React **/
|
|
@@ -51,4 +50,14 @@ export type StructuredTextPropTypes<R1 extends StructuredTextGraphQlResponseReco
|
|
|
51
50
|
/** @deprecated use customNodeRules **/
|
|
52
51
|
customRules?: RenderRule<H, T, F>[];
|
|
53
52
|
};
|
|
54
|
-
export declare function StructuredText<
|
|
53
|
+
export declare function StructuredText<BlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, LinkRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, InlineBlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord>({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderInlineBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }: StructuredTextPropTypes<BlockRecord, LinkRecord, InlineBlockRecord>): ReactElement | null;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use renderNodeRule instead
|
|
56
|
+
*/
|
|
57
|
+
export { renderNodeRule as renderRule };
|
|
58
|
+
/** @deprecated Use CdaStructuredTextValue */
|
|
59
|
+
export type { StructuredTextGraphQlResponse };
|
|
60
|
+
/** @deprecated Use TypesafeCdaStructuredTextValue */
|
|
61
|
+
export type { TypesafeStructuredTextGraphQlResponse };
|
|
62
|
+
/** @deprecated Use CdaStructuredTextRecord */
|
|
63
|
+
export type { StructuredTextGraphQlResponseRecord };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-datocms",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=8.0.0"
|
|
6
6
|
},
|
|
@@ -135,8 +135,8 @@
|
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@mux/mux-player-react": "*",
|
|
137
137
|
"datocms-listen": "^0.1.9",
|
|
138
|
-
"datocms-structured-text-generic-html-renderer": "^
|
|
139
|
-
"datocms-structured-text-utils": "^
|
|
138
|
+
"datocms-structured-text-generic-html-renderer": "^5.0.0",
|
|
139
|
+
"datocms-structured-text-utils": "^5.1.6",
|
|
140
140
|
"react-intersection-observer": "^9.4.3",
|
|
141
141
|
"react-string-replace": "^1.1.0",
|
|
142
142
|
"use-deep-compare-effect": "^1.6.1"
|
|
@@ -150,8 +150,9 @@ describe('StructuredText', () => {
|
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
const structuredText: StructuredTextGraphQlResponse<
|
|
153
|
-
QuoteRecord
|
|
154
|
-
DocPageRecord
|
|
153
|
+
QuoteRecord,
|
|
154
|
+
DocPageRecord,
|
|
155
|
+
MentionRecord
|
|
155
156
|
> = {
|
|
156
157
|
value: {
|
|
157
158
|
schema: 'dast',
|
|
@@ -201,6 +202,8 @@ describe('StructuredText', () => {
|
|
|
201
202
|
quote: 'Foo bar.',
|
|
202
203
|
author: 'Mark Smith',
|
|
203
204
|
},
|
|
205
|
+
],
|
|
206
|
+
inlineBlocks: [
|
|
204
207
|
{
|
|
205
208
|
id: '789',
|
|
206
209
|
__typename: 'MentionRecord',
|
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
type RenderResult,
|
|
14
14
|
type RenderRule,
|
|
15
15
|
type Document as StructuredTextDocument,
|
|
16
|
+
type CdaStructuredTextValue,
|
|
17
|
+
type CdaStructuredTextRecord,
|
|
18
|
+
type TypesafeCdaStructuredTextValue,
|
|
16
19
|
type StructuredText as StructuredTextGraphQlResponse,
|
|
17
20
|
type Record as StructuredTextGraphQlResponseRecord,
|
|
18
21
|
type TypesafeStructuredText as TypesafeStructuredTextGraphQlResponse,
|
|
@@ -26,14 +29,11 @@ import React, { type ReactElement, cloneElement, isValidElement } from 'react';
|
|
|
26
29
|
|
|
27
30
|
export { renderNodeRule, renderMarkRule, RenderError };
|
|
28
31
|
|
|
29
|
-
// deprecated
|
|
30
|
-
export { renderNodeRule as renderRule };
|
|
31
|
-
|
|
32
32
|
export type {
|
|
33
|
-
StructuredTextGraphQlResponse,
|
|
34
|
-
TypesafeStructuredTextGraphQlResponse,
|
|
35
33
|
StructuredTextDocument,
|
|
36
|
-
|
|
34
|
+
CdaStructuredTextValue,
|
|
35
|
+
TypesafeCdaStructuredTextValue,
|
|
36
|
+
CdaStructuredTextRecord,
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
type AdapterReturn = ReactElement | string | null;
|
|
@@ -81,12 +81,16 @@ export type RenderBlockContext<R extends StructuredTextGraphQlResponseRecord> =
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
export type StructuredTextPropTypes<
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
BlockRecord extends
|
|
85
|
+
StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord,
|
|
86
|
+
LinkRecord extends
|
|
87
|
+
StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord,
|
|
88
|
+
InlineBlockRecord extends
|
|
89
|
+
StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord,
|
|
86
90
|
> = {
|
|
87
91
|
/** The actual field value you get from DatoCMS **/
|
|
88
92
|
data:
|
|
89
|
-
| StructuredTextGraphQlResponse<
|
|
93
|
+
| StructuredTextGraphQlResponse<BlockRecord, LinkRecord, InlineBlockRecord>
|
|
90
94
|
| StructuredTextDocument
|
|
91
95
|
| Node
|
|
92
96
|
| null
|
|
@@ -97,16 +101,20 @@ export type StructuredTextPropTypes<
|
|
|
97
101
|
customMarkRules?: RenderMarkRule<H, T, F>[];
|
|
98
102
|
/** Fuction that converts an 'inlineItem' node into React **/
|
|
99
103
|
renderInlineRecord?: (
|
|
100
|
-
context: RenderInlineRecordContext<
|
|
104
|
+
context: RenderInlineRecordContext<LinkRecord>,
|
|
101
105
|
) => ReactElement | null;
|
|
102
106
|
/** Fuction that converts an 'itemLink' node into React **/
|
|
103
107
|
renderLinkToRecord?: (
|
|
104
|
-
context: RenderRecordLinkContext<
|
|
108
|
+
context: RenderRecordLinkContext<LinkRecord>,
|
|
105
109
|
) => ReactElement | null;
|
|
106
110
|
/** Fuction that converts a 'block' node into React **/
|
|
107
|
-
renderBlock?: (
|
|
111
|
+
renderBlock?: (
|
|
112
|
+
context: RenderBlockContext<BlockRecord>,
|
|
113
|
+
) => ReactElement | null;
|
|
108
114
|
/** Fuction that converts an 'inlineBlock' node into React **/
|
|
109
|
-
renderInlineBlock?: (
|
|
115
|
+
renderInlineBlock?: (
|
|
116
|
+
context: RenderBlockContext<InlineBlockRecord>,
|
|
117
|
+
) => ReactElement | null;
|
|
110
118
|
/** Function that converts 'link' and 'itemLink' `meta` into HTML props */
|
|
111
119
|
metaTransformer?: TransformMetaFn;
|
|
112
120
|
/** Fuction that converts a simple string text into React **/
|
|
@@ -120,8 +128,12 @@ export type StructuredTextPropTypes<
|
|
|
120
128
|
};
|
|
121
129
|
|
|
122
130
|
export function StructuredText<
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
BlockRecord extends
|
|
132
|
+
StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord,
|
|
133
|
+
LinkRecord extends
|
|
134
|
+
StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord,
|
|
135
|
+
InlineBlockRecord extends
|
|
136
|
+
StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord,
|
|
125
137
|
>({
|
|
126
138
|
data,
|
|
127
139
|
renderInlineRecord,
|
|
@@ -135,7 +147,11 @@ export function StructuredText<
|
|
|
135
147
|
customRules,
|
|
136
148
|
customNodeRules,
|
|
137
149
|
metaTransformer,
|
|
138
|
-
}: StructuredTextPropTypes<
|
|
150
|
+
}: StructuredTextPropTypes<
|
|
151
|
+
BlockRecord,
|
|
152
|
+
LinkRecord,
|
|
153
|
+
InlineBlockRecord
|
|
154
|
+
>): ReactElement | null {
|
|
139
155
|
const result = render(data, {
|
|
140
156
|
adapter: {
|
|
141
157
|
renderText: renderText || defaultAdapter.renderText,
|
|
@@ -246,18 +262,18 @@ export function StructuredText<
|
|
|
246
262
|
);
|
|
247
263
|
}
|
|
248
264
|
|
|
249
|
-
if (!(isStructuredText(data) && data.
|
|
265
|
+
if (!(isStructuredText(data) && data.inlineBlocks)) {
|
|
250
266
|
throw new RenderError(
|
|
251
|
-
`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.
|
|
267
|
+
`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.inlineBlocks is not present!`,
|
|
252
268
|
node,
|
|
253
269
|
);
|
|
254
270
|
}
|
|
255
271
|
|
|
256
|
-
const item = data.
|
|
272
|
+
const item = data.inlineBlocks.find((item) => item.id === node.item);
|
|
257
273
|
|
|
258
274
|
if (!item) {
|
|
259
275
|
throw new RenderError(
|
|
260
|
-
`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.
|
|
276
|
+
`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.inlineBlocks!`,
|
|
261
277
|
node,
|
|
262
278
|
);
|
|
263
279
|
}
|
|
@@ -277,3 +293,19 @@ export function StructuredText<
|
|
|
277
293
|
|
|
278
294
|
return result || null;
|
|
279
295
|
}
|
|
296
|
+
|
|
297
|
+
// ============================================================================
|
|
298
|
+
// DEPRECATED EXPORTS - kept for backward compatibility
|
|
299
|
+
// ============================================================================
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @deprecated Use renderNodeRule instead
|
|
303
|
+
*/
|
|
304
|
+
export { renderNodeRule as renderRule };
|
|
305
|
+
|
|
306
|
+
/** @deprecated Use CdaStructuredTextValue */
|
|
307
|
+
export type { StructuredTextGraphQlResponse };
|
|
308
|
+
/** @deprecated Use TypesafeCdaStructuredTextValue */
|
|
309
|
+
export type { TypesafeStructuredTextGraphQlResponse };
|
|
310
|
+
/** @deprecated Use CdaStructuredTextRecord */
|
|
311
|
+
export type { StructuredTextGraphQlResponseRecord };
|