@prismicio/react 2.1.2 → 2.4.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/dist/index.d.ts CHANGED
@@ -31,7 +31,7 @@ interface LinkProps {
31
31
  /**
32
32
  * Props for `<PrismicLink>`.
33
33
  */
34
- declare type PrismicLinkProps<InternalComponent extends React.ElementType<LinkProps> = React.ElementType<LinkProps>, ExternalComponent extends React.ElementType<LinkProps> = React.ElementType<LinkProps>, LinkResolverFunction extends prismicH.LinkResolverFunction = prismicH.LinkResolverFunction> = Omit<React.ComponentPropsWithoutRef<InternalComponent> & React.ComponentPropsWithoutRef<ExternalComponent>, keyof LinkProps> & {
34
+ declare type PrismicLinkProps<InternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent, ExternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent, LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction> = Omit<React.ComponentPropsWithoutRef<InternalComponent> & React.ComponentPropsWithoutRef<ExternalComponent>, keyof LinkProps> & {
35
35
  /**
36
36
  * The Link Resolver used to resolve links.
37
37
  *
@@ -84,7 +84,26 @@ declare type PrismicLinkProps<InternalComponent extends React.ElementType<LinkPr
84
84
  */
85
85
  href: string | null | undefined;
86
86
  });
87
- declare const PrismicLink: <InternalComponent extends React.ElementType<LinkProps>, ExternalComponent extends React.ElementType<LinkProps>, LinkResolverFunction extends prismicH.LinkResolverFunction<string>>(props: PrismicLinkProps<InternalComponent, ExternalComponent, LinkResolverFunction> & {
87
+ /**
88
+ * The default component rendered for internal URLs.
89
+ */
90
+ declare const defaultInternalComponent = "a";
91
+ /**
92
+ * React component that renders a link from a Prismic Link field.
93
+ *
94
+ * Different components can be rendered depending on whether the link is
95
+ * internal or external. This is helpful when integrating with client-side
96
+ * routers, such as a router-specific Link component.
97
+ *
98
+ * If a link is configured to open in a new window using `target="_blank"`,
99
+ * `rel="noopener noreferrer"` is set by default.
100
+ *
101
+ * @param props - Props for the component.
102
+ *
103
+ * @returns The internal or external link component depending on whether the
104
+ * link is internal or external.
105
+ */
106
+ declare const PrismicLink: <InternalComponent extends React.ElementType<LinkProps> = "a", ExternalComponent extends React.ElementType<LinkProps> = "a", LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction<string>>(props: PrismicLinkProps<InternalComponent, ExternalComponent, LinkResolverFunction> & {
88
107
  ref?: React.Ref<Element> | undefined;
89
108
  }) => JSX.Element | null;
90
109
 
@@ -111,7 +130,7 @@ declare type PrismicClientHookState = "idle" | "loading" | "loaded" | "failed";
111
130
  * React context value containing shared configuration for `@prismicio/react`
112
131
  * components and hooks.
113
132
  */
114
- declare type PrismicContextValue = {
133
+ declare type PrismicContextValue<LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction> = {
115
134
  /**
116
135
  * A `@prismicio/client` instance used to fetch content from a Prismic
117
136
  * repository. This is used by `@prismicio/react` hooks, such as
@@ -126,7 +145,7 @@ declare type PrismicContextValue = {
126
145
  * repository's content, a Link Resolver does not need to be provided.
127
146
  * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
128
147
  */
129
- linkResolver?: prismicH.LinkResolverFunction;
148
+ linkResolver?: LinkResolverFunction;
130
149
  /**
131
150
  * A map or function that maps a Rich Text block to a React component.
132
151
  *
@@ -170,14 +189,14 @@ declare type PrismicContextValue = {
170
189
  /**
171
190
  * Props for `<PrismicProvider>`.
172
191
  */
173
- declare type PrismicProviderProps = PrismicContextValue;
192
+ declare type PrismicProviderProps<LinkResolverFunction extends prismicH.LinkResolverFunction> = PrismicContextValue<LinkResolverFunction>;
174
193
  /**
175
194
  * React context provider to share configuration for `@prismicio/react`
176
195
  * components and hooks.
177
196
  *
178
197
  * @returns A React context provider with shared configuration.
179
198
  */
180
- declare const PrismicProvider: ({ client, linkResolver, richTextComponents, internalLinkComponent, externalLinkComponent, children, }: PrismicProviderProps) => JSX.Element;
199
+ declare const PrismicProvider: <LinkResolverFunction extends prismicH.LinkResolverFunction<any>>({ client, linkResolver, richTextComponents, internalLinkComponent, externalLinkComponent, children, }: PrismicProviderProps<LinkResolverFunction>) => JSX.Element;
181
200
 
182
201
  /**
183
202
  * React hook used to read shared configuration for `@prismicio/react`
@@ -239,7 +258,7 @@ declare const PrismicText: (props: PrismicTextProps) => JSX.Element | null;
239
258
  /**
240
259
  * Props for `<PrismicRichText>`.
241
260
  */
242
- declare type PrismicRichTextProps = {
261
+ declare type PrismicRichTextProps<LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction> = {
243
262
  /**
244
263
  * The Prismic Rich Text field to render.
245
264
  */
@@ -252,7 +271,7 @@ declare type PrismicRichTextProps = {
252
271
  * repository's content, a Link Resolver does not need to be provided.
253
272
  * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
254
273
  */
255
- linkResolver?: PrismicLinkProps["linkResolver"];
274
+ linkResolver?: LinkResolverFunction;
256
275
  /**
257
276
  * A function that maps a Rich Text block to a React component.
258
277
  *
@@ -300,6 +319,11 @@ declare type PrismicRichTextProps = {
300
319
  * @defaultValue `<a>`
301
320
  */
302
321
  externalLinkComponent?: PrismicLinkProps["externalComponent"];
322
+ /**
323
+ * The value to be rendered when the field is empty. If a fallback is not
324
+ * given, `null` will be rendered.
325
+ */
326
+ fallback?: React.ReactNode;
303
327
  };
304
328
  /**
305
329
  * React component that renders content from a Prismic Rich Text field. By
@@ -341,7 +365,166 @@ declare type PrismicRichTextProps = {
341
365
  * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
342
366
  * @see Learn about Rich Text serializers {@link https://prismic.io/docs/core-concepts/html-serializer}
343
367
  */
344
- declare const PrismicRichText: (props: PrismicRichTextProps) => JSX.Element | null;
368
+ declare const PrismicRichText: <LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction<string>>(props: PrismicRichTextProps<LinkResolverFunction>) => JSX.Element | null;
369
+
370
+ /**
371
+ * Props for `<PrismicImage>`.
372
+ */
373
+ declare type PrismicImageProps = Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcset" | "alt"> & {
374
+ /**
375
+ * The Prismic Image field or thumbnail to render.
376
+ */
377
+ field: prismicT.ImageFieldImage | null | undefined;
378
+ /**
379
+ * An object of Imgix URL API parameters to transform the image.
380
+ *
381
+ * See: https://docs.imgix.com/apis/rendering
382
+ */
383
+ imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
384
+ /**
385
+ * Declare an image as decorative by providing `alt=""`.
386
+ *
387
+ * See:
388
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
389
+ */
390
+ alt?: "";
391
+ /**
392
+ * Declare an image as decorative only if the Image field does not have
393
+ * alternative text by providing `fallbackAlt=""`.
394
+ *
395
+ * See:
396
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
397
+ */
398
+ fallbackAlt?: "";
399
+ } & ({
400
+ /**
401
+ * Widths used to build a `srcset` value for the Image field.
402
+ *
403
+ * If a `widths` prop is not given or `"defaults"` is passed, the
404
+ * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
405
+ *
406
+ * If the Image field contains responsive views, each responsive view
407
+ * can be used as a width in the resulting `srcset` by passing
408
+ * `"thumbnails"` as the `widths` prop.
409
+ */
410
+ widths?: NonNullable<Parameters<typeof prismicH.asImageWidthSrcSet>[1]>["widths"] | "defaults";
411
+ /**
412
+ * Not used when the `widths` prop is used.
413
+ */
414
+ pixelDensities?: never;
415
+ } | {
416
+ /**
417
+ * Not used when the `widths` prop is used.
418
+ */
419
+ widths?: never;
420
+ /**
421
+ * Pixel densities used to build a `srcset` value for the Image field.
422
+ *
423
+ * If a `pixelDensities` prop is passed `"defaults"`, the following
424
+ * pixel densities will be used: 1, 2, 3.
425
+ */
426
+ pixelDensities: NonNullable<Parameters<typeof prismicH.asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
427
+ });
428
+ /**
429
+ * React component that renders an image from a Prismic Image field or one of
430
+ * its thumbnails. It will automatically set the `alt` attribute using the Image
431
+ * field's `alt` property.
432
+ *
433
+ * By default, a widths-based srcset will be used to support responsive images.
434
+ * This ensures only the smallest image needed for a browser is downloaded.
435
+ *
436
+ * To use a pixel-density-based srcset, use the `pixelDensities` prop. Default
437
+ * pixel densities can be used by using `pixelDensities="defaults"`.
438
+ *
439
+ * **Note**: If you are using a framework that has a native image component,
440
+ * such as Next.js and Gatsby, prefer using those image components instead. They
441
+ * can provide deeper framework integration than `<PrismicImage>`.
442
+ *
443
+ * @param props - Props for the component.
444
+ *
445
+ * @returns A responsive image component for the given Image field.
446
+ */
447
+ declare const PrismicImage: React.ForwardRefExoticComponent<(Pick<Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "alt" | "src" | "srcset"> & {
448
+ /**
449
+ * The Prismic Image field or thumbnail to render.
450
+ */
451
+ field: prismicT.ImageFieldImage | null | undefined;
452
+ /**
453
+ * An object of Imgix URL API parameters to transform the image.
454
+ *
455
+ * See: https://docs.imgix.com/apis/rendering
456
+ */
457
+ imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
458
+ /**
459
+ * Declare an image as decorative by providing `alt=""`.
460
+ *
461
+ * See:
462
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
463
+ */
464
+ alt?: "" | undefined;
465
+ /**
466
+ * Declare an image as decorative only if the Image field does not have
467
+ * alternative text by providing `fallbackAlt=""`.
468
+ *
469
+ * See:
470
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
471
+ */
472
+ fallbackAlt?: "" | undefined;
473
+ } & {
474
+ /**
475
+ * Widths used to build a `srcset` value for the Image field.
476
+ *
477
+ * If a `widths` prop is not given or `"defaults"` is passed, the
478
+ * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
479
+ *
480
+ * If the Image field contains responsive views, each responsive view
481
+ * can be used as a width in the resulting `srcset` by passing
482
+ * `"thumbnails"` as the `widths` prop.
483
+ */
484
+ widths?: NonNullable<Parameters<typeof prismicH.asImageWidthSrcSet>[1]>["widths"] | "defaults";
485
+ /**
486
+ * Not used when the `widths` prop is used.
487
+ */
488
+ pixelDensities?: undefined;
489
+ }, "children" | "slot" | "style" | "title" | "className" | "color" | "height" | "id" | "lang" | "width" | "role" | "tabIndex" | "crossOrigin" | "widths" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "useMap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "translate" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "referrerPolicy" | "alt" | "loading" | "decoding" | "sizes" | "srcSet" | "field" | "pixelDensities" | "imgixParams" | "fallbackAlt"> | Pick<Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "alt" | "src" | "srcset"> & {
490
+ /**
491
+ * The Prismic Image field or thumbnail to render.
492
+ */
493
+ field: prismicT.ImageFieldImage | null | undefined;
494
+ /**
495
+ * An object of Imgix URL API parameters to transform the image.
496
+ *
497
+ * See: https://docs.imgix.com/apis/rendering
498
+ */
499
+ imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
500
+ /**
501
+ * Declare an image as decorative by providing `alt=""`.
502
+ *
503
+ * See:
504
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
505
+ */
506
+ alt?: "" | undefined;
507
+ /**
508
+ * Declare an image as decorative only if the Image field does not have
509
+ * alternative text by providing `fallbackAlt=""`.
510
+ *
511
+ * See:
512
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
513
+ */
514
+ fallbackAlt?: "" | undefined;
515
+ } & {
516
+ /**
517
+ * Not used when the `widths` prop is used.
518
+ */
519
+ widths?: undefined;
520
+ /**
521
+ * Pixel densities used to build a `srcset` value for the Image field.
522
+ *
523
+ * If a `pixelDensities` prop is passed `"defaults"`, the following
524
+ * pixel densities will be used: 1, 2, 3.
525
+ */
526
+ pixelDensities: NonNullable<Parameters<typeof prismicH.asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
527
+ }, "children" | "slot" | "style" | "title" | "className" | "color" | "height" | "id" | "lang" | "width" | "role" | "tabIndex" | "crossOrigin" | "widths" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "useMap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "translate" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "referrerPolicy" | "alt" | "loading" | "decoding" | "sizes" | "srcSet" | "field" | "pixelDensities" | "imgixParams" | "fallbackAlt">) & React.RefAttributes<HTMLImageElement>>;
345
528
 
346
529
  declare type WordSeparators = "-" | "_" | " ";
347
530
  declare type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : S extends Delimiter ? [] : [S];
@@ -361,20 +544,47 @@ declare type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K exte
361
544
  */
362
545
  declare type PascalCase<Value> = CamelCase<Value> extends string ? Capitalize<CamelCase<Value>> : CamelCase<Value>;
363
546
 
547
+ /**
548
+ * Returns the type of a `SliceLike` type.
549
+ *
550
+ * @typeParam Slice - The Slice from which the type will be extracted.
551
+ */
552
+ declare type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ? Slice["slice_type"] : Slice extends SliceLikeGraphQL ? Slice["type"] : never;
553
+ /**
554
+ * The minimum required properties to represent a Prismic Slice from the Prismic
555
+ * Rest API V2 for the `<SliceZone>` component.
556
+ *
557
+ * If using Prismic's Rest API V2, use the `Slice` export from
558
+ * `@prismicio/types` for a full interface.
559
+ *
560
+ * @typeParam SliceType - Type name of the Slice.
561
+ */
562
+ declare type SliceLikeRestV2<SliceType extends string = string> = {
563
+ slice_type: prismicT.Slice<SliceType>["slice_type"];
564
+ };
565
+ /**
566
+ * The minimum required properties to represent a Prismic Slice from the Prismic
567
+ * GraphQL API for the `<SliceZone>` component.
568
+ *
569
+ * @typeParam SliceType - Type name of the Slice.
570
+ */
571
+ declare type SliceLikeGraphQL<SliceType extends string = string> = {
572
+ type: prismicT.Slice<SliceType>["slice_type"];
573
+ };
364
574
  /**
365
575
  * The minimum required properties to represent a Prismic Slice for the
366
576
  * `<SliceZone>` component.
367
577
  *
368
- * If using Prismic's REST API, use the `Slice` export from `@prismicio/types`
369
- * for a full interface.
578
+ * If using Prismic's Rest API V2, use the `Slice` export from
579
+ * `@prismicio/types` for a full interface.
370
580
  *
371
581
  * @typeParam SliceType - Type name of the Slice.
372
582
  */
373
- declare type SliceLike<SliceType extends string = string> = Pick<prismicT.Slice<SliceType>, "slice_type">;
583
+ declare type SliceLike<SliceType extends string = string> = SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>;
374
584
  /**
375
585
  * A looser version of the `SliceZone` type from `@prismicio/types` using `SliceLike`.
376
586
  *
377
- * If using Prismic's REST API, use the `SliceZone` export from
587
+ * If using Prismic's Rest API V2, use the `SliceZone` export from
378
588
  * `@prismicio/types` for the full type.
379
589
  *
380
590
  * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
@@ -421,7 +631,7 @@ declare type SliceComponentType<TSlice extends SliceLike = SliceLike, TContext =
421
631
  * @typeParam TContext - Arbitrary data made available to all Slice components.
422
632
  */
423
633
  declare type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
424
- [SliceType in keyof Record<TSlice["slice_type"], never>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
634
+ [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
425
635
  };
426
636
  /**
427
637
  * This Slice component can be used as a reminder to provide a proper implementation.
@@ -441,7 +651,7 @@ declare type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
441
651
  /**
442
652
  * The name of the Slice.
443
653
  */
444
- sliceName: PascalCase<TSlice["slice_type"]>;
654
+ sliceName: PascalCase<ExtractSliceType<TSlice>>;
445
655
  /**
446
656
  * The index of the Slice in the Slice Zone.
447
657
  */
@@ -1074,4 +1284,4 @@ declare const Elements: {
1074
1284
  readonly span: "span";
1075
1285
  };
1076
1286
 
1077
- export { Elements, JSXFunctionSerializer, JSXMapSerializer, LinkProps, PrismicClientHookState, PrismicContextValue, PrismicLink, PrismicLinkProps, PrismicProvider, PrismicProviderProps, PrismicRichText, PrismicRichTextProps, PrismicText, PrismicTextProps, PrismicToolbar, PrismicToolbarProps, SliceComponentProps, SliceComponentType, SliceLike, SliceZone, SliceZoneComponents, SliceZoneLike, SliceZoneProps, SliceZoneResolver, TODOSliceComponent, UsePrismicPreviewResolverArgs, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicClient, usePrismicContext, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, usePrismicPreviewResolver, useSinglePrismicDocument };
1287
+ export { Elements, JSXFunctionSerializer, JSXMapSerializer, LinkProps, PrismicClientHookState, PrismicContextValue, PrismicImage, PrismicImageProps, PrismicLink, PrismicLinkProps, PrismicProvider, PrismicProviderProps, PrismicRichText, PrismicRichTextProps, PrismicText, PrismicTextProps, PrismicToolbar, PrismicToolbarProps, SliceComponentProps, SliceComponentType, SliceLike, SliceZone, SliceZoneComponents, SliceZoneLike, SliceZoneProps, SliceZoneResolver, TODOSliceComponent, UsePrismicPreviewResolverArgs, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicClient, usePrismicContext, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, usePrismicPreviewResolver, useSinglePrismicDocument };
package/dist/index.js CHANGED
@@ -77,11 +77,11 @@ const _PrismicLink = (props, ref) => {
77
77
  } else if ("field" in props && props.field) {
78
78
  href = prismicH.asLink(props.field, linkResolver);
79
79
  }
80
- const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || void 0;
80
+ const isInternal = href && isInternalURL(href);
81
+ const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || !isInternal && "_blank" || void 0;
81
82
  const rel = props.rel || (target === "_blank" ? "noopener noreferrer" : void 0);
82
83
  const InternalComponent = props.internalComponent || context.internalLinkComponent || defaultInternalComponent;
83
84
  const ExternalComponent = props.externalComponent || context.externalLinkComponent || defaultExternalComponent;
84
- const isInternal = href && isInternalURL(href);
85
85
  const Component = isInternal ? InternalComponent : ExternalComponent;
86
86
  const passthroughProps = Object.assign({}, props);
87
87
  delete passthroughProps.linkResolver;
@@ -104,6 +104,9 @@ const _PrismicLink = (props, ref) => {
104
104
  rel
105
105
  }) : null;
106
106
  };
107
+ if (!__PRODUCTION__) {
108
+ _PrismicLink.displayName = "PrismicLink";
109
+ }
107
110
  const PrismicLink = React.forwardRef(_PrismicLink);
108
111
 
109
112
  const PrismicText = (props) => {
@@ -237,7 +240,7 @@ const PrismicRichText = (props) => {
237
240
  });
238
241
  return /* @__PURE__ */ React.createElement(React.Fragment, null, serialized);
239
242
  } else {
240
- return null;
243
+ return props.fallback != null ? /* @__PURE__ */ React.createElement(React.Fragment, null, props.fallback) : null;
241
244
  }
242
245
  }, [
243
246
  props.field,
@@ -245,11 +248,73 @@ const PrismicRichText = (props) => {
245
248
  props.externalLinkComponent,
246
249
  props.components,
247
250
  props.linkResolver,
251
+ props.fallback,
248
252
  context.linkResolver,
249
253
  context.richTextComponents
250
254
  ]);
251
255
  };
252
256
 
257
+ var version = "2.4.0";
258
+
259
+ const devMsg = (slug) => {
260
+ return `https://prismic.dev/msg/react/v${version}/${slug}`;
261
+ };
262
+
263
+ const _PrismicImage = (props, ref) => {
264
+ const {
265
+ field,
266
+ alt,
267
+ fallbackAlt,
268
+ imgixParams,
269
+ widths,
270
+ pixelDensities,
271
+ ...restProps
272
+ } = props;
273
+ if (!__PRODUCTION__) {
274
+ if (typeof alt === "string" && props.alt !== "") {
275
+ console.warn(`[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
276
+ }
277
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
278
+ console.warn(`[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
279
+ }
280
+ if (widths && pixelDensities) {
281
+ console.warn(`[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`);
282
+ }
283
+ }
284
+ if (prismicH.isFilled.imageThumbnail(field)) {
285
+ let src;
286
+ let srcSet;
287
+ if (widths || !pixelDensities) {
288
+ const res = prismicH.asImageWidthSrcSet(field, {
289
+ ...imgixParams,
290
+ widths: widths === "defaults" ? void 0 : widths
291
+ });
292
+ src = res.src;
293
+ srcSet = res.srcset;
294
+ } else if (pixelDensities) {
295
+ const res = prismicH.asImagePixelDensitySrcSet(field, {
296
+ ...imgixParams,
297
+ pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
298
+ });
299
+ src = res.src;
300
+ srcSet = res.srcset;
301
+ }
302
+ return /* @__PURE__ */ React.createElement("img", {
303
+ ref,
304
+ src,
305
+ srcSet,
306
+ alt: alt != null ? alt : field.alt || fallbackAlt,
307
+ ...restProps
308
+ });
309
+ } else {
310
+ return null;
311
+ }
312
+ };
313
+ if (!__PRODUCTION__) {
314
+ _PrismicImage.displayName = "PrismicImage";
315
+ }
316
+ const PrismicImage = React.forwardRef(_PrismicImage);
317
+
253
318
  const pascalCase = (input) => {
254
319
  const camelCased = input.replace(/(?:-|_)(\w)/g, (_, c) => {
255
320
  return c ? c.toUpperCase() : "";
@@ -260,13 +325,14 @@ const pascalCase = (input) => {
260
325
  const TODOSliceComponent = __PRODUCTION__ ? () => null : ({
261
326
  slice
262
327
  }) => {
328
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
263
329
  React.useEffect(() => {
264
- console.warn(`[SliceZone] Could not find a component for Slice type "${slice.slice_type}"`, slice);
265
- }, [slice]);
330
+ console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
331
+ }, [slice, type]);
266
332
  return /* @__PURE__ */ React.createElement("section", {
267
333
  "data-slice-zone-todo-component": "",
268
- "data-slice-type": slice.slice_type
269
- }, "Could not find a component for Slice type \u201C", slice.slice_type, "\u201D");
334
+ "data-slice-type": type
335
+ }, "Could not find a component for Slice type \u201C", type, "\u201D");
270
336
  };
271
337
  const SliceZone = ({
272
338
  slices = [],
@@ -277,11 +343,12 @@ const SliceZone = ({
277
343
  }) => {
278
344
  const renderedSlices = React.useMemo(() => {
279
345
  return slices.map((slice, index) => {
280
- let Comp = components[slice.slice_type] || defaultComponent;
346
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
347
+ let Comp = components[type] || defaultComponent;
281
348
  if (resolver) {
282
349
  const resolvedComp = resolver({
283
350
  slice,
284
- sliceName: pascalCase(slice.slice_type),
351
+ sliceName: pascalCase(type),
285
352
  i: index
286
353
  });
287
354
  if (resolvedComp) {
@@ -315,6 +382,9 @@ const PrismicToolbar = ({
315
382
  script.dataset.prismicToolbar = "";
316
383
  script.dataset.repositoryName = repositoryName;
317
384
  script.dataset.type = type;
385
+ if (process.env.NODE_ENV === "test") {
386
+ script._evaluateScript = false;
387
+ }
318
388
  document.body.appendChild(script);
319
389
  }
320
390
  }, [repositoryName, type, src]);
@@ -427,5 +497,5 @@ const useAllPrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMe
427
497
 
428
498
  const Elements = Element;
429
499
 
430
- export { Elements, PrismicLink, PrismicProvider, PrismicRichText, PrismicText, PrismicToolbar, SliceZone, TODOSliceComponent, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicClient, usePrismicContext, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, usePrismicPreviewResolver, useSinglePrismicDocument };
500
+ export { Elements, PrismicImage, PrismicLink, PrismicProvider, PrismicRichText, PrismicText, PrismicToolbar, SliceZone, TODOSliceComponent, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicClient, usePrismicContext, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, usePrismicPreviewResolver, useSinglePrismicDocument };
431
501
  //# sourceMappingURL=index.js.map