react-datocms 8.0.0-0 → 8.0.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.
Files changed (80) hide show
  1. package/README.md +35 -15
  2. package/dist/cjs/ContentLink/index.js +104 -0
  3. package/dist/cjs/ContentLink/index.js.map +1 -0
  4. package/dist/cjs/Image/index.js +3 -3
  5. package/dist/cjs/Image/index.js.map +1 -1
  6. package/dist/cjs/Image/utils.js +3 -3
  7. package/dist/cjs/Image/utils.js.map +1 -1
  8. package/dist/cjs/SRCImage/index.js +3 -4
  9. package/dist/cjs/SRCImage/index.js.map +1 -1
  10. package/dist/cjs/SRCImage/utils.js +4 -4
  11. package/dist/cjs/SRCImage/utils.js.map +1 -1
  12. package/dist/cjs/Seo/nextUtils.js +1 -2
  13. package/dist/cjs/Seo/nextUtils.js.map +1 -1
  14. package/dist/cjs/Seo/remixUtils.js +2 -3
  15. package/dist/cjs/Seo/remixUtils.js.map +1 -1
  16. package/dist/cjs/Seo/renderMetaTags.js +1 -2
  17. package/dist/cjs/Seo/renderMetaTags.js.map +1 -1
  18. package/dist/cjs/Seo/renderMetaTagsToString.js +1 -2
  19. package/dist/cjs/Seo/renderMetaTagsToString.js.map +1 -1
  20. package/dist/cjs/StructuredText/index.js +34 -11
  21. package/dist/cjs/StructuredText/index.js.map +1 -1
  22. package/dist/cjs/VideoPlayer/index.js +45 -14
  23. package/dist/cjs/VideoPlayer/index.js.map +1 -1
  24. package/dist/cjs/index.js +2 -0
  25. package/dist/cjs/index.js.map +1 -1
  26. package/dist/cjs/useContentLink/index.js +111 -0
  27. package/dist/cjs/useContentLink/index.js.map +1 -0
  28. package/dist/cjs/useQuerySubscription/index.js +1 -2
  29. package/dist/cjs/useQuerySubscription/index.js.map +1 -1
  30. package/dist/cjs/useSiteSearch/index.js +3 -10
  31. package/dist/cjs/useSiteSearch/index.js.map +1 -1
  32. package/dist/esm/ContentLink/index.js +101 -0
  33. package/dist/esm/ContentLink/index.js.map +1 -0
  34. package/dist/esm/Image/index.js +3 -3
  35. package/dist/esm/Image/index.js.map +1 -1
  36. package/dist/esm/SRCImage/index.js +2 -2
  37. package/dist/esm/SRCImage/index.js.map +1 -1
  38. package/dist/esm/StructuredText/index.js +22 -4
  39. package/dist/esm/StructuredText/index.js.map +1 -1
  40. package/dist/esm/VideoPlayer/index.js +30 -9
  41. package/dist/esm/VideoPlayer/index.js.map +1 -1
  42. package/dist/esm/index.js +2 -0
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/useContentLink/index.js +105 -0
  45. package/dist/esm/useContentLink/index.js.map +1 -0
  46. package/dist/esm/useSiteSearch/index.js +2 -8
  47. package/dist/esm/useSiteSearch/index.js.map +1 -1
  48. package/dist/types/ContentLink/index.d.ts +88 -0
  49. package/dist/types/Image/index.d.ts +8 -1
  50. package/dist/types/Image/utils.d.ts +0 -1
  51. package/dist/types/SRCImage/index.d.ts +10 -3
  52. package/dist/types/SRCImage/utils.d.ts +1 -2
  53. package/dist/types/Seo/renderMetaTags.d.ts +0 -1
  54. package/dist/types/StructuredText/index.d.ts +20 -9
  55. package/dist/types/VideoPlayer/index.d.ts +6 -6
  56. package/dist/types/index.d.ts +2 -0
  57. package/dist/types/useContentLink/index.d.ts +91 -0
  58. package/dist/types/useSiteSearch/index.d.ts +3 -1
  59. package/dist/types/useVideoPlayer/index.d.ts +2 -2
  60. package/package.json +32 -17
  61. package/src/ContentLink/index.tsx +134 -0
  62. package/src/Image/__tests__/__snapshots__/index.test.tsx.snap +20 -0
  63. package/src/Image/index.tsx +11 -1
  64. package/src/SRCImage/__tests__/__snapshots__/index.test.tsx.snap +7 -0
  65. package/src/SRCImage/index.tsx +11 -2
  66. package/src/SRCImage/utils.tsx +1 -1
  67. package/src/StructuredText/__tests__/__snapshots__/index.test.tsx.snap +17 -0
  68. package/src/StructuredText/__tests__/index.test.tsx +27 -1
  69. package/src/StructuredText/index.tsx +80 -15
  70. package/src/VideoPlayer/index.tsx +43 -17
  71. package/src/index.ts +3 -0
  72. package/src/useContentLink/index.ts +187 -0
  73. package/src/useSiteSearch/index.tsx +6 -5
  74. package/src/useVideoPlayer/index.ts +2 -2
  75. package/dist/cjs/VideoPlayer/lazy.js +0 -35
  76. package/dist/cjs/VideoPlayer/lazy.js.map +0 -1
  77. package/dist/esm/VideoPlayer/lazy.js +0 -9
  78. package/dist/esm/VideoPlayer/lazy.js.map +0 -1
  79. package/dist/types/VideoPlayer/lazy.d.ts +0 -6
  80. package/src/VideoPlayer/lazy.tsx +0 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-datocms",
3
- "version": "8.0.0-0",
3
+ "version": "8.0.0",
4
4
  "engines": {
5
5
  "node": ">=8.0.0"
6
6
  },
@@ -24,11 +24,6 @@
24
24
  "import": "./dist/esm/Image/index.js",
25
25
  "types": "./dist/types/Image/index.d.ts"
26
26
  },
27
- "./video-player/lazy": {
28
- "require": "./dist/cjs/VideoPlayer/lazy.js",
29
- "import": "./dist/esm/VideoPlayer/lazy.js",
30
- "types": "./dist/types/VideoPlayer/lazy.d.ts"
31
- },
32
27
  "./video-player": {
33
28
  "require": "./dist/cjs/VideoPlayer/index.js",
34
29
  "import": "./dist/esm/VideoPlayer/index.js",
@@ -53,6 +48,16 @@
53
48
  "require": "./dist/cjs/useVideoPlayer/index.js",
54
49
  "import": "./dist/esm/useVideoPlayer/index.js",
55
50
  "types": "./dist/types/useVideoPlayer/index.d.ts"
51
+ },
52
+ "./use-content-link": {
53
+ "require": "./dist/cjs/useContentLink/index.js",
54
+ "import": "./dist/esm/useContentLink/index.js",
55
+ "types": "./dist/types/useContentLink/index.d.ts"
56
+ },
57
+ "./content-link": {
58
+ "require": "./dist/cjs/ContentLink/index.js",
59
+ "import": "./dist/esm/ContentLink/index.js",
60
+ "types": "./dist/types/ContentLink/index.d.ts"
56
61
  }
57
62
  },
58
63
  "typesVersions": {
@@ -69,9 +74,6 @@
69
74
  "video-player": [
70
75
  "./dist/types/VideoPlayer/index.d.ts"
71
76
  ],
72
- "video-player/lazy": [
73
- "./dist/types/VideoPlayer/lazy.d.ts"
74
- ],
75
77
  "structured-text": [
76
78
  "./dist/types/StructuredText/index.d.ts"
77
79
  ],
@@ -83,6 +85,12 @@
83
85
  ],
84
86
  "use-video-player": [
85
87
  "./dist/types/useVideoPlayer/index.d.ts"
88
+ ],
89
+ "use-content-link": [
90
+ "./dist/types/useContentLink/index.d.ts"
91
+ ],
92
+ "content-link": [
93
+ "./dist/types/ContentLink/index.d.ts"
86
94
  ]
87
95
  }
88
96
  },
@@ -103,10 +111,11 @@
103
111
  "homepage": "https://github.com/datocms/react-datocms",
104
112
  "devDependencies": {
105
113
  "@biomejs/biome": "^1.6.3",
106
- "@mux/mux-player-react": "*",
114
+ "@mux/mux-player-react": "^3.11.4",
107
115
  "@types/enzyme": "^3.10.8",
108
116
  "@types/enzyme-to-json": "^1.5.4",
109
117
  "@types/jest": "^29.5.11",
118
+ "@types/node": "^25.0.10",
110
119
  "@types/raf": "^3.4.0",
111
120
  "@types/react": "^17.0.3",
112
121
  "@types/react-dom": "^17.0.3",
@@ -123,8 +132,8 @@
123
132
  "react-dom": "^17.0.2",
124
133
  "resize-observer-polyfill": "^1.5.1",
125
134
  "rimraf": "^3.0.2",
126
- "ts-jest": "^29.1.2",
127
- "typescript": "^5.0.0"
135
+ "ts-jest": "^29.2.5",
136
+ "typescript": "^5.9.3"
128
137
  },
129
138
  "scripts": {
130
139
  "build": "rimraf dist && npm run tsc:types && npm run tsc:cjs && npm run tsc:esm",
@@ -138,15 +147,21 @@
138
147
  "tsc:esm": "tsc --project ./tsconfig.esnext.json"
139
148
  },
140
149
  "peerDependencies": {
150
+ "@mux/mux-player-react": ">=2.5.0",
141
151
  "react": ">= 16.12.0"
142
152
  },
153
+ "peerDependenciesMeta": {
154
+ "@mux/mux-player-react": {
155
+ "optional": true
156
+ }
157
+ },
143
158
  "dependencies": {
144
- "datocms-listen": "^0.1.9",
145
- "datocms-structured-text-generic-html-renderer": "^4.0.1",
146
- "datocms-structured-text-utils": "^4.0.1",
159
+ "@datocms/content-link": "^0.3.13",
160
+ "datocms-listen": "^1.0.2",
161
+ "datocms-structured-text-generic-html-renderer": "^5.0.0",
162
+ "datocms-structured-text-utils": "^5.1.6",
147
163
  "react-intersection-observer": "^9.4.3",
148
164
  "react-string-replace": "^1.1.0",
149
- "use-deep-compare-effect": "^1.6.1",
150
- "@mux/mux-player-react": "*"
165
+ "use-deep-compare-effect": "^1.6.1"
151
166
  }
152
167
  }
@@ -0,0 +1,134 @@
1
+ 'use client';
2
+
3
+ import { useEffect } from 'react';
4
+ import {
5
+ type ClickToEditOptions,
6
+ type UseContentLinkOptions,
7
+ useContentLink,
8
+ } from '../useContentLink/index.js';
9
+
10
+ export type ContentLinkProps = Omit<UseContentLinkOptions, 'enabled'> & {
11
+ /** Current pathname to sync with Web Previews plugin */
12
+ currentPath?: string;
13
+ /**
14
+ * Whether to enable click-to-edit overlays on mount, or options to configure them.
15
+ *
16
+ * - `true`: Enable click-to-edit mode immediately
17
+ * - `{ scrollToNearestTarget: true }`: Enable and scroll to nearest editable if none visible
18
+ * - `{ hoverOnly: true }`: Only enable on devices with hover capability (non-touch)
19
+ * - `false`/`undefined`: Don't enable automatically (use Alt/Option key to toggle)
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * <ContentLink enableClickToEdit={true} />
24
+ * <ContentLink enableClickToEdit={{ scrollToNearestTarget: true }} />
25
+ * <ContentLink enableClickToEdit={{ hoverOnly: true, scrollToNearestTarget: true }} />
26
+ * ```
27
+ */
28
+ enableClickToEdit?: boolean | ClickToEditOptions;
29
+ /** Whether to strip stega encoding from text nodes after stamping. */
30
+ stripStega?: boolean;
31
+ };
32
+
33
+ /**
34
+ * ContentLink component for Visual Editing with DatoCMS.
35
+ *
36
+ * This component enables Visual Editing by:
37
+ * - Detecting stega-encoded metadata in content and creating click-to-edit overlays
38
+ * - Integrating with DatoCMS Web Previews plugin for in-editor editing
39
+ * - Supporting Alt/Option key for temporary click-to-edit mode
40
+ * - Providing bidirectional communication between preview and DatoCMS editor
41
+ *
42
+ * ## Basic Usage (Standalone Website with Click-to-Edit)
43
+ *
44
+ * For standalone websites with click-to-edit overlays:
45
+ *
46
+ * ```tsx
47
+ * import { ContentLink } from 'react-datocms';
48
+ *
49
+ * function App() {
50
+ * return (
51
+ * <>
52
+ * <ContentLink enableClickToEdit={true} />
53
+ * {/* Your content with stega-encoded data *\/}
54
+ * </>
55
+ * );
56
+ * }
57
+ * ```
58
+ *
59
+ * ## Web Previews Plugin Integration (Next.js Example)
60
+ *
61
+ * For integration with DatoCMS Web Previews plugin, provide navigation callbacks:
62
+ *
63
+ * ```tsx
64
+ * 'use client';
65
+ * import { ContentLink } from 'react-datocms';
66
+ * import { useRouter, usePathname } from 'next/navigation';
67
+ *
68
+ * export function VisualEditing() {
69
+ * const router = useRouter();
70
+ * const pathname = usePathname();
71
+ *
72
+ * return (
73
+ * <ContentLink
74
+ * onNavigateTo={(path) => router.push(path)}
75
+ * currentPath={pathname}
76
+ * />
77
+ * );
78
+ * }
79
+ * ```
80
+ *
81
+ * ## How Visual Editing Works
82
+ *
83
+ * 1. **Fetch content with stega encoding**: Use the `contentLink` and `baseEditingUrl` options
84
+ * when fetching content from DatoCMS to embed editing metadata.
85
+ *
86
+ * 2. **Add ContentLink component**: Place this component in your app to scan for encoded
87
+ * content and create overlays.
88
+ *
89
+ * 3. **Enable editing**: Either set `enableClickToEdit={true}` prop or hold Alt/Option key
90
+ * for temporary editing mode.
91
+ *
92
+ * 4. **Click to edit**: Click on any content to open the DatoCMS editor at that field.
93
+ *
94
+ * @param props - Configuration props for ContentLink
95
+ * @returns null - This component has no visual output
96
+ */
97
+ export function ContentLink(props: ContentLinkProps): null {
98
+ const {
99
+ currentPath,
100
+ enableClickToEdit: enableClickToEditOptions,
101
+ stripStega,
102
+ ...useContentLinkOptions
103
+ } = props;
104
+
105
+ const { enableClickToEdit, setCurrentPath } = useContentLink({
106
+ ...useContentLinkOptions,
107
+ enabled: stripStega !== undefined ? { stripStega } : true,
108
+ });
109
+
110
+ // Sync current path when it changes
111
+ useEffect(() => {
112
+ if (currentPath !== undefined) {
113
+ setCurrentPath(currentPath);
114
+ }
115
+ }, [currentPath, setCurrentPath]);
116
+
117
+ // Enable click-to-edit on mount if requested
118
+ useEffect(() => {
119
+ if (!enableClickToEditOptions) {
120
+ return;
121
+ }
122
+
123
+ // Never enable click-to-edit inside an iframe
124
+ if (typeof window === 'undefined' || window.parent !== window) {
125
+ return;
126
+ }
127
+
128
+ enableClickToEdit(
129
+ enableClickToEditOptions === true ? undefined : enableClickToEditOptions,
130
+ );
131
+ }, [enableClickToEditOptions, enableClickToEdit]);
132
+
133
+ return null;
134
+ }
@@ -61,6 +61,7 @@ exports[`Image explicit sizes renders correctly 1`] = `
61
61
  <img
62
62
  alt=""
63
63
  onLoad={[Function]}
64
+ referrerPolicy="no-referrer-when-downgrade"
64
65
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
65
66
  style={
66
67
  {
@@ -205,6 +206,7 @@ exports[`Image layout=fill visible image loaded shows the image 1`] = `
205
206
  <img
206
207
  alt="DatoCMS swag"
207
208
  onLoad={[Function]}
209
+ referrerPolicy="no-referrer-when-downgrade"
208
210
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
209
211
  style={
210
212
  {
@@ -285,6 +287,7 @@ exports[`Image layout=fill visible renders the image (minimal data) 1`] = `
285
287
  <img
286
288
  alt=""
287
289
  onLoad={[Function]}
290
+ referrerPolicy="no-referrer-when-downgrade"
288
291
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
289
292
  style={
290
293
  {
@@ -364,6 +367,7 @@ exports[`Image layout=fill visible renders the image (relative URL) 1`] = `
364
367
  <img
365
368
  alt=""
366
369
  onLoad={[Function]}
370
+ referrerPolicy="no-referrer-when-downgrade"
367
371
  src="/205/image.png?ar=16%3A9&fit=crop&w=750"
368
372
  style={
369
373
  {
@@ -449,6 +453,7 @@ exports[`Image layout=fill visible renders the image 1`] = `
449
453
  <img
450
454
  alt="DatoCMS swag"
451
455
  onLoad={[Function]}
456
+ referrerPolicy="no-referrer-when-downgrade"
452
457
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
453
458
  style={
454
459
  {
@@ -606,6 +611,7 @@ exports[`Image layout=fixed visible image loaded shows the image 1`] = `
606
611
  <img
607
612
  alt="DatoCMS swag"
608
613
  onLoad={[Function]}
614
+ referrerPolicy="no-referrer-when-downgrade"
609
615
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
610
616
  style={
611
617
  {
@@ -692,6 +698,7 @@ exports[`Image layout=fixed visible renders the image (minimal data) 1`] = `
692
698
  <img
693
699
  alt=""
694
700
  onLoad={[Function]}
701
+ referrerPolicy="no-referrer-when-downgrade"
695
702
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
696
703
  style={
697
704
  {
@@ -777,6 +784,7 @@ exports[`Image layout=fixed visible renders the image (relative URL) 1`] = `
777
784
  <img
778
785
  alt=""
779
786
  onLoad={[Function]}
787
+ referrerPolicy="no-referrer-when-downgrade"
780
788
  src="/205/image.png?ar=16%3A9&fit=crop&w=750"
781
789
  style={
782
790
  {
@@ -868,6 +876,7 @@ exports[`Image layout=fixed visible renders the image 1`] = `
868
876
  <img
869
877
  alt="DatoCMS swag"
870
878
  onLoad={[Function]}
879
+ referrerPolicy="no-referrer-when-downgrade"
871
880
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
872
881
  style={
873
882
  {
@@ -1027,6 +1036,7 @@ exports[`Image layout=intrinsic visible image loaded shows the image 1`] = `
1027
1036
  <img
1028
1037
  alt="DatoCMS swag"
1029
1038
  onLoad={[Function]}
1039
+ referrerPolicy="no-referrer-when-downgrade"
1030
1040
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1031
1041
  style={
1032
1042
  {
@@ -1114,6 +1124,7 @@ exports[`Image layout=intrinsic visible renders the image (minimal data) 1`] = `
1114
1124
  <img
1115
1125
  alt=""
1116
1126
  onLoad={[Function]}
1127
+ referrerPolicy="no-referrer-when-downgrade"
1117
1128
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1118
1129
  style={
1119
1130
  {
@@ -1200,6 +1211,7 @@ exports[`Image layout=intrinsic visible renders the image (relative URL) 1`] = `
1200
1211
  <img
1201
1212
  alt=""
1202
1213
  onLoad={[Function]}
1214
+ referrerPolicy="no-referrer-when-downgrade"
1203
1215
  src="/205/image.png?ar=16%3A9&fit=crop&w=750"
1204
1216
  style={
1205
1217
  {
@@ -1292,6 +1304,7 @@ exports[`Image layout=intrinsic visible renders the image 1`] = `
1292
1304
  <img
1293
1305
  alt="DatoCMS swag"
1294
1306
  onLoad={[Function]}
1307
+ referrerPolicy="no-referrer-when-downgrade"
1295
1308
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1296
1309
  style={
1297
1310
  {
@@ -1449,6 +1462,7 @@ exports[`Image layout=responsive visible image loaded shows the image 1`] = `
1449
1462
  <img
1450
1463
  alt="DatoCMS swag"
1451
1464
  onLoad={[Function]}
1465
+ referrerPolicy="no-referrer-when-downgrade"
1452
1466
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1453
1467
  style={
1454
1468
  {
@@ -1535,6 +1549,7 @@ exports[`Image layout=responsive visible renders the image (minimal data) 1`] =
1535
1549
  <img
1536
1550
  alt=""
1537
1551
  onLoad={[Function]}
1552
+ referrerPolicy="no-referrer-when-downgrade"
1538
1553
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1539
1554
  style={
1540
1555
  {
@@ -1620,6 +1635,7 @@ exports[`Image layout=responsive visible renders the image (relative URL) 1`] =
1620
1635
  <img
1621
1636
  alt=""
1622
1637
  onLoad={[Function]}
1638
+ referrerPolicy="no-referrer-when-downgrade"
1623
1639
  src="/205/image.png?ar=16%3A9&fit=crop&w=750"
1624
1640
  style={
1625
1641
  {
@@ -1711,6 +1727,7 @@ exports[`Image layout=responsive visible renders the image 1`] = `
1711
1727
  <img
1712
1728
  alt="DatoCMS swag"
1713
1729
  onLoad={[Function]}
1730
+ referrerPolicy="no-referrer-when-downgrade"
1714
1731
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1715
1732
  style={
1716
1733
  {
@@ -1834,6 +1851,7 @@ exports[`Image passing className and/or style renders correctly 1`] = `
1834
1851
  alt=""
1835
1852
  className="img-class-name"
1836
1853
  onLoad={[Function]}
1854
+ referrerPolicy="no-referrer-when-downgrade"
1837
1855
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1838
1856
  style={
1839
1857
  {
@@ -1928,6 +1946,7 @@ exports[`Image priority=true renders correctly 1`] = `
1928
1946
  alt=""
1929
1947
  fetchpriority="high"
1930
1948
  onLoad={[Function]}
1949
+ referrerPolicy="no-referrer-when-downgrade"
1931
1950
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1932
1951
  style={
1933
1952
  {
@@ -1993,6 +2012,7 @@ exports[`Image usePlaceholder=false renders correctly 1`] = `
1993
2012
  <img
1994
2013
  alt=""
1995
2014
  onLoad={[Function]}
2015
+ referrerPolicy="no-referrer-when-downgrade"
1996
2016
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
1997
2017
  style={
1998
2018
  {
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  // biome-ignore lint/style/useImportType: wrong warning
4
- import React from 'react';
4
+ import React, { HTMLAttributeReferrerPolicy } from 'react';
5
5
  import { type CSSProperties, forwardRef, useRef } from 'react';
6
6
  import {
7
7
  buildRegularSource,
@@ -111,6 +111,13 @@ export type ImagePropTypes = {
111
111
  * Default candidate multipliers are [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4]
112
112
  **/
113
113
  srcSetCandidates?: number[];
114
+ /**
115
+ * Defines which referrer is sent when fetching the image
116
+ * Read more: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#referrerpolicy
117
+ *
118
+ * Defaults to `no-referrer-when-downgrade` to give more useful stats in DatoCMS Project Usages
119
+ **/
120
+ referrerPolicy?: HTMLAttributeReferrerPolicy;
114
121
  };
115
122
 
116
123
  type State = {
@@ -175,6 +182,7 @@ export const Image = forwardRef<HTMLDivElement, ImagePropTypes>(
175
182
  srcSetCandidates = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4],
176
183
  placeholderClassName,
177
184
  placeholderStyle,
185
+ referrerPolicy = 'no-referrer-when-downgrade',
178
186
  },
179
187
  ref,
180
188
  ) => {
@@ -300,6 +308,7 @@ export const Image = forwardRef<HTMLDivElement, ImagePropTypes>(
300
308
  objectPosition,
301
309
  ...imgStyle,
302
310
  }}
311
+ referrerPolicy={referrerPolicy}
303
312
  />
304
313
  )}
305
314
  </picture>
@@ -323,6 +332,7 @@ export const Image = forwardRef<HTMLDivElement, ImagePropTypes>(
323
332
  }}
324
333
  loading={priority ? undefined : 'lazy'}
325
334
  {...priorityProp(priority ? 'high' : undefined)}
335
+ referrerPolicy={referrerPolicy}
326
336
  />
327
337
  )}
328
338
  </picture>
@@ -20,6 +20,7 @@ exports[`Image explicit sizes renders correctly 1`] = `
20
20
  <img
21
21
  alt=""
22
22
  loading="lazy"
23
+ referrerPolicy="no-referrer-when-downgrade"
23
24
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
24
25
  style={
25
26
  {
@@ -63,6 +64,7 @@ exports[`Image full data renders correctly 1`] = `
63
64
  <img
64
65
  alt="DatoCMS swag"
65
66
  loading="lazy"
67
+ referrerPolicy="no-referrer-when-downgrade"
66
68
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
67
69
  style={
68
70
  {
@@ -101,6 +103,7 @@ exports[`Image minimal data renders correctly 1`] = `
101
103
  <img
102
104
  alt=""
103
105
  loading="lazy"
106
+ referrerPolicy="no-referrer-when-downgrade"
104
107
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
105
108
  style={
106
109
  {
@@ -138,6 +141,7 @@ exports[`Image minimalDataWithRelativeUrl renders correctly 1`] = `
138
141
  <img
139
142
  alt=""
140
143
  loading="lazy"
144
+ referrerPolicy="no-referrer-when-downgrade"
141
145
  src="/205/image.png?ar=16%3A9&fit=crop&w=750"
142
146
  style={
143
147
  {
@@ -195,6 +199,7 @@ exports[`Image passing className and/or style renders correctly 1`] = `
195
199
  alt=""
196
200
  className="class-name"
197
201
  loading="lazy"
202
+ referrerPolicy="no-referrer-when-downgrade"
198
203
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
199
204
  style={
200
205
  {
@@ -234,6 +239,7 @@ exports[`Image priority=true renders correctly 1`] = `
234
239
  <img
235
240
  alt=""
236
241
  fetchpriority="high"
242
+ referrerPolicy="no-referrer-when-downgrade"
237
243
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
238
244
  style={
239
245
  {
@@ -272,6 +278,7 @@ exports[`Image usePlaceholder=false renders correctly 1`] = `
272
278
  <img
273
279
  alt=""
274
280
  loading="lazy"
281
+ referrerPolicy="no-referrer-when-downgrade"
275
282
  src="https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750"
276
283
  style={
277
284
  {
@@ -1,6 +1,6 @@
1
1
  // biome-ignore lint/style/useImportType: wrong warning
2
- import React from 'react';
3
- import type { ResponsiveImageType } from '../Image';
2
+ import React, { HTMLAttributeReferrerPolicy } from 'react';
3
+ import type { ResponsiveImageType } from '../Image/index.js';
4
4
  import { buildRegularSource, buildWebpSource, priorityProp } from './utils.js';
5
5
 
6
6
  export type SRCImagePropTypes = {
@@ -36,6 +36,13 @@ export type SRCImagePropTypes = {
36
36
  * Default candidate multipliers are [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4]
37
37
  **/
38
38
  srcSetCandidates?: number[];
39
+ /**
40
+ * Defines which referrer is sent when fetching the image
41
+ * Read more: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#referrerpolicy
42
+ *
43
+ * Defaults to `no-referrer-when-downgrade` to give more useful stats in DatoCMS Project Usages
44
+ **/
45
+ referrerPolicy?: HTMLAttributeReferrerPolicy;
39
46
  };
40
47
 
41
48
  export function SRCImage({
@@ -48,6 +55,7 @@ export function SRCImage({
48
55
  priority = false,
49
56
  sizes,
50
57
  srcSetCandidates = [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4],
58
+ referrerPolicy = 'no-referrer-when-downgrade',
51
59
  }: SRCImagePropTypes) {
52
60
  const webpSource = buildWebpSource(data, sizes);
53
61
  const regularSource = buildRegularSource(data, sizes, srcSetCandidates);
@@ -98,6 +106,7 @@ export function SRCImage({
98
106
  ...sizingStyle,
99
107
  ...imgStyle,
100
108
  }}
109
+ referrerPolicy={referrerPolicy}
101
110
  />
102
111
  )}
103
112
  </picture>
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { ResponsiveImageType } from '../Image';
2
+ import type { ResponsiveImageType } from '../Image/index.js';
3
3
 
4
4
  export function priorityProp(
5
5
  fetchPriority?: string,
@@ -225,6 +225,13 @@ exports[`StructuredText with links/blocks with default rules renders the documen
225
225
  "quote": "Foo bar.",
226
226
  },
227
227
  ],
228
+ "inlineBlocks": [
229
+ {
230
+ "__typename": "MentionRecord",
231
+ "id": "789",
232
+ "name": "Jane Doe",
233
+ },
234
+ ],
228
235
  "links": [
229
236
  {
230
237
  "__typename": "DocPageRecord",
@@ -269,6 +276,10 @@ exports[`StructuredText with links/blocks with default rules renders the documen
269
276
  ],
270
277
  "type": "itemLink",
271
278
  },
279
+ {
280
+ "item": "789",
281
+ "type": "inlineBlock",
282
+ },
272
283
  ],
273
284
  "level": 1,
274
285
  "type": "heading",
@@ -285,6 +296,7 @@ exports[`StructuredText with links/blocks with default rules renders the documen
285
296
  }
286
297
  }
287
298
  renderBlock={[Function]}
299
+ renderInlineBlock={[Function]}
288
300
  renderInlineRecord={[Function]}
289
301
  renderLinkToRecord={[Function]}
290
302
  >
@@ -310,6 +322,11 @@ exports[`StructuredText with links/blocks with default rules renders the documen
310
322
  >
311
323
  here!
312
324
  </a>
325
+ <em
326
+ key="t-4"
327
+ >
328
+ Jane Doe
329
+ </em>
313
330
  </h1>
314
331
  <figure
315
332
  key="t-1"
@@ -136,6 +136,12 @@ describe('StructuredText', () => {
136
136
  author: string;
137
137
  };
138
138
 
139
+ type MentionRecord = {
140
+ id: string;
141
+ __typename: 'MentionRecord';
142
+ name: string;
143
+ };
144
+
139
145
  type DocPageRecord = {
140
146
  id: string;
141
147
  __typename: 'DocPageRecord';
@@ -145,7 +151,8 @@ describe('StructuredText', () => {
145
151
 
146
152
  const structuredText: StructuredTextGraphQlResponse<
147
153
  QuoteRecord,
148
- DocPageRecord
154
+ DocPageRecord,
155
+ MentionRecord
149
156
  > = {
150
157
  value: {
151
158
  schema: 'dast',
@@ -175,6 +182,10 @@ describe('StructuredText', () => {
175
182
  meta: [{ id: 'target', value: '_blank' }],
176
183
  children: [{ type: 'span', value: 'here!' }],
177
184
  },
185
+ {
186
+ type: 'inlineBlock',
187
+ item: '789',
188
+ },
178
189
  ],
179
190
  },
180
191
  {
@@ -192,6 +203,13 @@ describe('StructuredText', () => {
192
203
  author: 'Mark Smith',
193
204
  },
194
205
  ],
206
+ inlineBlocks: [
207
+ {
208
+ id: '789',
209
+ __typename: 'MentionRecord',
210
+ name: 'Jane Doe',
211
+ },
212
+ ],
195
213
  links: [
196
214
  {
197
215
  id: '123',
@@ -240,6 +258,14 @@ describe('StructuredText', () => {
240
258
  return null;
241
259
  }
242
260
  }}
261
+ renderInlineBlock={({ record }) => {
262
+ switch (record.__typename) {
263
+ case 'MentionRecord':
264
+ return <em>{record.name}</em>;
265
+ default:
266
+ return null;
267
+ }
268
+ }}
243
269
  />,
244
270
  );
245
271
  expect(wrapper).toMatchSnapshot();