@pantheon-systems/p1-media 0.4.3 → 0.4.4

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.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactElement, ImgHTMLAttributes, ReactNode } from 'react';
2
+ import { ImgHTMLAttributes, ReactElement, ReactNode } from 'react';
3
3
  import { ComponentConfig } from '@puckeditor/core';
4
4
 
5
5
  /**
@@ -188,7 +188,7 @@ declare function getMediaProps(value: MediaFieldValue | null | undefined, option
188
188
  * (a broken foreign-origin image is never emitted). `alt` may be overridden;
189
189
  * otherwise it comes from the value.
190
190
  */
191
- declare function MediaImage({ image, mediaBaseUrl, transform, alt, ...rest }: {
191
+ declare function MediaImage({ image, mediaBaseUrl, transform, alt, loading, decoding, ...rest }: {
192
192
  image: MediaFieldValue | null | undefined;
193
193
  mediaBaseUrl?: string;
194
194
  transform?: ImageTransformParams;
@@ -198,17 +198,21 @@ declare function MediaImage({ image, mediaBaseUrl, transform, alt, ...rest }: {
198
198
  * ESCAPED text (React default escaping — never dangerouslySetInnerHTML, req.
199
199
  * R6). Renders nothing when the src is rejected/empty.
200
200
  */
201
- declare function MediaFigure({ image, schema, mediaBaseUrl, transform, className, captionClassName, }: {
201
+ declare function MediaFigure({ image, schema, mediaBaseUrl, transform, className, captionClassName, loading, decoding, }: {
202
202
  image: MediaFieldValue | null | undefined;
203
203
  schema?: MetadataFieldDef[];
204
204
  mediaBaseUrl?: string;
205
205
  transform?: ImageTransformParams;
206
206
  className?: string;
207
207
  captionClassName?: string;
208
+ /** Defaults to "lazy"; pass "eager" for an above-the-fold figure. */
209
+ loading?: ImgHTMLAttributes<HTMLImageElement>["loading"];
210
+ decoding?: ImgHTMLAttributes<HTMLImageElement>["decoding"];
208
211
  }): ReactElement | null;
209
212
 
210
213
  interface MediaFigureBlockProps {
211
214
  photo: MediaFieldValue | null;
215
+ loading?: "lazy" | "eager";
212
216
  }
213
217
  interface MediaFigureBlockOptions {
214
218
  /**
@@ -233,6 +237,12 @@ interface MediaFigureBlockOptions {
233
237
  captionClassName?: string;
234
238
  /** Rendered when no photo is chosen (or its URL fails origin validation). */
235
239
  placeholder?: ReactNode;
240
+ /**
241
+ * Default for the block's "Loading" field. "lazy" (the default) keeps
242
+ * off-screen images off the wire on image-heavy pages; use "eager" when the
243
+ * block is reliably above the fold.
244
+ */
245
+ defaultLoading?: "lazy" | "eager";
236
246
  }
237
247
  /**
238
248
  * Builds a registerable Puck component around the rich `p1-media` field and
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactElement, ImgHTMLAttributes, ReactNode } from 'react';
2
+ import { ImgHTMLAttributes, ReactElement, ReactNode } from 'react';
3
3
  import { ComponentConfig } from '@puckeditor/core';
4
4
 
5
5
  /**
@@ -188,7 +188,7 @@ declare function getMediaProps(value: MediaFieldValue | null | undefined, option
188
188
  * (a broken foreign-origin image is never emitted). `alt` may be overridden;
189
189
  * otherwise it comes from the value.
190
190
  */
191
- declare function MediaImage({ image, mediaBaseUrl, transform, alt, ...rest }: {
191
+ declare function MediaImage({ image, mediaBaseUrl, transform, alt, loading, decoding, ...rest }: {
192
192
  image: MediaFieldValue | null | undefined;
193
193
  mediaBaseUrl?: string;
194
194
  transform?: ImageTransformParams;
@@ -198,17 +198,21 @@ declare function MediaImage({ image, mediaBaseUrl, transform, alt, ...rest }: {
198
198
  * ESCAPED text (React default escaping — never dangerouslySetInnerHTML, req.
199
199
  * R6). Renders nothing when the src is rejected/empty.
200
200
  */
201
- declare function MediaFigure({ image, schema, mediaBaseUrl, transform, className, captionClassName, }: {
201
+ declare function MediaFigure({ image, schema, mediaBaseUrl, transform, className, captionClassName, loading, decoding, }: {
202
202
  image: MediaFieldValue | null | undefined;
203
203
  schema?: MetadataFieldDef[];
204
204
  mediaBaseUrl?: string;
205
205
  transform?: ImageTransformParams;
206
206
  className?: string;
207
207
  captionClassName?: string;
208
+ /** Defaults to "lazy"; pass "eager" for an above-the-fold figure. */
209
+ loading?: ImgHTMLAttributes<HTMLImageElement>["loading"];
210
+ decoding?: ImgHTMLAttributes<HTMLImageElement>["decoding"];
208
211
  }): ReactElement | null;
209
212
 
210
213
  interface MediaFigureBlockProps {
211
214
  photo: MediaFieldValue | null;
215
+ loading?: "lazy" | "eager";
212
216
  }
213
217
  interface MediaFigureBlockOptions {
214
218
  /**
@@ -233,6 +237,12 @@ interface MediaFigureBlockOptions {
233
237
  captionClassName?: string;
234
238
  /** Rendered when no photo is chosen (or its URL fails origin validation). */
235
239
  placeholder?: ReactNode;
240
+ /**
241
+ * Default for the block's "Loading" field. "lazy" (the default) keeps
242
+ * off-screen images off the wire on image-heavy pages; use "eager" when the
243
+ * block is reliably above the fold.
244
+ */
245
+ defaultLoading?: "lazy" | "eager";
236
246
  }
237
247
  /**
238
248
  * Builds a registerable Puck component around the rich `p1-media` field and
package/dist/index.js CHANGED
@@ -2815,6 +2815,8 @@ function MediaImage({
2815
2815
  mediaBaseUrl,
2816
2816
  transform,
2817
2817
  alt,
2818
+ loading = "lazy",
2819
+ decoding = "async",
2818
2820
  ...rest
2819
2821
  }) {
2820
2822
  const props = getMediaProps(image, { mediaBaseUrl, transform });
@@ -2824,6 +2826,8 @@ function MediaImage({
2824
2826
  {
2825
2827
  src: props.src,
2826
2828
  alt: alt ?? props.alt,
2829
+ loading,
2830
+ decoding,
2827
2831
  ...props.width !== void 0 ? { width: props.width } : {},
2828
2832
  ...props.height !== void 0 ? { height: props.height } : {},
2829
2833
  ...rest
@@ -2856,7 +2860,9 @@ function MediaFigure({
2856
2860
  mediaBaseUrl,
2857
2861
  transform,
2858
2862
  className,
2859
- captionClassName
2863
+ captionClassName,
2864
+ loading = "lazy",
2865
+ decoding = "async"
2860
2866
  }) {
2861
2867
  const props = getMediaProps(image, { mediaBaseUrl, transform });
2862
2868
  if (!props.src) return null;
@@ -2867,6 +2873,8 @@ function MediaFigure({
2867
2873
  {
2868
2874
  src: props.src,
2869
2875
  alt: props.alt,
2876
+ loading,
2877
+ decoding,
2870
2878
  ...props.width !== void 0 ? { width: props.width } : {},
2871
2879
  ...props.height !== void 0 ? { height: props.height } : {}
2872
2880
  }
@@ -2898,19 +2906,29 @@ function createMediaFigureBlock(options) {
2898
2906
  schema,
2899
2907
  className,
2900
2908
  captionClassName,
2901
- placeholder = "Choose a photo from the media library"
2909
+ placeholder = "Choose a photo from the media library",
2910
+ defaultLoading = "lazy"
2902
2911
  } = options;
2903
2912
  return {
2904
2913
  label,
2905
2914
  fields: {
2906
2915
  // `p1-media` is registered by createMediaPlugin via overrides.fieldTypes,
2907
2916
  // so it is not part of Puck's built-in Field union.
2908
- photo: { type: "p1-media", label: fieldLabel }
2917
+ photo: { type: "p1-media", label: fieldLabel },
2918
+ loading: {
2919
+ type: "radio",
2920
+ label: "Loading",
2921
+ options: [
2922
+ { label: "Lazy", value: "lazy" },
2923
+ { label: "Eager", value: "eager" }
2924
+ ]
2925
+ }
2909
2926
  },
2910
2927
  defaultProps: {
2911
- photo: null
2928
+ photo: null,
2929
+ loading: defaultLoading
2912
2930
  },
2913
- render: ({ photo }) => {
2931
+ render: ({ photo, loading }) => {
2914
2932
  const { src } = getMediaProps(photo ?? null, { mediaBaseUrl });
2915
2933
  if (!src) {
2916
2934
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { style: placeholderStyle, children: placeholder });
@@ -2923,7 +2941,8 @@ function createMediaFigureBlock(options) {
2923
2941
  transform,
2924
2942
  schema,
2925
2943
  className,
2926
- captionClassName
2944
+ captionClassName,
2945
+ loading: loading === "eager" ? "eager" : "lazy"
2927
2946
  }
2928
2947
  );
2929
2948
  }