@datocms/astro 0.5.1 → 0.6.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.
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.1",
5
+ "version": "0.6.0",
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": "*"
@@ -14,7 +14,7 @@ const {
14
14
  usePlaceholder = true,
15
15
  sizes,
16
16
  srcSetCandidates = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4],
17
- referrerPolicy = 'strict-origin',
17
+ referrerPolicy = 'no-referrer-when-downgrade',
18
18
  } = Astro.props;
19
19
 
20
20
  const placeholderStyle =
@@ -122,4 +122,4 @@ Here's a complete recap of what `responsiveImage` offers:
122
122
  | sizes | string | undefined | :x: | The HTML5 [`sizes`](https://web.dev/learn/design/responsive-images/#sizes) attribute for the image (will be used `data.sizes` as a fallback) |
123
123
  | usePlaceholder | Boolean | true | :x: | Whether the image should use a blurred image placeholder |
124
124
  | srcSetCandidates | Array<number> | [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4] | :x: | If `data` does not contain `srcSet`, the candidates for the `srcset` attribute of the image will be auto-generated based on these width multipliers |
125
- | referrerPolicy | string | `strict-origin` | :x: | Defines which referrer is sent when fetching the image. Defaults to `strict-origin` to give more useful stats in DatoCMS Project Usages |
125
+ | referrerPolicy | string | `no-referrer-when-downgrade` | :x: | Defines which referrer is sent when fetching the image. Defaults to `no-referrer-when-downgrade` to give more useful stats in DatoCMS Project Usages |
@@ -67,7 +67,7 @@ export type ImageProps = {
67
67
  * Defines which referrer is sent when fetching the image
68
68
  * Read more: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#referrerpolicy
69
69
  *
70
- * Defaults to `strict-origin` to give more useful stats in DatoCMS Project Usages
70
+ * Defaults to `no-referrer-when-downgrade` to give more useful stats in DatoCMS Project Usages
71
71
  **/
72
72
  referrerPolicy?: JSX.HTMLAttributeReferrerPolicy;
73
73
  };
@@ -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>;
@@ -4,14 +4,9 @@ import {
4
4
  type Document,
5
5
  type StructuredText,
6
6
  } from 'datocms-structured-text-utils';
7
- import type {
8
- BlockComponents,
9
- InlineBlockComponents,
10
- InlineRecordComponents,
11
- LinkToRecordComponents,
12
- } from './types';
7
+ import type { BlockComponents, InlineRecordComponents, LinkToRecordComponents } from './types';
13
8
 
14
- type Props<R1 extends DatocmsRecord, R2 extends DatocmsRecord> =
9
+ type Props<B extends DatocmsRecord, L extends DatocmsRecord, I extends DatocmsRecord> =
15
10
  | {
16
11
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
17
12
  data: Document | DastNode | null | undefined;
@@ -23,57 +18,129 @@ type Props<R1 extends DatocmsRecord, R2 extends DatocmsRecord> =
23
18
  | {
24
19
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
25
20
  data:
26
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks: R1[]; links: R2[] })
21
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
22
+ blocks: B[];
23
+ links: never;
24
+ inlineBlocks: never;
25
+ })
27
26
  | null
28
27
  | undefined;
29
28
  /** 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>;
29
+ blockComponents: BlockComponents<B, L, I>;
30
+ inlineBlockComponents?: never;
31
+ linkToRecordComponents?: never;
32
+ inlineRecordComponents?: never;
33
+ }
34
+ | {
35
+ /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
36
+ data:
37
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
38
+ blocks: never;
39
+ links: L[];
40
+ inlineBlocks: never;
41
+ })
42
+ | null
43
+ | undefined;
44
+ blockComponents?: never;
45
+ inlineBlockComponents?: never;
33
46
  /** 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>;
47
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
35
48
  /** 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>;
49
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
37
50
  }
38
51
  | {
39
52
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
40
53
  data:
41
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks: R1[]; links?: never })
54
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
55
+ blocks: never;
56
+ links: never;
57
+ inlineBlocks: I[];
58
+ })
42
59
  | null
43
60
  | 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>;
61
+ blockComponents?: never;
62
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
63
+ inlineBlockComponents: BlockComponents<B, L, I>;
47
64
  linkToRecordComponents?: never;
48
65
  inlineRecordComponents?: never;
49
66
  }
50
67
  | {
51
68
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
52
69
  data:
53
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks?: never; links: R2[] })
70
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
71
+ blocks: never;
72
+ links: L[];
73
+ inlineBlocks: I[];
74
+ })
54
75
  | null
55
76
  | undefined;
56
77
  blockComponents?: never;
57
- inlineBlockComponents?: never;
78
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
79
+ inlineBlockComponents: BlockComponents<B, L, I>;
58
80
  /** 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>;
81
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
60
82
  /** 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>;
83
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
62
84
  }
63
85
  | {
64
86
  /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
65
87
  data:
66
- | (Omit<StructuredText<R1, R2>, 'blocks' | 'links'> & { blocks?: never; links?: never })
88
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
89
+ blocks: B[];
90
+ links: never;
91
+ inlineBlocks: I[];
92
+ })
67
93
  | null
68
94
  | undefined;
69
- blockComponents?: never;
70
- inlineBlockComponents?: never;
95
+ /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
96
+ blockComponents: BlockComponents<B, L, I>;
97
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
98
+ inlineBlockComponents: BlockComponents<B, L, I>;
71
99
  linkToRecordComponents?: never;
72
100
  inlineRecordComponents?: never;
101
+ }
102
+ | {
103
+ /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
104
+ data:
105
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
106
+ blocks: B[];
107
+ links: L[];
108
+ inlineBlocks: never;
109
+ })
110
+ | null
111
+ | undefined;
112
+ /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
113
+ blockComponents: BlockComponents<B, L, I>;
114
+ inlineBlockComponents?: never;
115
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
116
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
117
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
118
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
119
+ }
120
+ | {
121
+ /** The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from a DatoCMS Structured Text field */
122
+ data:
123
+ | (Omit<StructuredText<B, L, I>, 'blocks' | 'links' | 'inlineBlocks'> & {
124
+ blocks: B[];
125
+ links: L[];
126
+ inlineBlocks: I[];
127
+ })
128
+ | null
129
+ | undefined;
130
+ /** An object in which the keys are the `__typename` of the blocks to be rendered, and the values are the Astro components */
131
+ blockComponents: BlockComponents<B, L, I>;
132
+ /** An object in which the keys are the `__typename` of the inline blocks to be rendered, and the values are the Astro components */
133
+ inlineBlockComponents: BlockComponents<B, L, I>;
134
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
135
+ linkToRecordComponents: LinkToRecordComponents<B, L, I>;
136
+ /** An object in which the keys are the `__typename` of the records to be rendered, and the values are the Astro components */
137
+ inlineRecordComponents: InlineRecordComponents<B, L, I>;
73
138
  };
74
139
 
75
- export function ensureValidStructuredTextProps<R1 extends DatocmsRecord, R2 extends DatocmsRecord>(
76
- props: Props<R1, R2>,
77
- ): Props<R1, R2> {
140
+ export function ensureValidStructuredTextProps<
141
+ B extends DatocmsRecord,
142
+ L extends DatocmsRecord,
143
+ I extends DatocmsRecord,
144
+ >(props: Props<B, L, I>): Props<B, L, I> {
78
145
  return props;
79
146
  }
@@ -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
  >;