@datocms/astro 0.3.1 → 0.3.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
@@ -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.3.1",
5
+ "version": "0.3.3",
6
6
  "sideEffects": false,
7
7
  "repository": {
8
8
  "type": "git",
@@ -10,6 +10,7 @@ import {
10
10
  isInlineItem,
11
11
  isItemLink,
12
12
  RenderError,
13
+ type NodeType,
13
14
  } from 'datocms-structured-text-utils';
14
15
 
15
16
  import Blockquote from './nodes/Blockquote.astro';
@@ -26,7 +27,13 @@ import BlockComponent from './nodes/Block.astro';
26
27
  import InlineItemComponent from './nodes/InlineItem.astro';
27
28
  import ItemLinkComponent from './nodes/ItemLink.astro';
28
29
 
29
- import type { BlockComponents, InlineItemComponents, ItemLinkComponents, Overrides } from './types';
30
+ import type {
31
+ BlockComponents,
32
+ InlineItemComponents,
33
+ ItemLinkComponents,
34
+ Overrides,
35
+ AstroComponent,
36
+ } from './types';
30
37
 
31
38
  interface Props {
32
39
  node: DastNode;
@@ -71,7 +78,7 @@ function findRecordInLinks(node: ItemLink | InlineItem) {
71
78
  return record;
72
79
  }
73
80
 
74
- const defaultComponents: Overrides = {
81
+ const defaultComponents: Record<NodeType, AstroComponent> = {
75
82
  paragraph: Paragraph,
76
83
  root: Root,
77
84
  span: Span,
@@ -87,7 +94,11 @@ const defaultComponents: Overrides = {
87
94
  block: BlockComponent,
88
95
  };
89
96
 
90
- const otherNodeComponents: Overrides = { ...defaultComponents, ...overrides };
97
+ const otherNodeComponents: Record<NodeType, AstroComponent> = {
98
+ ...defaultComponents,
99
+ ...overrides,
100
+ };
101
+
91
102
  const Component = otherNodeComponents[node.type];
92
103
  ---
93
104
 
@@ -12,13 +12,18 @@ import {
12
12
  import Node from './Node.astro';
13
13
  import type { BlockComponents, InlineItemComponents, ItemLinkComponents, Overrides } from './types';
14
14
 
15
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
16
- interface Props<R1 extends DatocmsRecord = any, R2 extends DatocmsRecord = any> {
17
- data: StructuredText<R1, R2> | Document | DastNode | null | undefined;
18
-
19
- blockComponents?: BlockComponents<R1, R2>;
20
- itemLinkComponents?: ItemLinkComponents<R1, R2>;
21
- inlineItemComponents?: InlineItemComponents<R1, R2>;
15
+ // It would be better to type this as:
16
+ //
17
+ // interface Props<R1 extends DatocmsRecord = any, R2 extends DatocmsRecord = any>
18
+ //
19
+ // but it's currently not possible: https://github.com/withastro/roadmap/discussions/601#discussioncomment-10333959
20
+
21
+ interface Props {
22
+ data: StructuredText<DatocmsRecord, DatocmsRecord> | Document | DastNode | null | undefined;
23
+
24
+ blockComponents?: BlockComponents<DatocmsRecord, DatocmsRecord>;
25
+ itemLinkComponents?: ItemLinkComponents<DatocmsRecord, DatocmsRecord>;
26
+ inlineItemComponents?: InlineItemComponents<DatocmsRecord, DatocmsRecord>;
22
27
  overrides?: Overrides;
23
28
  }
24
29
 
@@ -1,7 +1,7 @@
1
1
  import type { Record as DatocmsRecord, NodeType } from 'datocms-structured-text-utils';
2
2
 
3
3
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
4
- type AstroComponent = (props: any) => any;
4
+ export type AstroComponent = (props: any) => any;
5
5
 
6
6
  export type BlockComponents<R1 extends DatocmsRecord, R2 extends DatocmsRecord> = Record<
7
7
  R1['__typename'],
@@ -18,4 +18,4 @@ export type InlineItemComponents<R1 extends DatocmsRecord, R2 extends DatocmsRec
18
18
  AstroComponent
19
19
  >;
20
20
 
21
- export type Overrides = Record<NodeType, AstroComponent>;
21
+ export type Overrides = Partial<Record<NodeType, AstroComponent>>;