react-datocms 5.0.3 → 6.0.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.
Files changed (72) hide show
  1. package/README.md +4 -13
  2. package/dist/cjs/Image/index.js +39 -138
  3. package/dist/cjs/Image/index.js.map +1 -1
  4. package/dist/cjs/Image/utils.js +52 -0
  5. package/dist/cjs/Image/utils.js.map +1 -0
  6. package/dist/cjs/SRCImage/index.js +44 -0
  7. package/dist/cjs/SRCImage/index.js.map +1 -0
  8. package/dist/cjs/SRCImage/utils.js +82 -0
  9. package/dist/cjs/SRCImage/utils.js.map +1 -0
  10. package/dist/cjs/Seo/nextUtils.js +15 -15
  11. package/dist/cjs/Seo/nextUtils.js.map +1 -1
  12. package/dist/cjs/Seo/renderMetaTags.js +1 -1
  13. package/dist/cjs/Seo/renderMetaTags.js.map +1 -1
  14. package/dist/cjs/StructuredText/index.js.map +1 -1
  15. package/dist/cjs/VideoPlayer/index.js +1 -1
  16. package/dist/cjs/index.js +2 -1
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/useSiteSearch/index.js +9 -31
  19. package/dist/cjs/useSiteSearch/index.js.map +1 -1
  20. package/dist/cjs/useVideoPlayer/index.js.map +1 -1
  21. package/dist/esm/Image/index.js +31 -110
  22. package/dist/esm/Image/index.js.map +1 -1
  23. package/dist/esm/Image/utils.js +46 -0
  24. package/dist/esm/Image/utils.js.map +1 -0
  25. package/dist/esm/SRCImage/index.js +37 -0
  26. package/dist/esm/SRCImage/index.js.map +1 -0
  27. package/dist/esm/SRCImage/utils.js +52 -0
  28. package/dist/esm/SRCImage/utils.js.map +1 -0
  29. package/dist/esm/Seo/nextUtils.js +15 -15
  30. package/dist/esm/Seo/nextUtils.js.map +1 -1
  31. package/dist/esm/Seo/renderMetaTags.js +1 -1
  32. package/dist/esm/Seo/renderMetaTags.js.map +1 -1
  33. package/dist/esm/StructuredText/index.js.map +1 -1
  34. package/dist/esm/VideoPlayer/index.js +1 -1
  35. package/dist/esm/index.js +2 -1
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/useSiteSearch/index.js +2 -1
  38. package/dist/esm/useSiteSearch/index.js.map +1 -1
  39. package/dist/esm/useVideoPlayer/index.js.map +1 -1
  40. package/dist/types/Image/index.d.ts +3 -4
  41. package/dist/types/Image/utils.d.ts +7 -0
  42. package/dist/types/SRCImage/index.d.ts +33 -0
  43. package/dist/types/SRCImage/utils.d.ts +6 -0
  44. package/dist/types/Seo/remixUtils.d.ts +1 -1
  45. package/dist/types/Seo/renderMetaTags.d.ts +1 -1
  46. package/dist/types/Seo/renderMetaTagsToString.d.ts +1 -1
  47. package/dist/types/StructuredText/index.d.ts +3 -3
  48. package/dist/types/VideoPlayer/index.d.ts +1 -1
  49. package/dist/types/index.d.ts +2 -1
  50. package/dist/types/useQuerySubscription/index.d.ts +1 -1
  51. package/dist/types/useVideoPlayer/index.d.ts +2 -2
  52. package/package.json +3 -4
  53. package/src/Image/__tests__/__snapshots__/index.test.tsx.snap +387 -60
  54. package/src/Image/__tests__/index.test.tsx +55 -8
  55. package/src/Image/index.tsx +65 -177
  56. package/src/Image/utils.ts +58 -0
  57. package/src/SRCImage/__tests__/__snapshots__/index.test.tsx.snap +274 -0
  58. package/src/SRCImage/__tests__/index.test.tsx +91 -0
  59. package/src/SRCImage/index.tsx +99 -0
  60. package/src/SRCImage/utils.tsx +95 -0
  61. package/src/Seo/__tests__/index.test.tsx +1 -1
  62. package/src/Seo/nextUtils.ts +20 -20
  63. package/src/Seo/remixUtils.ts +1 -1
  64. package/src/Seo/renderMetaTags.tsx +2 -2
  65. package/src/Seo/renderMetaTagsToString.tsx +1 -1
  66. package/src/StructuredText/__tests__/index.test.tsx +2 -2
  67. package/src/StructuredText/index.tsx +10 -10
  68. package/src/VideoPlayer/index.tsx +2 -2
  69. package/src/index.ts +2 -1
  70. package/src/useQuerySubscription/index.ts +4 -4
  71. package/src/useSiteSearch/index.tsx +29 -28
  72. package/src/useVideoPlayer/index.ts +3 -6
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
- import { SeoOrFaviconTag, TitleMetaLinkTag } from './types.js';
2
+ import type { SeoOrFaviconTag, TitleMetaLinkTag } from './types.js';
3
3
 
4
4
  export function renderMetaTags(
5
5
  data: TitleMetaLinkTag[] | SeoOrFaviconTag[],
6
6
  ): JSX.Element[] {
7
7
  return data.map(({ tag, attributes, content }) => {
8
- let key: string[] = [tag];
8
+ const key: string[] = [tag];
9
9
 
10
10
  if (attributes && 'property' in attributes) {
11
11
  key.push(attributes.property);
@@ -1,4 +1,4 @@
1
- import { SeoOrFaviconTag, TitleMetaLinkTag } from './types.js';
1
+ import type { SeoOrFaviconTag, TitleMetaLinkTag } from './types.js';
2
2
 
3
3
  export function renderMetaTagsToString(
4
4
  data: TitleMetaLinkTag[] | SeoOrFaviconTag[],
@@ -5,8 +5,8 @@ import * as React from 'react';
5
5
  import {
6
6
  RenderError,
7
7
  StructuredText,
8
- StructuredTextDocument,
9
- StructuredTextGraphQlResponse,
8
+ type StructuredTextDocument,
9
+ type StructuredTextGraphQlResponse,
10
10
  renderNodeRule,
11
11
  } from '../index.js';
12
12
 
@@ -1,26 +1,26 @@
1
1
  import {
2
- RenderMarkRule,
3
- TransformMetaFn,
4
- TransformedMeta,
2
+ type RenderMarkRule,
3
+ type TransformMetaFn,
4
+ type TransformedMeta,
5
5
  defaultMetaTransformer,
6
6
  render,
7
7
  renderMarkRule,
8
8
  renderNodeRule,
9
9
  } from 'datocms-structured-text-generic-html-renderer';
10
10
  import {
11
- Document as StructuredTextDocument,
12
- Node,
13
- Record as StructuredTextGraphQlResponseRecord,
11
+ type Node,
14
12
  RenderError,
15
- RenderResult,
16
- RenderRule,
17
- StructuredText as StructuredTextGraphQlResponse,
13
+ type RenderResult,
14
+ type RenderRule,
15
+ type Document as StructuredTextDocument,
16
+ type StructuredText as StructuredTextGraphQlResponse,
17
+ type Record as StructuredTextGraphQlResponseRecord,
18
18
  isBlock,
19
19
  isInlineItem,
20
20
  isItemLink,
21
21
  isStructuredText,
22
22
  } from 'datocms-structured-text-utils';
23
- import React, { ReactElement, cloneElement, isValidElement } from 'react';
23
+ import React, { type ReactElement, cloneElement, isValidElement } from 'react';
24
24
 
25
25
  export { renderNodeRule, renderMarkRule, RenderError };
26
26
 
@@ -13,7 +13,7 @@ import React, { forwardRef } from 'react';
13
13
  // We use and extend Typescript types defined in the MUX player.
14
14
 
15
15
  import type MuxPlayerElement from '@mux/mux-player';
16
- import { type MuxPlayerProps } from '@mux/mux-player-react/.';
16
+ import type { MuxPlayerProps } from '@mux/mux-player-react';
17
17
 
18
18
  // React MUX player is made available in two flavours: eager and lazy loaded. We
19
19
  // choose to use the lazy version to avoid loading the web component uselessly.
@@ -72,7 +72,7 @@ export const VideoPlayer: (
72
72
  const {
73
73
  data = {},
74
74
  disableCookies = true,
75
- preload = "metadata",
75
+ preload = 'metadata',
76
76
  style: styleFromProps,
77
77
  ...rest
78
78
  } = props;
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export * from './Image/index.js';
2
+ export * from './SRCImage/index.js';
2
3
  export * from './Seo/index.js';
3
- export * from './VideoPlayer/index.js';
4
4
  export * from './StructuredText/index.js';
5
+ export * from './VideoPlayer/index.js';
5
6
 
6
7
  export * from './useQuerySubscription/index.js';
7
8
  export * from './useSiteSearch/index.js';
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import {
4
- ChannelErrorData,
5
- ConnectionStatus,
6
- Options,
7
- UnsubscribeFn,
4
+ type ChannelErrorData,
5
+ type ConnectionStatus,
6
+ type Options,
7
+ type UnsubscribeFn,
8
8
  subscribeToQuery,
9
9
  } from 'datocms-listen';
10
10
  import { useState } from 'react';
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
- import React, { useCallback, useEffect, useState } from 'react';
3
+ import React from 'react';
4
+ import { useCallback, useEffect, useState } from 'react';
4
5
  import reactStringReplace from 'react-string-replace';
5
6
 
6
7
  type SearchResultInstancesHrefSchema = {
@@ -243,32 +244,32 @@ export function useSiteSearch<Client extends GenericClient>(
243
244
  totalPages: 0,
244
245
  }
245
246
  : response
246
- ? {
247
- pageResults: response.data.map((rawSearchResult) => ({
248
- id: rawSearchResult.id,
249
- url: rawSearchResult.attributes.url,
250
- title: rawSearchResult.attributes.highlight.title ? (
251
- <MatchHighlighter highlighter={highlighter} context="title">
252
- {rawSearchResult.attributes.highlight.title[0]}
253
- </MatchHighlighter>
254
- ) : (
255
- rawSearchResult.attributes.title
256
- ),
257
- bodyExcerpt: rawSearchResult.attributes.highlight.body ? (
258
- <MatchHighlighter
259
- highlighter={highlighter}
260
- context="bodyExcerpt"
261
- >
262
- {rawSearchResult.attributes.highlight.body[0]}
263
- </MatchHighlighter>
264
- ) : (
265
- rawSearchResult.attributes.body_excerpt
266
- ),
267
- raw: rawSearchResult,
268
- })),
269
- totalResults: response.meta.total_count,
270
- totalPages: Math.ceil(response.meta.total_count / resultsPerPage),
271
- }
272
- : undefined,
247
+ ? {
248
+ pageResults: response.data.map((rawSearchResult) => ({
249
+ id: rawSearchResult.id,
250
+ url: rawSearchResult.attributes.url,
251
+ title: rawSearchResult.attributes.highlight.title ? (
252
+ <MatchHighlighter highlighter={highlighter} context="title">
253
+ {rawSearchResult.attributes.highlight.title[0]}
254
+ </MatchHighlighter>
255
+ ) : (
256
+ rawSearchResult.attributes.title
257
+ ),
258
+ bodyExcerpt: rawSearchResult.attributes.highlight.body ? (
259
+ <MatchHighlighter
260
+ highlighter={highlighter}
261
+ context="bodyExcerpt"
262
+ >
263
+ {rawSearchResult.attributes.highlight.body[0]}
264
+ </MatchHighlighter>
265
+ ) : (
266
+ rawSearchResult.attributes.body_excerpt
267
+ ),
268
+ raw: rawSearchResult,
269
+ })),
270
+ totalResults: response.meta.total_count,
271
+ totalPages: Math.ceil(response.meta.total_count / resultsPerPage),
272
+ }
273
+ : undefined,
273
274
  };
274
275
  }
@@ -1,6 +1,6 @@
1
- import { MuxPlayerProps } from '@mux/mux-player-react/.';
1
+ import type { MuxPlayerProps } from '@mux/mux-player-react/.';
2
2
 
3
- import { Video } from '../VideoPlayer';
3
+ import type { Video } from '../VideoPlayer';
4
4
 
5
5
  type Maybe<T> = T | null;
6
6
  type Possibly<T> = Maybe<T> | undefined;
@@ -18,10 +18,7 @@ const computedPlaybackId = (
18
18
  return { playbackId: `${muxPlaybackId || playbackId}` };
19
19
  };
20
20
 
21
- const computedStyle = (
22
- width: Possibly<number>,
23
- height: Possibly<number>,
24
- ) => {
21
+ const computedStyle = (width: Possibly<number>, height: Possibly<number>) => {
25
22
  if (!(width && height)) return undefined;
26
23
 
27
24
  return {