@plugable-io/react 0.0.7 → 0.0.10
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/README.md +111 -0
- package/dist/index.d.mts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.js +308 -83
- package/dist/index.mjs +312 -90
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,7 +35,10 @@ __export(index_exports, {
|
|
|
35
35
|
FileList: () => FileList,
|
|
36
36
|
FilePreview: () => FilePreview,
|
|
37
37
|
PlugableProvider: () => PlugableProvider,
|
|
38
|
+
applyCSSVariables: () => applyCSSVariables,
|
|
38
39
|
clearImageCache: () => clearImageCache,
|
|
40
|
+
generateCSSVariables: () => generateCSSVariables,
|
|
41
|
+
getThemeColors: () => getThemeColors,
|
|
39
42
|
useFiles: () => useFiles,
|
|
40
43
|
usePlugable: () => usePlugable
|
|
41
44
|
});
|
|
@@ -44,6 +47,112 @@ module.exports = __toCommonJS(index_exports);
|
|
|
44
47
|
// src/PlugableProvider.tsx
|
|
45
48
|
var import_react = require("react");
|
|
46
49
|
var import_js = require("@plugable-io/js");
|
|
50
|
+
|
|
51
|
+
// src/utils/theme.ts
|
|
52
|
+
var defaultLightTheme = {
|
|
53
|
+
// Purple to blue accent gradient
|
|
54
|
+
accentPrimary: "#9333ea",
|
|
55
|
+
// purple-600
|
|
56
|
+
accentSecondary: "#2563eb",
|
|
57
|
+
// blue-600
|
|
58
|
+
accentHover: "#7c3aed",
|
|
59
|
+
// purple-700
|
|
60
|
+
// Light backgrounds
|
|
61
|
+
baseBg: "#ffffff",
|
|
62
|
+
baseSurface: "#f8fafc",
|
|
63
|
+
// slate-50
|
|
64
|
+
baseBorder: "#e2e8f0",
|
|
65
|
+
// slate-200
|
|
66
|
+
// Dark text on light
|
|
67
|
+
textPrimary: "#0f172a",
|
|
68
|
+
// slate-900
|
|
69
|
+
textSecondary: "#475569",
|
|
70
|
+
// slate-600
|
|
71
|
+
textMuted: "#94a3b8",
|
|
72
|
+
// slate-400
|
|
73
|
+
// State colors
|
|
74
|
+
success: "#10b981",
|
|
75
|
+
// green-500
|
|
76
|
+
error: "#ef4444",
|
|
77
|
+
// red-500
|
|
78
|
+
warning: "#f59e0b",
|
|
79
|
+
// amber-500
|
|
80
|
+
// Overlay
|
|
81
|
+
overlay: "rgba(0, 0, 0, 0.05)",
|
|
82
|
+
backdropBlur: "blur(12px)"
|
|
83
|
+
};
|
|
84
|
+
var defaultDarkTheme = {
|
|
85
|
+
// Purple to blue accent gradient (same as light)
|
|
86
|
+
accentPrimary: "#9333ea",
|
|
87
|
+
accentSecondary: "#2563eb",
|
|
88
|
+
accentHover: "#a855f7",
|
|
89
|
+
// purple-500 (lighter for dark mode)
|
|
90
|
+
// Dark backgrounds
|
|
91
|
+
baseBg: "#0f172a",
|
|
92
|
+
// slate-900
|
|
93
|
+
baseSurface: "rgba(30, 41, 59, 0.5)",
|
|
94
|
+
// slate-800/50 with transparency
|
|
95
|
+
baseBorder: "rgba(255, 255, 255, 0.1)",
|
|
96
|
+
// Light text on dark
|
|
97
|
+
textPrimary: "#f1f5f9",
|
|
98
|
+
// slate-100
|
|
99
|
+
textSecondary: "#cbd5e1",
|
|
100
|
+
// slate-300
|
|
101
|
+
textMuted: "#64748b",
|
|
102
|
+
// slate-500
|
|
103
|
+
// State colors (slightly adjusted for dark mode)
|
|
104
|
+
success: "#34d399",
|
|
105
|
+
// green-400
|
|
106
|
+
error: "#f87171",
|
|
107
|
+
// red-400
|
|
108
|
+
warning: "#fbbf24",
|
|
109
|
+
// amber-400
|
|
110
|
+
// Overlay
|
|
111
|
+
overlay: "rgba(0, 0, 0, 0.3)",
|
|
112
|
+
backdropBlur: "blur(24px)"
|
|
113
|
+
};
|
|
114
|
+
function getThemeColors(config = {}) {
|
|
115
|
+
const { theme = "dark", accentColor, baseColor } = config;
|
|
116
|
+
const isDark = theme === "dark" || theme === "auto" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
117
|
+
const colors = isDark ? { ...defaultDarkTheme } : { ...defaultLightTheme };
|
|
118
|
+
if (accentColor) {
|
|
119
|
+
colors.accentPrimary = accentColor;
|
|
120
|
+
colors.accentSecondary = accentColor;
|
|
121
|
+
colors.accentHover = accentColor;
|
|
122
|
+
}
|
|
123
|
+
if (baseColor) {
|
|
124
|
+
colors.baseBg = baseColor;
|
|
125
|
+
colors.baseSurface = baseColor;
|
|
126
|
+
}
|
|
127
|
+
return colors;
|
|
128
|
+
}
|
|
129
|
+
function generateCSSVariables(colors) {
|
|
130
|
+
return {
|
|
131
|
+
"--plugable-accent-primary": colors.accentPrimary,
|
|
132
|
+
"--plugable-accent-secondary": colors.accentSecondary,
|
|
133
|
+
"--plugable-accent-hover": colors.accentHover,
|
|
134
|
+
"--plugable-base-bg": colors.baseBg,
|
|
135
|
+
"--plugable-base-surface": colors.baseSurface,
|
|
136
|
+
"--plugable-base-border": colors.baseBorder,
|
|
137
|
+
"--plugable-text-primary": colors.textPrimary,
|
|
138
|
+
"--plugable-text-secondary": colors.textSecondary,
|
|
139
|
+
"--plugable-text-muted": colors.textMuted,
|
|
140
|
+
"--plugable-success": colors.success,
|
|
141
|
+
"--plugable-error": colors.error,
|
|
142
|
+
"--plugable-warning": colors.warning,
|
|
143
|
+
"--plugable-overlay": colors.overlay,
|
|
144
|
+
"--plugable-backdrop-blur": colors.backdropBlur
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function applyCSSVariables(element, config = {}) {
|
|
148
|
+
const colors = getThemeColors(config);
|
|
149
|
+
const variables = generateCSSVariables(colors);
|
|
150
|
+
Object.entries(variables).forEach(([key, value]) => {
|
|
151
|
+
element.style.setProperty(key, value);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/PlugableProvider.tsx
|
|
47
156
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
157
|
var PlugableContext = (0, import_react.createContext)(null);
|
|
49
158
|
function createAuthTokenGetter(authProvider, clerkJWTTemplate) {
|
|
@@ -88,6 +197,13 @@ function createAuthTokenGetter(authProvider, clerkJWTTemplate) {
|
|
|
88
197
|
"Firebase not found. Please ensure firebase is installed and initialized, or provide a custom getToken function."
|
|
89
198
|
);
|
|
90
199
|
};
|
|
200
|
+
case "generic_jwks":
|
|
201
|
+
case "generic_jwt":
|
|
202
|
+
return async () => {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`Manual token required for ${authProvider}. Please provide a custom getToken function.`
|
|
205
|
+
);
|
|
206
|
+
};
|
|
91
207
|
default:
|
|
92
208
|
throw new Error(
|
|
93
209
|
`Unknown auth provider: ${authProvider}. Please provide either a valid authProvider or a custom getToken function.`
|
|
@@ -101,11 +217,15 @@ function PlugableProvider({
|
|
|
101
217
|
authProvider,
|
|
102
218
|
clerkJWTTemplate,
|
|
103
219
|
baseUrl,
|
|
104
|
-
staleTime = 5 * 60 * 1e3
|
|
220
|
+
staleTime = 5 * 60 * 1e3,
|
|
105
221
|
// Default 5 minutes
|
|
222
|
+
accentColor,
|
|
223
|
+
baseColor,
|
|
224
|
+
theme = "dark"
|
|
106
225
|
}) {
|
|
107
226
|
const listenersRef = (0, import_react.useRef)({});
|
|
108
227
|
const [cache, setCacheState] = (0, import_react.useState)(/* @__PURE__ */ new Map());
|
|
228
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
109
229
|
const client = (0, import_react.useMemo)(() => {
|
|
110
230
|
if (!getToken && !authProvider) {
|
|
111
231
|
throw new Error(
|
|
@@ -175,7 +295,12 @@ function PlugableProvider({
|
|
|
175
295
|
}),
|
|
176
296
|
[client, bucketId, on, emit, baseUrl, staleTime, getCache, setCache, invalidateCache]
|
|
177
297
|
);
|
|
178
|
-
|
|
298
|
+
(0, import_react.useEffect)(() => {
|
|
299
|
+
if (containerRef.current) {
|
|
300
|
+
applyCSSVariables(containerRef.current, { accentColor, baseColor, theme });
|
|
301
|
+
}
|
|
302
|
+
}, [accentColor, baseColor, theme]);
|
|
303
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlugableContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: containerRef, className: "plugable-root", children }) });
|
|
179
304
|
}
|
|
180
305
|
function usePlugable() {
|
|
181
306
|
const context = (0, import_react.useContext)(PlugableContext);
|
|
@@ -320,6 +445,74 @@ function Dropzone({
|
|
|
320
445
|
}
|
|
321
446
|
);
|
|
322
447
|
}
|
|
448
|
+
const containerStyle = {
|
|
449
|
+
position: "relative",
|
|
450
|
+
border: `2px dashed ${isDragActive ? "var(--plugable-accent-primary)" : "var(--plugable-base-border)"}`,
|
|
451
|
+
borderRadius: "12px",
|
|
452
|
+
padding: "48px 24px",
|
|
453
|
+
textAlign: "center",
|
|
454
|
+
cursor: "pointer",
|
|
455
|
+
background: isDragActive ? "var(--plugable-accent-primary)10" : "var(--plugable-base-surface)",
|
|
456
|
+
backdropFilter: "var(--plugable-backdrop-blur)",
|
|
457
|
+
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
|
|
458
|
+
...style
|
|
459
|
+
};
|
|
460
|
+
const iconContainerStyle = {
|
|
461
|
+
width: "48px",
|
|
462
|
+
height: "48px",
|
|
463
|
+
margin: "0 auto 16px",
|
|
464
|
+
borderRadius: "50%",
|
|
465
|
+
display: "flex",
|
|
466
|
+
alignItems: "center",
|
|
467
|
+
justifyContent: "center",
|
|
468
|
+
background: isDragActive ? `linear-gradient(135deg, var(--plugable-accent-primary), var(--plugable-accent-secondary))` : "var(--plugable-overlay)",
|
|
469
|
+
transition: "all 0.3s ease",
|
|
470
|
+
transform: isDragActive ? "scale(1.1)" : "scale(1)"
|
|
471
|
+
};
|
|
472
|
+
const cloudIconStyle = {
|
|
473
|
+
width: "24px",
|
|
474
|
+
height: "24px",
|
|
475
|
+
color: isDragActive ? "#fff" : "var(--plugable-accent-primary)"
|
|
476
|
+
};
|
|
477
|
+
const titleStyle = {
|
|
478
|
+
margin: 0,
|
|
479
|
+
fontWeight: 600,
|
|
480
|
+
fontSize: "16px",
|
|
481
|
+
color: "var(--plugable-text-primary)",
|
|
482
|
+
marginBottom: "8px"
|
|
483
|
+
};
|
|
484
|
+
const subtitleStyle = {
|
|
485
|
+
margin: 0,
|
|
486
|
+
fontSize: "14px",
|
|
487
|
+
color: "var(--plugable-text-secondary)"
|
|
488
|
+
};
|
|
489
|
+
const maxFilesStyle = {
|
|
490
|
+
margin: "4px 0 0 0",
|
|
491
|
+
fontSize: "12px",
|
|
492
|
+
color: "var(--plugable-text-muted)"
|
|
493
|
+
};
|
|
494
|
+
const progressContainerStyle = {
|
|
495
|
+
marginTop: "16px"
|
|
496
|
+
};
|
|
497
|
+
const progressItemStyle = {
|
|
498
|
+
marginBottom: "12px",
|
|
499
|
+
textAlign: "left"
|
|
500
|
+
};
|
|
501
|
+
const progressLabelStyle = {
|
|
502
|
+
fontSize: "14px",
|
|
503
|
+
color: "var(--plugable-text-secondary)",
|
|
504
|
+
marginBottom: "6px",
|
|
505
|
+
display: "flex",
|
|
506
|
+
justifyContent: "space-between",
|
|
507
|
+
alignItems: "center"
|
|
508
|
+
};
|
|
509
|
+
const progressBarBgStyle = {
|
|
510
|
+
width: "100%",
|
|
511
|
+
height: "6px",
|
|
512
|
+
backgroundColor: "var(--plugable-overlay)",
|
|
513
|
+
borderRadius: "3px",
|
|
514
|
+
overflow: "hidden"
|
|
515
|
+
};
|
|
323
516
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
324
517
|
"div",
|
|
325
518
|
{
|
|
@@ -328,16 +521,7 @@ function Dropzone({
|
|
|
328
521
|
onDragLeave: handleDragLeave,
|
|
329
522
|
onClick: openFileDialog,
|
|
330
523
|
className,
|
|
331
|
-
style:
|
|
332
|
-
border: `2px dashed ${isDragActive ? "#0070f3" : "#ccc"}`,
|
|
333
|
-
borderRadius: "8px",
|
|
334
|
-
padding: "40px 20px",
|
|
335
|
-
textAlign: "center",
|
|
336
|
-
cursor: "pointer",
|
|
337
|
-
backgroundColor: isDragActive ? "#f0f8ff" : "#fafafa",
|
|
338
|
-
transition: "all 0.2s ease",
|
|
339
|
-
...style
|
|
340
|
-
},
|
|
524
|
+
style: containerStyle,
|
|
341
525
|
children: [
|
|
342
526
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
343
527
|
"input",
|
|
@@ -351,42 +535,34 @@ function Dropzone({
|
|
|
351
535
|
}
|
|
352
536
|
),
|
|
353
537
|
isUploading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
354
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("
|
|
355
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
":
|
|
359
|
-
|
|
360
|
-
|
|
538
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: iconContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { style: cloudIconStyle, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" }) }) }),
|
|
539
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: titleStyle, children: "Uploading..." }),
|
|
540
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: progressContainerStyle, children: Object.entries(uploadProgress).map(([fileName, progress]) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: progressItemStyle, children: [
|
|
541
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: progressLabelStyle, children: [
|
|
542
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: fileName }),
|
|
543
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: { fontWeight: 600 }, children: [
|
|
544
|
+
progress,
|
|
545
|
+
"%"
|
|
546
|
+
] })
|
|
361
547
|
] }),
|
|
362
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
548
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: progressBarBgStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
363
549
|
"div",
|
|
364
550
|
{
|
|
365
551
|
style: {
|
|
366
|
-
width:
|
|
367
|
-
height: "
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
373
|
-
"div",
|
|
374
|
-
{
|
|
375
|
-
style: {
|
|
376
|
-
width: `${progress}%`,
|
|
377
|
-
height: "100%",
|
|
378
|
-
backgroundColor: "#0070f3",
|
|
379
|
-
transition: "width 0.3s ease"
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
)
|
|
552
|
+
width: `${progress}%`,
|
|
553
|
+
height: "100%",
|
|
554
|
+
background: `linear-gradient(90deg, var(--plugable-accent-primary), var(--plugable-accent-secondary))`,
|
|
555
|
+
transition: "width 0.3s ease",
|
|
556
|
+
borderRadius: "3px"
|
|
557
|
+
}
|
|
383
558
|
}
|
|
384
|
-
)
|
|
559
|
+
) })
|
|
385
560
|
] }, fileName)) })
|
|
386
561
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
387
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("
|
|
388
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style:
|
|
389
|
-
|
|
562
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: iconContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { style: cloudIconStyle, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" }) }) }),
|
|
563
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: titleStyle, children: isDragActive ? "Drop files here" : "Click to upload or drag and drop" }),
|
|
564
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: subtitleStyle, children: accept ? `Accepted: ${accept}` : "Any file type" }),
|
|
565
|
+
maxFiles && maxFiles > 1 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { style: maxFilesStyle, children: [
|
|
390
566
|
"(Maximum ",
|
|
391
567
|
maxFiles,
|
|
392
568
|
" files)"
|
|
@@ -679,20 +855,25 @@ function FileImage({
|
|
|
679
855
|
...style
|
|
680
856
|
};
|
|
681
857
|
if (error) {
|
|
682
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.
|
|
858
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
683
859
|
"div",
|
|
684
860
|
{
|
|
685
861
|
className,
|
|
686
862
|
style: {
|
|
687
863
|
...imageStyle,
|
|
688
864
|
display: "flex",
|
|
865
|
+
flexDirection: "column",
|
|
689
866
|
alignItems: "center",
|
|
690
867
|
justifyContent: "center",
|
|
691
|
-
backgroundColor: "
|
|
692
|
-
color: "
|
|
693
|
-
fontSize: "14px"
|
|
868
|
+
backgroundColor: "var(--plugable-base-surface)",
|
|
869
|
+
color: "var(--plugable-text-muted)",
|
|
870
|
+
fontSize: "14px",
|
|
871
|
+
gap: "8px"
|
|
694
872
|
},
|
|
695
|
-
children:
|
|
873
|
+
children: [
|
|
874
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { style: { width: "32px", height: "32px" }, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }),
|
|
875
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "Failed to load" })
|
|
876
|
+
]
|
|
696
877
|
}
|
|
697
878
|
);
|
|
698
879
|
}
|
|
@@ -703,29 +884,27 @@ function FileImage({
|
|
|
703
884
|
className,
|
|
704
885
|
style: {
|
|
705
886
|
...imageStyle,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
backgroundColor: "#f0f0f0"
|
|
887
|
+
position: "relative",
|
|
888
|
+
overflow: "hidden",
|
|
889
|
+
backgroundColor: "rgba(0, 0, 0, 0.02)"
|
|
710
890
|
},
|
|
711
891
|
children: [
|
|
712
892
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
713
893
|
"div",
|
|
714
894
|
{
|
|
715
895
|
style: {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
animation: "spin 1s linear infinite"
|
|
896
|
+
position: "absolute",
|
|
897
|
+
inset: 0,
|
|
898
|
+
background: "linear-gradient(110deg, transparent 40%, rgba(255, 255, 255, 0.3) 50%, transparent 60%)",
|
|
899
|
+
backgroundSize: "200% 100%",
|
|
900
|
+
animation: "shimmer-pulse 1.5s ease-in-out infinite"
|
|
722
901
|
}
|
|
723
902
|
}
|
|
724
903
|
),
|
|
725
904
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("style", { children: `
|
|
726
|
-
@keyframes
|
|
727
|
-
0% {
|
|
728
|
-
100% {
|
|
905
|
+
@keyframes shimmer-pulse {
|
|
906
|
+
0% { background-position: 200% 0; }
|
|
907
|
+
100% { background-position: -200% 0; }
|
|
729
908
|
}
|
|
730
909
|
` })
|
|
731
910
|
]
|
|
@@ -738,7 +917,11 @@ function FileImage({
|
|
|
738
917
|
src: imageSrc,
|
|
739
918
|
alt: alt || file.name,
|
|
740
919
|
className,
|
|
741
|
-
style:
|
|
920
|
+
style: {
|
|
921
|
+
...imageStyle,
|
|
922
|
+
opacity: isLoading ? 0 : 1,
|
|
923
|
+
transition: "opacity 0.3s ease-in"
|
|
924
|
+
},
|
|
742
925
|
onLoad: handleLoad,
|
|
743
926
|
onError: handleError
|
|
744
927
|
}
|
|
@@ -750,21 +933,35 @@ function clearImageCache() {
|
|
|
750
933
|
}
|
|
751
934
|
|
|
752
935
|
// src/components/FilePreview.tsx
|
|
753
|
-
var import_react5 = require("react");
|
|
936
|
+
var import_react5 = __toESM(require("react"));
|
|
754
937
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
755
938
|
function FilePreview({
|
|
756
939
|
file: initialFile,
|
|
757
|
-
width =
|
|
758
|
-
height =
|
|
940
|
+
width = 120,
|
|
941
|
+
height = 120,
|
|
759
942
|
className,
|
|
760
943
|
style,
|
|
761
944
|
objectFit = "cover",
|
|
762
|
-
showExtension = true,
|
|
763
945
|
renderNonImage
|
|
764
946
|
}) {
|
|
765
947
|
const { client } = usePlugable();
|
|
766
948
|
const [file, setFile] = (0, import_react5.useState)(initialFile);
|
|
767
949
|
const [isRefetching, setIsRefetching] = (0, import_react5.useState)(false);
|
|
950
|
+
const [containerSize, setContainerSize] = (0, import_react5.useState)({ width: 0, height: 0 });
|
|
951
|
+
const containerRef = import_react5.default.useRef(null);
|
|
952
|
+
(0, import_react5.useEffect)(() => {
|
|
953
|
+
if (!containerRef.current) return;
|
|
954
|
+
const observer = new ResizeObserver((entries) => {
|
|
955
|
+
for (const entry of entries) {
|
|
956
|
+
setContainerSize({
|
|
957
|
+
width: entry.contentRect.width,
|
|
958
|
+
height: entry.contentRect.height
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
observer.observe(containerRef.current);
|
|
963
|
+
return () => observer.disconnect();
|
|
964
|
+
}, []);
|
|
768
965
|
(0, import_react5.useEffect)(() => {
|
|
769
966
|
setFile(initialFile);
|
|
770
967
|
}, [initialFile.id, initialFile.download_url]);
|
|
@@ -779,45 +976,70 @@ function FilePreview({
|
|
|
779
976
|
} finally {
|
|
780
977
|
setIsRefetching(false);
|
|
781
978
|
}
|
|
782
|
-
}, [file.id, client]);
|
|
979
|
+
}, [file.id, client, isRefetching]);
|
|
783
980
|
const isImage = file.content_type.startsWith("image/");
|
|
981
|
+
const isSmall = containerSize.width > 0 && containerSize.width <= 80 || containerSize.height > 0 && containerSize.height <= 80;
|
|
784
982
|
const containerStyle = {
|
|
785
983
|
width,
|
|
786
984
|
height,
|
|
787
|
-
borderRadius:
|
|
985
|
+
borderRadius: isSmall ? "4px" : "8px",
|
|
788
986
|
overflow: "hidden",
|
|
789
|
-
|
|
987
|
+
position: "relative",
|
|
790
988
|
display: "flex",
|
|
791
989
|
alignItems: "center",
|
|
792
990
|
justifyContent: "center",
|
|
793
|
-
|
|
991
|
+
background: "var(--plugable-base-surface)",
|
|
794
992
|
...style
|
|
795
993
|
};
|
|
796
994
|
if (isImage) {
|
|
797
995
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
798
|
-
|
|
996
|
+
"div",
|
|
799
997
|
{
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
height,
|
|
803
|
-
objectFit,
|
|
998
|
+
ref: containerRef,
|
|
999
|
+
style: containerStyle,
|
|
804
1000
|
className,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
1001
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1002
|
+
FileImage,
|
|
1003
|
+
{
|
|
1004
|
+
file,
|
|
1005
|
+
width,
|
|
1006
|
+
height,
|
|
1007
|
+
objectFit,
|
|
1008
|
+
style: { borderRadius: isSmall ? "4px" : "8px" },
|
|
1009
|
+
onRefetchNeeded: handleRefetch
|
|
1010
|
+
}
|
|
1011
|
+
)
|
|
808
1012
|
}
|
|
809
1013
|
);
|
|
810
1014
|
}
|
|
811
1015
|
if (renderNonImage) {
|
|
812
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1016
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1017
|
+
"div",
|
|
1018
|
+
{
|
|
1019
|
+
ref: containerRef,
|
|
1020
|
+
className,
|
|
1021
|
+
style: containerStyle,
|
|
1022
|
+
children: renderNonImage(file)
|
|
1023
|
+
}
|
|
1024
|
+
);
|
|
813
1025
|
}
|
|
814
1026
|
const extension = file.name.split(".").pop()?.toUpperCase() || "FILE";
|
|
815
|
-
|
|
816
|
-
fontSize: "12px",
|
|
817
|
-
fontWeight:
|
|
818
|
-
color: "
|
|
819
|
-
textTransform: "uppercase"
|
|
820
|
-
|
|
1027
|
+
const extensionStyle = {
|
|
1028
|
+
fontSize: isSmall ? "9px" : "12px",
|
|
1029
|
+
fontWeight: 700,
|
|
1030
|
+
color: "var(--plugable-text-secondary)",
|
|
1031
|
+
textTransform: "uppercase",
|
|
1032
|
+
letterSpacing: "0.5px"
|
|
1033
|
+
};
|
|
1034
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1035
|
+
"div",
|
|
1036
|
+
{
|
|
1037
|
+
ref: containerRef,
|
|
1038
|
+
className,
|
|
1039
|
+
style: containerStyle,
|
|
1040
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: extensionStyle, children: extension })
|
|
1041
|
+
}
|
|
1042
|
+
);
|
|
821
1043
|
}
|
|
822
1044
|
// Annotate the CommonJS export names for ESM import in node:
|
|
823
1045
|
0 && (module.exports = {
|
|
@@ -826,7 +1048,10 @@ function FilePreview({
|
|
|
826
1048
|
FileList,
|
|
827
1049
|
FilePreview,
|
|
828
1050
|
PlugableProvider,
|
|
1051
|
+
applyCSSVariables,
|
|
829
1052
|
clearImageCache,
|
|
1053
|
+
generateCSSVariables,
|
|
1054
|
+
getThemeColors,
|
|
830
1055
|
useFiles,
|
|
831
1056
|
usePlugable
|
|
832
1057
|
});
|