@slopmachine/react 0.1.25 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slopmachine/react",
3
- "version": "0.1.25",
3
+ "version": "0.2.0",
4
4
  "llms": "https://docs.slopmachine.dev/llms.txt",
5
5
  "llmsFull": "https://docs.slopmachine.dev/llms-full.txt",
6
6
  "description": "The official React SDK for Slop Machine",
@@ -47,7 +47,7 @@
47
47
  "@radix-ui/react-label": "^2.1.8",
48
48
  "@radix-ui/react-select": "^2.2.6",
49
49
  "@radix-ui/react-slot": "^1.2.4",
50
- "@slopmachine/core": "^0.1.25",
50
+ "@slopmachine/core": "^0.2.0",
51
51
  "@tailwindcss/postcss": "^4.1.18",
52
52
  "@tailwindcss/vite": "^4.1.18",
53
53
  "@types/marked": "^5.0.2",
@@ -44,6 +44,7 @@ export interface SlopImageProps
44
44
  *
45
45
  * @example
46
46
  * ```tsx
47
+ * // Using a Bucket
47
48
  * <SlopImage
48
49
  * bucketId="my-bucket"
49
50
  * resultId="some-result"
@@ -51,12 +52,24 @@ export interface SlopImageProps
51
52
  * className="rounded-lg"
52
53
  * objectFit="cover"
53
54
  * />
55
+ *
56
+ * // Using a Pipeline with runtime prompt
57
+ * <SlopImage
58
+ * pipelineId="pipe_live_abc123"
59
+ * prompt="1960s retro robot eating pizza on Mars"
60
+ * aspectRatio="16:9"
61
+ * metadata={{ userId: "123" }}
62
+ * />
54
63
  * ```
55
64
  *
56
- * @version 0.1.25
65
+ * @version 0.2.0
57
66
  */
58
67
  export const SlopImage: React.FC<SlopImageProps> = ({
59
68
  bucketId,
69
+ pipelineId,
70
+ siloId,
71
+ prompt,
72
+ metadata,
60
73
  className,
61
74
  aspectRatio = "1:1",
62
75
  version,
@@ -70,6 +83,8 @@ export const SlopImage: React.FC<SlopImageProps> = ({
70
83
  objectFit = "cover",
71
84
  imageClassName,
72
85
  style,
86
+ onLoad,
87
+ onError,
73
88
  ...props
74
89
  }) => {
75
90
  // Construct API URL
@@ -77,6 +92,10 @@ export const SlopImage: React.FC<SlopImageProps> = ({
77
92
  () =>
78
93
  buildImageUrl({
79
94
  bucketId,
95
+ pipelineId,
96
+ siloId,
97
+ prompt,
98
+ metadata,
80
99
  aspectRatio,
81
100
  version,
82
101
  resultId,
@@ -88,6 +107,10 @@ export const SlopImage: React.FC<SlopImageProps> = ({
88
107
  }),
89
108
  [
90
109
  bucketId,
110
+ pipelineId,
111
+ siloId,
112
+ prompt,
113
+ metadata,
91
114
  aspectRatio,
92
115
  version,
93
116
  resultId,
@@ -301,8 +324,15 @@ export const SlopImage: React.FC<SlopImageProps> = ({
301
324
  key={src}
302
325
  src={src}
303
326
  alt={alt}
304
- onLoad={() => setIsLoading(false)}
305
- onError={() => setIsLoading(false)}
327
+ {...props}
328
+ onLoad={(e) => {
329
+ setIsLoading(false);
330
+ onLoad?.(e);
331
+ }}
332
+ onError={(e) => {
333
+ setIsLoading(false);
334
+ onError?.(e);
335
+ }}
306
336
  className={cn(
307
337
  "h-full w-full transition-opacity duration-500",
308
338
  isLoading ? "opacity-0" : "opacity-100",
@@ -315,7 +345,6 @@ export const SlopImage: React.FC<SlopImageProps> = ({
315
345
  transition: "opacity 500ms",
316
346
  opacity: isLoading ? 0 : 1,
317
347
  }}
318
- {...props}
319
348
  />
320
349
  </div>
321
350
  </div>
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useEffect, useMemo, useState } from "react";
2
2
  import { buildTextUrl, type SlopTextOptions } from "@slopmachine/core";
3
3
  import { marked } from "marked";
4
4
 
@@ -24,20 +24,32 @@ export interface SlopTextProps
24
24
  *
25
25
  * @example
26
26
  * ```tsx
27
+ * // Using a Bucket
27
28
  * <SlopText
28
29
  * bucketId="my-text-bucket"
29
30
  * fallback={<div>Loading story...</div>}
30
31
  * errorFallback={<div>Failed to load story</div>}
31
32
  * className="text-lg text-gray-800"
32
33
  * />
34
+ *
35
+ * // Using a Pipeline with runtime prompt
36
+ * <SlopText
37
+ * pipelineId="pipe_live_abc123"
38
+ * prompt="Write a whimsical haiku about quantum physics"
39
+ * metadata={{ userId: "123" }}
40
+ * />
33
41
  * ```
34
42
  *
35
- * @version 0.1.25
43
+ * @version 0.2.0
36
44
  */
37
45
  export const SlopText = React.forwardRef<HTMLDivElement, SlopTextProps>(
38
46
  (
39
47
  {
40
48
  bucketId,
49
+ pipelineId,
50
+ siloId,
51
+ prompt,
52
+ metadata,
41
53
  version,
42
54
  resultId,
43
55
  variables,
@@ -53,6 +65,34 @@ export const SlopText = React.forwardRef<HTMLDivElement, SlopTextProps>(
53
65
  const [loading, setLoading] = useState(true);
54
66
  const [error, setError] = useState<Error | null>(null);
55
67
 
68
+ const rawUrl = useMemo(
69
+ () =>
70
+ buildTextUrl({
71
+ bucketId,
72
+ pipelineId,
73
+ siloId,
74
+ prompt,
75
+ metadata,
76
+ version,
77
+ resultId,
78
+ variables,
79
+ baseUrl,
80
+ attachments,
81
+ }),
82
+ [
83
+ bucketId,
84
+ pipelineId,
85
+ siloId,
86
+ prompt,
87
+ JSON.stringify(metadata),
88
+ version,
89
+ resultId,
90
+ JSON.stringify(variables),
91
+ baseUrl,
92
+ JSON.stringify(attachments),
93
+ ],
94
+ );
95
+
56
96
  useEffect(() => {
57
97
  let isMounted = true;
58
98
 
@@ -61,17 +101,8 @@ export const SlopText = React.forwardRef<HTMLDivElement, SlopTextProps>(
61
101
  setLoading(true);
62
102
  setError(null);
63
103
 
64
- const url = buildTextUrl({
65
- bucketId,
66
- version,
67
- resultId,
68
- variables,
69
- baseUrl,
70
- attachments,
71
- });
72
-
73
104
  // Fetch the URL to get the content, following redirects automatically
74
- const response = await fetch(url, { cache: "no-store" });
105
+ const response = await fetch(rawUrl, { cache: "no-store" });
75
106
  if (!response.ok) {
76
107
  let errorMessage = response.statusText;
77
108
  try {
@@ -108,14 +139,7 @@ export const SlopText = React.forwardRef<HTMLDivElement, SlopTextProps>(
108
139
  return () => {
109
140
  isMounted = false;
110
141
  };
111
- }, [
112
- bucketId,
113
- version,
114
- resultId,
115
- JSON.stringify(variables),
116
- JSON.stringify(attachments),
117
- baseUrl,
118
- ]);
142
+ }, [rawUrl]);
119
143
 
120
144
  if (error && errorFallback) {
121
145
  return <>{errorFallback}</>;
@@ -36,6 +36,7 @@ export interface SlopVideoProps
36
36
  *
37
37
  * @example
38
38
  * ```tsx
39
+ * // Using a Bucket
39
40
  * <SlopVideo
40
41
  * bucketId="my-bucket"
41
42
  * resultId="some-result"
@@ -45,12 +46,24 @@ export interface SlopVideoProps
45
46
  * loop
46
47
  * muted
47
48
  * />
49
+ *
50
+ * // Using a Pipeline with runtime prompt
51
+ * <SlopVideo
52
+ * pipelineId="pipe_live_abc123"
53
+ * prompt="Drone shot of a cyberpunk city in rain"
54
+ * aspectRatio="16:9"
55
+ * metadata={{ campaign: "spring_launch" }}
56
+ * />
48
57
  * ```
49
58
  *
50
- * @version 0.1.25
59
+ * @version 0.2.0
51
60
  */
52
61
  export const SlopVideo: React.FC<SlopVideoProps> = ({
53
62
  bucketId,
63
+ pipelineId,
64
+ siloId,
65
+ prompt,
66
+ metadata,
54
67
  className,
55
68
  aspectRatio = "16:9",
56
69
  version,
@@ -66,6 +79,8 @@ export const SlopVideo: React.FC<SlopVideoProps> = ({
66
79
  loop = true,
67
80
  muted = true,
68
81
  playsInline = true,
82
+ onLoadedData,
83
+ onError,
69
84
  ...props
70
85
  }) => {
71
86
  // Construct API URL
@@ -73,6 +88,10 @@ export const SlopVideo: React.FC<SlopVideoProps> = ({
73
88
  () =>
74
89
  buildVideoUrl({
75
90
  bucketId,
91
+ pipelineId,
92
+ siloId,
93
+ prompt,
94
+ metadata,
76
95
  aspectRatio,
77
96
  version,
78
97
  resultId,
@@ -85,6 +104,10 @@ export const SlopVideo: React.FC<SlopVideoProps> = ({
85
104
  }),
86
105
  [
87
106
  bucketId,
107
+ pipelineId,
108
+ siloId,
109
+ prompt,
110
+ metadata,
88
111
  aspectRatio,
89
112
  version,
90
113
  resultId,
@@ -302,8 +325,15 @@ export const SlopVideo: React.FC<SlopVideoProps> = ({
302
325
  loop={loop}
303
326
  muted={muted}
304
327
  playsInline={playsInline}
305
- onLoadedData={() => setIsLoading(false)}
306
- onError={() => setIsLoading(false)}
328
+ {...props}
329
+ onLoadedData={(e) => {
330
+ setIsLoading(false);
331
+ onLoadedData?.(e);
332
+ }}
333
+ onError={(e) => {
334
+ setIsLoading(false);
335
+ onError?.(e);
336
+ }}
307
337
  className={cn(
308
338
  "h-full w-full object-cover transition-opacity duration-500",
309
339
  isLoading ? "opacity-0" : "opacity-100",
@@ -315,7 +345,6 @@ export const SlopVideo: React.FC<SlopVideoProps> = ({
315
345
  transition: "opacity 500ms",
316
346
  opacity: isLoading ? 0 : 1,
317
347
  }}
318
- {...props}
319
348
  />
320
349
  </div>
321
350
  </div>
File without changes