@slopmachine/react 0.6.0 → 0.7.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/CHANGELOG.md +19 -0
- package/dist/index.d.mts +34 -6
- package/dist/index.d.ts +34 -6
- package/dist/index.js +185 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +197 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/ErrorOverlay.tsx +91 -0
- package/src/components/SlopImage.tsx +54 -31
- package/src/components/SlopText.tsx +1 -1
- package/src/components/SlopVideo.tsx +52 -29
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @slopmachine/react
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2644625: Add error states to `SlopImage` and `SlopVideo` (React and Svelte).
|
|
8
|
+
|
|
9
|
+
- When generation or loading fails, the media slot now shows a default error message instead of a broken image or empty video, keeping the layout intact. The failed element is hidden from assistive technology.
|
|
10
|
+
- New `errorFallback` prop (React: node or `(error) => node`; Svelte: snippet receiving `{ error }`) to customise the error UI.
|
|
11
|
+
- New `onGenerationError(error)` callback, called once per URL.
|
|
12
|
+
- Errors are `SlopMachineError` instances (exported from all three packages) carrying the API's error message and HTTP `status` when the API rejected the request.
|
|
13
|
+
- Fixed: a stale URL check could affect the loading state after props changed (React had no request cancellation). Network/CORS failures of the HEAD check no longer end the loading state early; the media element's own load/error events decide.
|
|
14
|
+
- Svelte components no longer render an empty `src` attribute before the URL is ready.
|
|
15
|
+
- Core: new `SlopMachineError`, `checkRenderUrl()` and `createRenderUrlMonitor()` exports.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [2644625]
|
|
20
|
+
- @slopmachine/core@0.7.0
|
|
21
|
+
|
|
3
22
|
## 0.6.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SlopImageOptions, ImageAspectRatio, SlopVideoOptions, VideoAspectRatio, SlopTextOptions } from '@slopmachine/core';
|
|
3
|
-
export { ImageAspectRatio, RateResultOptions, RateResultResponse, ResultRating, SlopImageOptions, SlopTextOptions, SlopVideoOptions, VideoAspectRatio, preloadImage, preloadText, preloadVideo, rateResult } from '@slopmachine/core';
|
|
2
|
+
import { SlopMachineError, SlopImageOptions, ImageAspectRatio, SlopVideoOptions, VideoAspectRatio, SlopTextOptions } from '@slopmachine/core';
|
|
3
|
+
export { ImageAspectRatio, RateResultOptions, RateResultResponse, ResultRating, SlopImageOptions, SlopMachineError, SlopTextOptions, SlopVideoOptions, VideoAspectRatio, preloadImage, preloadText, preloadVideo, rateResult } from '@slopmachine/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Content to render when generation or loading fails. Either a node, or a
|
|
7
|
+
* function that receives the error and returns a node.
|
|
8
|
+
*/
|
|
9
|
+
type SlopErrorFallback = React.ReactNode | ((error: SlopMachineError) => React.ReactNode);
|
|
4
10
|
|
|
5
11
|
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">, Omit<SlopImageOptions, "aspectRatio"> {
|
|
6
12
|
/**
|
|
@@ -12,6 +18,17 @@ interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>,
|
|
|
12
18
|
* If not provided, a default spinner and shimmer effect will be shown.
|
|
13
19
|
*/
|
|
14
20
|
loader?: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Content to display if the image fails to generate or load.
|
|
23
|
+
* Pass a node, or a function that receives the `SlopMachineError` and returns a node.
|
|
24
|
+
* If not provided, a default error message is shown in place of the image.
|
|
25
|
+
*/
|
|
26
|
+
errorFallback?: SlopErrorFallback;
|
|
27
|
+
/**
|
|
28
|
+
* Called once per URL when the image fails to generate or load.
|
|
29
|
+
* `error.status` holds the HTTP status when the API reported the failure.
|
|
30
|
+
*/
|
|
31
|
+
onGenerationError?: (error: SlopMachineError) => void;
|
|
15
32
|
/**
|
|
16
33
|
* How the image should be resized to fit its container. Defaults to "cover".
|
|
17
34
|
*/
|
|
@@ -47,7 +64,7 @@ interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>,
|
|
|
47
64
|
* />
|
|
48
65
|
* ```
|
|
49
66
|
*
|
|
50
|
-
* @version 0.
|
|
67
|
+
* @version 0.7.0
|
|
51
68
|
*/
|
|
52
69
|
declare const SlopImage: React.FC<SlopImageProps>;
|
|
53
70
|
|
|
@@ -61,6 +78,17 @@ interface SlopVideoProps extends Omit<React.VideoHTMLAttributes<HTMLVideoElement
|
|
|
61
78
|
* If not provided, a default spinner and shimmer effect will be shown.
|
|
62
79
|
*/
|
|
63
80
|
loader?: React.ReactNode;
|
|
81
|
+
/**
|
|
82
|
+
* Content to display if the video fails to generate or load.
|
|
83
|
+
* Pass a node, or a function that receives the `SlopMachineError` and returns a node.
|
|
84
|
+
* If not provided, a default error message is shown in place of the video.
|
|
85
|
+
*/
|
|
86
|
+
errorFallback?: SlopErrorFallback;
|
|
87
|
+
/**
|
|
88
|
+
* Called once per URL when the video fails to generate or load.
|
|
89
|
+
* `error.status` holds the HTTP status when the API reported the failure.
|
|
90
|
+
*/
|
|
91
|
+
onGenerationError?: (error: SlopMachineError) => void;
|
|
64
92
|
}
|
|
65
93
|
/**
|
|
66
94
|
* Renders a video generated by Slop Machine.
|
|
@@ -90,7 +118,7 @@ interface SlopVideoProps extends Omit<React.VideoHTMLAttributes<HTMLVideoElement
|
|
|
90
118
|
* />
|
|
91
119
|
* ```
|
|
92
120
|
*
|
|
93
|
-
* @version 0.
|
|
121
|
+
* @version 0.7.0
|
|
94
122
|
*/
|
|
95
123
|
declare const SlopVideo: React.FC<SlopVideoProps>;
|
|
96
124
|
|
|
@@ -128,8 +156,8 @@ interface SlopTextProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "chil
|
|
|
128
156
|
* />
|
|
129
157
|
* ```
|
|
130
158
|
*
|
|
131
|
-
* @version 0.
|
|
159
|
+
* @version 0.7.0
|
|
132
160
|
*/
|
|
133
161
|
declare const SlopText: React.ForwardRefExoticComponent<SlopTextProps & React.RefAttributes<HTMLDivElement>>;
|
|
134
162
|
|
|
135
|
-
export { SlopImage, type SlopImageProps, SlopText, type SlopTextProps, SlopVideo, type SlopVideoProps };
|
|
163
|
+
export { type SlopErrorFallback, SlopImage, type SlopImageProps, SlopText, type SlopTextProps, SlopVideo, type SlopVideoProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SlopImageOptions, ImageAspectRatio, SlopVideoOptions, VideoAspectRatio, SlopTextOptions } from '@slopmachine/core';
|
|
3
|
-
export { ImageAspectRatio, RateResultOptions, RateResultResponse, ResultRating, SlopImageOptions, SlopTextOptions, SlopVideoOptions, VideoAspectRatio, preloadImage, preloadText, preloadVideo, rateResult } from '@slopmachine/core';
|
|
2
|
+
import { SlopMachineError, SlopImageOptions, ImageAspectRatio, SlopVideoOptions, VideoAspectRatio, SlopTextOptions } from '@slopmachine/core';
|
|
3
|
+
export { ImageAspectRatio, RateResultOptions, RateResultResponse, ResultRating, SlopImageOptions, SlopMachineError, SlopTextOptions, SlopVideoOptions, VideoAspectRatio, preloadImage, preloadText, preloadVideo, rateResult } from '@slopmachine/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Content to render when generation or loading fails. Either a node, or a
|
|
7
|
+
* function that receives the error and returns a node.
|
|
8
|
+
*/
|
|
9
|
+
type SlopErrorFallback = React.ReactNode | ((error: SlopMachineError) => React.ReactNode);
|
|
4
10
|
|
|
5
11
|
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">, Omit<SlopImageOptions, "aspectRatio"> {
|
|
6
12
|
/**
|
|
@@ -12,6 +18,17 @@ interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>,
|
|
|
12
18
|
* If not provided, a default spinner and shimmer effect will be shown.
|
|
13
19
|
*/
|
|
14
20
|
loader?: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Content to display if the image fails to generate or load.
|
|
23
|
+
* Pass a node, or a function that receives the `SlopMachineError` and returns a node.
|
|
24
|
+
* If not provided, a default error message is shown in place of the image.
|
|
25
|
+
*/
|
|
26
|
+
errorFallback?: SlopErrorFallback;
|
|
27
|
+
/**
|
|
28
|
+
* Called once per URL when the image fails to generate or load.
|
|
29
|
+
* `error.status` holds the HTTP status when the API reported the failure.
|
|
30
|
+
*/
|
|
31
|
+
onGenerationError?: (error: SlopMachineError) => void;
|
|
15
32
|
/**
|
|
16
33
|
* How the image should be resized to fit its container. Defaults to "cover".
|
|
17
34
|
*/
|
|
@@ -47,7 +64,7 @@ interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>,
|
|
|
47
64
|
* />
|
|
48
65
|
* ```
|
|
49
66
|
*
|
|
50
|
-
* @version 0.
|
|
67
|
+
* @version 0.7.0
|
|
51
68
|
*/
|
|
52
69
|
declare const SlopImage: React.FC<SlopImageProps>;
|
|
53
70
|
|
|
@@ -61,6 +78,17 @@ interface SlopVideoProps extends Omit<React.VideoHTMLAttributes<HTMLVideoElement
|
|
|
61
78
|
* If not provided, a default spinner and shimmer effect will be shown.
|
|
62
79
|
*/
|
|
63
80
|
loader?: React.ReactNode;
|
|
81
|
+
/**
|
|
82
|
+
* Content to display if the video fails to generate or load.
|
|
83
|
+
* Pass a node, or a function that receives the `SlopMachineError` and returns a node.
|
|
84
|
+
* If not provided, a default error message is shown in place of the video.
|
|
85
|
+
*/
|
|
86
|
+
errorFallback?: SlopErrorFallback;
|
|
87
|
+
/**
|
|
88
|
+
* Called once per URL when the video fails to generate or load.
|
|
89
|
+
* `error.status` holds the HTTP status when the API reported the failure.
|
|
90
|
+
*/
|
|
91
|
+
onGenerationError?: (error: SlopMachineError) => void;
|
|
64
92
|
}
|
|
65
93
|
/**
|
|
66
94
|
* Renders a video generated by Slop Machine.
|
|
@@ -90,7 +118,7 @@ interface SlopVideoProps extends Omit<React.VideoHTMLAttributes<HTMLVideoElement
|
|
|
90
118
|
* />
|
|
91
119
|
* ```
|
|
92
120
|
*
|
|
93
|
-
* @version 0.
|
|
121
|
+
* @version 0.7.0
|
|
94
122
|
*/
|
|
95
123
|
declare const SlopVideo: React.FC<SlopVideoProps>;
|
|
96
124
|
|
|
@@ -128,8 +156,8 @@ interface SlopTextProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "chil
|
|
|
128
156
|
* />
|
|
129
157
|
* ```
|
|
130
158
|
*
|
|
131
|
-
* @version 0.
|
|
159
|
+
* @version 0.7.0
|
|
132
160
|
*/
|
|
133
161
|
declare const SlopText: React.ForwardRefExoticComponent<SlopTextProps & React.RefAttributes<HTMLDivElement>>;
|
|
134
162
|
|
|
135
|
-
export { SlopImage, type SlopImageProps, SlopText, type SlopTextProps, SlopVideo, type SlopVideoProps };
|
|
163
|
+
export { type SlopErrorFallback, SlopImage, type SlopImageProps, SlopText, type SlopTextProps, SlopVideo, type SlopVideoProps };
|