@datocms/astro 0.6.1 → 0.6.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/package.json
CHANGED
|
@@ -45,6 +45,7 @@ interface Props {
|
|
|
45
45
|
node: DastNode;
|
|
46
46
|
|
|
47
47
|
blocks?: DatocmsRecord[];
|
|
48
|
+
inlineBlocks?: DatocmsRecord[];
|
|
48
49
|
links?: DatocmsRecord[];
|
|
49
50
|
|
|
50
51
|
blockComponents?: BlockComponents<DatocmsRecord, DatocmsRecord>;
|
|
@@ -60,6 +61,7 @@ const { node, ...rest } = Astro.props;
|
|
|
60
61
|
|
|
61
62
|
const {
|
|
62
63
|
blocks,
|
|
64
|
+
inlineBlocks,
|
|
63
65
|
links,
|
|
64
66
|
blockComponents,
|
|
65
67
|
inlineBlockComponents,
|
|
@@ -69,7 +71,7 @@ const {
|
|
|
69
71
|
markOverrides,
|
|
70
72
|
} = rest;
|
|
71
73
|
|
|
72
|
-
function findRecordInBlocks(node: Block
|
|
74
|
+
function findRecordInBlocks(node: Block) {
|
|
73
75
|
const record = (blocks || []).find(({ id }) => id === node.item);
|
|
74
76
|
|
|
75
77
|
if (!record) {
|
|
@@ -82,6 +84,19 @@ function findRecordInBlocks(node: Block | InlineBlock) {
|
|
|
82
84
|
return record;
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
function findRecordInInlineBlocks(node: InlineBlock) {
|
|
88
|
+
const record = (inlineBlocks || []).find(({ id }) => id === node.item);
|
|
89
|
+
|
|
90
|
+
if (!record) {
|
|
91
|
+
throw new RenderError(
|
|
92
|
+
`The Structured Text document contains a '${node.type}' node, but cannot find a record with ID ${node.item} inside data.inlineBlocks!`,
|
|
93
|
+
node,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return record;
|
|
98
|
+
}
|
|
99
|
+
|
|
85
100
|
function findRecordInLinks(node: ItemLink | InlineItem) {
|
|
86
101
|
const record = (links || []).find(({ id }) => id === node.item);
|
|
87
102
|
|
|
@@ -125,7 +140,7 @@ const Component = otherNodeComponents[node.type] as AstroComponent;
|
|
|
125
140
|
isBlock(node) ? (
|
|
126
141
|
<Component {node} block={findRecordInBlocks(node)} {blockComponents} />
|
|
127
142
|
) : isInlineBlock(node) ? (
|
|
128
|
-
<Component {node} block={
|
|
143
|
+
<Component {node} block={findRecordInInlineBlocks(node)} {inlineBlockComponents} />
|
|
129
144
|
) : isInlineItem(node) ? (
|
|
130
145
|
<Component {node} record={findRecordInLinks(node)} {inlineRecordComponents} />
|
|
131
146
|
) : isItemLink(node) ? (
|
|
@@ -52,8 +52,8 @@ const node = !data
|
|
|
52
52
|
: undefined;
|
|
53
53
|
|
|
54
54
|
const blocks = isStructuredText(data) ? data?.blocks : undefined;
|
|
55
|
-
|
|
55
|
+
const inlineBlocks = isStructuredText(data) ? data?.inlineBlocks : undefined;
|
|
56
56
|
const links = isStructuredText(data) ? data?.links : undefined;
|
|
57
57
|
---
|
|
58
58
|
|
|
59
|
-
{node && <Node {node} {blocks} {links} {...rest} />}
|
|
59
|
+
{node && <Node {node} {blocks} {inlineBlocks} {links} {...rest} />}
|
|
@@ -14,7 +14,16 @@ import type {
|
|
|
14
14
|
type Props<B extends DatocmsRecord, L extends DatocmsRecord, I extends DatocmsRecord> =
|
|
15
15
|
| {
|
|
16
16
|
/** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
|
|
17
|
-
data:
|
|
17
|
+
data:
|
|
18
|
+
| (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
|
|
19
|
+
blocks?: never;
|
|
20
|
+
links?: never;
|
|
21
|
+
inlineBlocks?: never;
|
|
22
|
+
})
|
|
23
|
+
| Document
|
|
24
|
+
| DastNode
|
|
25
|
+
| null
|
|
26
|
+
| undefined;
|
|
18
27
|
blockComponents?: never;
|
|
19
28
|
inlineBlockComponents?: never;
|
|
20
29
|
linkToRecordComponents?: never;
|