@datocms/astro 0.5.2 → 0.6.1

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
@@ -2,7 +2,7 @@
2
2
  "name": "@datocms/astro",
3
3
  "description": "A set of components and utilities to work faster with DatoCMS in Astro projects.",
4
4
  "type": "module",
5
- "version": "0.5.2",
5
+ "version": "0.6.1",
6
6
  "sideEffects": false,
7
7
  "repository": {
8
8
  "type": "git",
@@ -45,8 +45,8 @@
45
45
  "dependencies": {
46
46
  "@0no-co/graphql.web": "^1.0.7",
47
47
  "datocms-listen": "^1.0.1",
48
- "datocms-structured-text-generic-html-renderer": "^4.1.2",
49
- "datocms-structured-text-utils": "^4.1.2"
48
+ "datocms-structured-text-generic-html-renderer": "^5.0.0",
49
+ "datocms-structured-text-utils": "^5.0.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "astro": "*"
@@ -94,6 +94,12 @@ const query = gql`
94
94
  label
95
95
  url
96
96
  }
97
+ }
98
+ inlineBlocks {
99
+ ... on RecordInterface {
100
+ id
101
+ __typename
102
+ }
97
103
  ... on NewsletterSignupRecord {
98
104
  title
99
105
  }
@@ -122,6 +128,8 @@ const { blogPost } = await executeQuery(query, { token: '<YOUR-API-TOKEN>' });
122
128
  data={blogPost.content}
123
129
  blockComponents={{
124
130
  CtaRecord: Cta,
131
+ }}
132
+ inlineBlockComponents={{
125
133
  NewsletterSignupRecord: NewsletterSignup,
126
134
  }}
127
135
  inlineRecordComponents={{
@@ -176,6 +184,8 @@ import { StructuredText, ensureValidStructuredTextProps } from '@datocms/astro/S
176
184
  data: blogPost.content,
177
185
  blockComponents: {
178
186
  CtaRecord: Cta,
187
+ },
188
+ inlineBlockComponents: {
179
189
  NewsletterSignupRecord: NewsletterSignup,
180
190
  },
181
191
  inlineRecordComponents: {
@@ -22,7 +22,7 @@ import type { NodeOverrides, MarkOverrides, AstroComponent } from './types';
22
22
 
23
23
  interface Props {
24
24
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
25
- data: StructuredText<DatocmsRecord, DatocmsRecord> | Document | DastNode | null | undefined;
25
+ data: StructuredText | Document | DastNode | null | undefined;
26
26
 
27
27
  /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
28
28
  blockComponents?: Record<string, AstroComponent>;
@@ -11,7 +11,7 @@ import type {
11
11
  LinkToRecordComponents,
12
12
  } from './types';
13
13
 
14
- type Props<R1 extends DatocmsRecord, R2 extends DatocmsRecord> =
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
17
  data: Document | DastNode | null | undefined;
@@ -23,57 +23,129 @@ type Props<R1 extends DatocmsRecord, R2 extends DatocmsRecord> =
23
23
  | {
24
24
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
25
25
  data:
26
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks: R1[]; links: R2[] })
26
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
27
+ blocks: B[];
28
+ links?: never;
29
+ inlineBlocks?: never;
30
+ })
27
31
  | null
28
32
  | undefined;
29
33
  /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
30
- blockComponents: BlockComponents<R1, R2>;
31
- /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
32
- inlineBlockComponents: BlockComponents<R1, R2>;
34
+ blockComponents: BlockComponents<B, L, I>;
35
+ inlineBlockComponents?: never;
36
+ linkToRecordComponents?: never;
37
+ inlineRecordComponents?: never;
38
+ }
39
+ | {
40
+ /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
41
+ data:
42
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
43
+ blocks?: never;
44
+ links: L[];
45
+ inlineBlocks?: never;
46
+ })
47
+ | null
48
+ | undefined;
49
+ blockComponents?: never;
50
+ inlineBlockComponents?: never;
33
51
  /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
34
- linkToRecordComponents: LinkToRecordComponents<R1, R2>;
52
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
35
53
  /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
36
- inlineRecordComponents: InlineRecordComponents<R1, R2>;
54
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
37
55
  }
38
56
  | {
39
57
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
40
58
  data:
41
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks: R1[]; links?: never })
59
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
60
+ blocks?: never;
61
+ links?: never;
62
+ inlineBlocks: I[];
63
+ })
42
64
  | null
43
65
  | undefined;
44
- /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
45
- blockComponents: BlockComponents<R1, R2>;
46
- inlineBlockComponents: InlineBlockComponents<R1, R2>;
66
+ blockComponents?: never;
67
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
68
+ inlineBlockComponents: InlineBlockComponents<B, L, I>;
47
69
  linkToRecordComponents?: never;
48
70
  inlineRecordComponents?: never;
49
71
  }
50
72
  | {
51
73
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
52
74
  data:
53
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks?: never; links: R2[] })
75
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
76
+ blocks?: never;
77
+ links: L[];
78
+ inlineBlocks: I[];
79
+ })
54
80
  | null
55
81
  | undefined;
56
82
  blockComponents?: never;
57
- inlineBlockComponents?: never;
83
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
84
+ inlineBlockComponents: InlineBlockComponents<B, L, I>;
58
85
  /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
59
- linkToRecordComponents: LinkToRecordComponents<R1, R2>;
86
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
60
87
  /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
61
- inlineRecordComponents: InlineRecordComponents<R1, R2>;
88
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
62
89
  }
63
90
  | {
64
91
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
65
92
  data:
66
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks?: never; links?: never })
93
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
94
+ blocks: B[];
95
+ links?: never;
96
+ inlineBlocks: I[];
97
+ })
67
98
  | null
68
99
  | undefined;
69
- blockComponents?: never;
70
- inlineBlockComponents?: never;
100
+ /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
101
+ blockComponents: BlockComponents<B, L, I>;
102
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
103
+ inlineBlockComponents: InlineBlockComponents<B, L, I>;
71
104
  linkToRecordComponents?: never;
72
105
  inlineRecordComponents?: never;
106
+ }
107
+ | {
108
+ /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
109
+ data:
110
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
111
+ blocks: B[];
112
+ links: L[];
113
+ inlineBlocks?: never;
114
+ })
115
+ | null
116
+ | undefined;
117
+ /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
118
+ blockComponents: BlockComponents<B, L, I>;
119
+ inlineBlockComponents?: never;
120
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
121
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
122
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
123
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
124
+ }
125
+ | {
126
+ /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
127
+ data:
128
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
129
+ blocks: B[];
130
+ links: L[];
131
+ inlineBlocks: I[];
132
+ })
133
+ | null
134
+ | undefined;
135
+ /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
136
+ blockComponents: BlockComponents<B, L, I>;
137
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
138
+ inlineBlockComponents: InlineBlockComponents<B, L, I>;
139
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
140
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
141
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
142
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
73
143
  };
74
144
 
75
- export function ensureValidStructuredTextProps<R1 extends DatocmsRecord, R2 extends DatocmsRecord>(
76
- props: Props<R1, R2>,
77
- ): Props<R1, R2> {
145
+ export function ensureValidStructuredTextProps<
146
+ B extends DatocmsRecord = DatocmsRecord,
147
+ L extends DatocmsRecord = DatocmsRecord,
148
+ I extends DatocmsRecord = DatocmsRecord,
149
+ >(props: Props<B, L, I>): Props<B, L, I> {
78
150
  return props;
79
151
  }
@@ -13,24 +13,40 @@ import type {
13
13
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
14
14
  export type AstroComponent<P = any> = (props: P) => any;
15
15
 
16
- export type BlockComponents<R1 extends DatocmsRecord, _R2 extends DatocmsRecord> = {
17
- [R in R1 as R['__typename']]: AstroComponent<{ block: R }>;
16
+ export type BlockComponents<
17
+ B extends DatocmsRecord,
18
+ _L extends DatocmsRecord,
19
+ _I extends DatocmsRecord,
20
+ > = {
21
+ [R in B as R['__typename']]: AstroComponent<{ block: R }>;
18
22
  };
19
23
 
20
- export type InlineBlockComponents<R1 extends DatocmsRecord, _R2 extends DatocmsRecord> = {
21
- [R in R1 as R['__typename']]: AstroComponent<{ block: R }>;
24
+ export type InlineBlockComponents<
25
+ _B extends DatocmsRecord,
26
+ _L extends DatocmsRecord,
27
+ I extends DatocmsRecord,
28
+ > = {
29
+ [R in I as R['__typename']]: AstroComponent<{ block: R }>;
22
30
  };
23
31
 
24
- export type LinkToRecordComponents<_R1 extends DatocmsRecord, R2 extends DatocmsRecord> = {
25
- [R in R2 as R['__typename']]: AstroComponent<{
32
+ export type LinkToRecordComponents<
33
+ _B extends DatocmsRecord,
34
+ L extends DatocmsRecord,
35
+ _I extends DatocmsRecord,
36
+ > = {
37
+ [R in L as R['__typename']]: AstroComponent<{
26
38
  node: ItemLink;
27
39
  attrs: TransformedMeta;
28
40
  record: R;
29
41
  }>;
30
42
  };
31
43
 
32
- export type InlineRecordComponents<_R1 extends DatocmsRecord, R2 extends DatocmsRecord> = {
33
- [R in R2 as R['__typename']]: AstroComponent<{ record: R }>;
44
+ export type InlineRecordComponents<
45
+ _B extends DatocmsRecord,
46
+ L extends DatocmsRecord,
47
+ _I extends DatocmsRecord,
48
+ > = {
49
+ [R in L as R['__typename']]: AstroComponent<{ record: R }>;
34
50
  };
35
51
 
36
52
  export type NodeOverrides = Partial<{
@@ -39,19 +55,27 @@ export type NodeOverrides = Partial<{
39
55
  ? {
40
56
  node: ItemLink;
41
57
  record: DatocmsRecord;
42
- linkToRecordComponents?: LinkToRecordComponents<DatocmsRecord, DatocmsRecord>;
58
+ linkToRecordComponents?: LinkToRecordComponents<
59
+ DatocmsRecord,
60
+ DatocmsRecord,
61
+ DatocmsRecord
62
+ >;
43
63
  }
44
64
  : N extends InlineItem
45
65
  ? {
46
66
  node: InlineItem;
47
67
  record: DatocmsRecord;
48
- inlineRecordComponents?: InlineRecordComponents<DatocmsRecord, DatocmsRecord>;
68
+ inlineRecordComponents?: InlineRecordComponents<
69
+ DatocmsRecord,
70
+ DatocmsRecord,
71
+ DatocmsRecord
72
+ >;
49
73
  }
50
74
  : N extends Block
51
75
  ? {
52
76
  node: Block;
53
77
  block: DatocmsRecord;
54
- blockComponents?: BlockComponents<DatocmsRecord, DatocmsRecord>;
78
+ blockComponents?: BlockComponents<DatocmsRecord, DatocmsRecord, DatocmsRecord>;
55
79
  }
56
80
  : N extends Span
57
81
  ? {
@@ -62,7 +86,11 @@ export type NodeOverrides = Partial<{
62
86
  ? {
63
87
  node: N;
64
88
  block: DatocmsRecord;
65
- inlineBlockComponents: InlineBlockComponents<DatocmsRecord, DatocmsRecord>;
89
+ inlineBlockComponents: InlineBlockComponents<
90
+ DatocmsRecord,
91
+ DatocmsRecord,
92
+ DatocmsRecord
93
+ >;
66
94
  }
67
95
  : { node: N }
68
96
  >;