@prismicio/react 2.2.0 → 2.4.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.
- package/dist/index.cjs +90 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +181 -3
- package/dist/index.js +90 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/PrismicImage.tsx +185 -0
- package/src/PrismicLink.tsx +63 -25
- package/src/PrismicText.tsx +13 -0
- package/src/PrismicToolbar.tsx +13 -0
- package/src/index.ts +3 -0
- package/src/lib/devMsg.ts +20 -0
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> =
|
|
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
|
-
|
|
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
|
|
|
@@ -348,6 +367,165 @@ declare type PrismicRichTextProps<LinkResolverFunction extends prismicH.LinkReso
|
|
|
348
367
|
*/
|
|
349
368
|
declare const PrismicRichText: <LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction<string>>(props: PrismicRichTextProps<LinkResolverFunction>) => JSX.Element | null;
|
|
350
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>, "src" | "alt" | "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>, "src" | "alt" | "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>>;
|
|
528
|
+
|
|
351
529
|
declare type WordSeparators = "-" | "_" | " ";
|
|
352
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];
|
|
353
531
|
declare type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] ? FirstPart extends undefined ? "" : FirstPart extends "" ? InnerCamelCaseStringArray<RemainingParts, PreviousPart> : `${PreviousPart extends "" ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}` : "";
|
|
@@ -1106,4 +1284,4 @@ declare const Elements: {
|
|
|
1106
1284
|
readonly span: "span";
|
|
1107
1285
|
};
|
|
1108
1286
|
|
|
1109
|
-
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
|
@@ -58,6 +58,12 @@ const usePrismicClient = (explicitClient) => {
|
|
|
58
58
|
return client;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
var version = "2.4.1";
|
|
62
|
+
|
|
63
|
+
const devMsg = (slug) => {
|
|
64
|
+
return `https://prismic.dev/msg/react/v${version}/${slug}`;
|
|
65
|
+
};
|
|
66
|
+
|
|
61
67
|
const isInternalURL = (url) => {
|
|
62
68
|
const isInternal = /^(\/(?!\/)|#)/.test(url);
|
|
63
69
|
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
|
|
@@ -68,6 +74,21 @@ const defaultInternalComponent = "a";
|
|
|
68
74
|
const defaultExternalComponent = "a";
|
|
69
75
|
const _PrismicLink = (props, ref) => {
|
|
70
76
|
const context = usePrismicContext();
|
|
77
|
+
if (!__PRODUCTION__) {
|
|
78
|
+
if ("field" in props && props.field) {
|
|
79
|
+
if (!("link_type" in props.field) || !("url" in props.field || "id" in props.field)) {
|
|
80
|
+
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
81
|
+
`, props.field);
|
|
82
|
+
throw new Error(`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render. For more details, see ${devMsg("missing-link-properties")}`);
|
|
83
|
+
}
|
|
84
|
+
} else if ("document" in props && props.document) {
|
|
85
|
+
if (!("url" in props.document || "id" in props.document)) {
|
|
86
|
+
console.error(`[PrismicLink] This "document" prop value caused an error to be thrown.
|
|
87
|
+
`, props.document);
|
|
88
|
+
throw new Error(`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render. For more details, see ${devMsg("missing-link-properties")}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
71
92
|
const linkResolver = props.linkResolver || context.linkResolver;
|
|
72
93
|
let href;
|
|
73
94
|
if ("href" in props) {
|
|
@@ -77,11 +98,11 @@ const _PrismicLink = (props, ref) => {
|
|
|
77
98
|
} else if ("field" in props && props.field) {
|
|
78
99
|
href = prismicH.asLink(props.field, linkResolver);
|
|
79
100
|
}
|
|
80
|
-
const
|
|
101
|
+
const isInternal = href && isInternalURL(href);
|
|
102
|
+
const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || !isInternal && "_blank" || void 0;
|
|
81
103
|
const rel = props.rel || (target === "_blank" ? "noopener noreferrer" : void 0);
|
|
82
104
|
const InternalComponent = props.internalComponent || context.internalLinkComponent || defaultInternalComponent;
|
|
83
105
|
const ExternalComponent = props.externalComponent || context.externalLinkComponent || defaultExternalComponent;
|
|
84
|
-
const isInternal = href && isInternalURL(href);
|
|
85
106
|
const Component = isInternal ? InternalComponent : ExternalComponent;
|
|
86
107
|
const passthroughProps = Object.assign({}, props);
|
|
87
108
|
delete passthroughProps.linkResolver;
|
|
@@ -104,9 +125,17 @@ const _PrismicLink = (props, ref) => {
|
|
|
104
125
|
rel
|
|
105
126
|
}) : null;
|
|
106
127
|
};
|
|
128
|
+
if (!__PRODUCTION__) {
|
|
129
|
+
_PrismicLink.displayName = "PrismicLink";
|
|
130
|
+
}
|
|
107
131
|
const PrismicLink = React.forwardRef(_PrismicLink);
|
|
108
132
|
|
|
109
133
|
const PrismicText = (props) => {
|
|
134
|
+
if (!__PRODUCTION__) {
|
|
135
|
+
if (typeof props.field === "string") {
|
|
136
|
+
throw new Error(`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
110
139
|
return React.useMemo(() => {
|
|
111
140
|
if (prismicH.isFilled.richText(props.field)) {
|
|
112
141
|
const text = prismicH.asText(props.field, props.separator);
|
|
@@ -251,6 +280,61 @@ const PrismicRichText = (props) => {
|
|
|
251
280
|
]);
|
|
252
281
|
};
|
|
253
282
|
|
|
283
|
+
const _PrismicImage = (props, ref) => {
|
|
284
|
+
const {
|
|
285
|
+
field,
|
|
286
|
+
alt,
|
|
287
|
+
fallbackAlt,
|
|
288
|
+
imgixParams,
|
|
289
|
+
widths,
|
|
290
|
+
pixelDensities,
|
|
291
|
+
...restProps
|
|
292
|
+
} = props;
|
|
293
|
+
if (!__PRODUCTION__) {
|
|
294
|
+
if (typeof alt === "string" && props.alt !== "") {
|
|
295
|
+
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")}`);
|
|
296
|
+
}
|
|
297
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
298
|
+
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")}`);
|
|
299
|
+
}
|
|
300
|
+
if (widths && pixelDensities) {
|
|
301
|
+
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.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (prismicH.isFilled.imageThumbnail(field)) {
|
|
305
|
+
let src;
|
|
306
|
+
let srcSet;
|
|
307
|
+
if (widths || !pixelDensities) {
|
|
308
|
+
const res = prismicH.asImageWidthSrcSet(field, {
|
|
309
|
+
...imgixParams,
|
|
310
|
+
widths: widths === "defaults" ? void 0 : widths
|
|
311
|
+
});
|
|
312
|
+
src = res.src;
|
|
313
|
+
srcSet = res.srcset;
|
|
314
|
+
} else if (pixelDensities) {
|
|
315
|
+
const res = prismicH.asImagePixelDensitySrcSet(field, {
|
|
316
|
+
...imgixParams,
|
|
317
|
+
pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
|
|
318
|
+
});
|
|
319
|
+
src = res.src;
|
|
320
|
+
srcSet = res.srcset;
|
|
321
|
+
}
|
|
322
|
+
return /* @__PURE__ */ React.createElement("img", {
|
|
323
|
+
ref,
|
|
324
|
+
src,
|
|
325
|
+
srcSet,
|
|
326
|
+
alt: alt != null ? alt : field.alt || fallbackAlt,
|
|
327
|
+
...restProps
|
|
328
|
+
});
|
|
329
|
+
} else {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
if (!__PRODUCTION__) {
|
|
334
|
+
_PrismicImage.displayName = "PrismicImage";
|
|
335
|
+
}
|
|
336
|
+
const PrismicImage = React.forwardRef(_PrismicImage);
|
|
337
|
+
|
|
254
338
|
const pascalCase = (input) => {
|
|
255
339
|
const camelCased = input.replace(/(?:-|_)(\w)/g, (_, c) => {
|
|
256
340
|
return c ? c.toUpperCase() : "";
|
|
@@ -318,6 +402,9 @@ const PrismicToolbar = ({
|
|
|
318
402
|
script.dataset.prismicToolbar = "";
|
|
319
403
|
script.dataset.repositoryName = repositoryName;
|
|
320
404
|
script.dataset.type = type;
|
|
405
|
+
if (process.env.NODE_ENV === "test") {
|
|
406
|
+
script._evaluateScript = false;
|
|
407
|
+
}
|
|
321
408
|
document.body.appendChild(script);
|
|
322
409
|
}
|
|
323
410
|
}, [repositoryName, type, src]);
|
|
@@ -430,5 +517,5 @@ const useAllPrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMe
|
|
|
430
517
|
|
|
431
518
|
const Elements = Element;
|
|
432
519
|
|
|
433
|
-
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 };
|
|
520
|
+
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 };
|
|
434
521
|
//# sourceMappingURL=index.js.map
|