@useupup/preact 3.3.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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/dist/AudioUploader-2WITC5YR-4WGBUCEB.js +298 -0
  4. package/dist/AudioUploader-2WITC5YR-4WGBUCEB.js.map +1 -0
  5. package/dist/AudioUploader-2WITC5YR-GCKVRJAT.cjs +298 -0
  6. package/dist/AudioUploader-2WITC5YR-GCKVRJAT.cjs.map +1 -0
  7. package/dist/BoxUploader-VE5LRJ7M-CWGNYYJV.js +170 -0
  8. package/dist/BoxUploader-VE5LRJ7M-CWGNYYJV.js.map +1 -0
  9. package/dist/BoxUploader-VE5LRJ7M-IE7LYW5P.cjs +170 -0
  10. package/dist/BoxUploader-VE5LRJ7M-IE7LYW5P.cjs.map +1 -0
  11. package/dist/CameraUploader-WF5A6UIS-3KBW647M.cjs +628 -0
  12. package/dist/CameraUploader-WF5A6UIS-3KBW647M.cjs.map +1 -0
  13. package/dist/CameraUploader-WF5A6UIS-DONVXSEZ.js +628 -0
  14. package/dist/CameraUploader-WF5A6UIS-DONVXSEZ.js.map +1 -0
  15. package/dist/DropboxUploader-VMUYG3OP-7FKTLIIL.cjs +172 -0
  16. package/dist/DropboxUploader-VMUYG3OP-7FKTLIIL.cjs.map +1 -0
  17. package/dist/DropboxUploader-VMUYG3OP-DBUPHIG7.js +172 -0
  18. package/dist/DropboxUploader-VMUYG3OP-DBUPHIG7.js.map +1 -0
  19. package/dist/GoogleDriveUploader-YA56X3QR-FMS6MTYU.js +175 -0
  20. package/dist/GoogleDriveUploader-YA56X3QR-FMS6MTYU.js.map +1 -0
  21. package/dist/GoogleDriveUploader-YA56X3QR-OR3CQLX2.cjs +175 -0
  22. package/dist/GoogleDriveUploader-YA56X3QR-OR3CQLX2.cjs.map +1 -0
  23. package/dist/ImageEditorInline-N2NSAODR-QWXPP3ON.js +184 -0
  24. package/dist/ImageEditorInline-N2NSAODR-QWXPP3ON.js.map +1 -0
  25. package/dist/ImageEditorInline-N2NSAODR-ZVAM6EOA.cjs +184 -0
  26. package/dist/ImageEditorInline-N2NSAODR-ZVAM6EOA.cjs.map +1 -0
  27. package/dist/ImageEditorModal-CWKMDVPY-PRD43JPH.cjs +236 -0
  28. package/dist/ImageEditorModal-CWKMDVPY-PRD43JPH.cjs.map +1 -0
  29. package/dist/ImageEditorModal-CWKMDVPY-ZRPTYHYN.js +236 -0
  30. package/dist/ImageEditorModal-CWKMDVPY-ZRPTYHYN.js.map +1 -0
  31. package/dist/OneDriveUploader-I25Y6AJP-FVXK6RGT.js +173 -0
  32. package/dist/OneDriveUploader-I25Y6AJP-FVXK6RGT.js.map +1 -0
  33. package/dist/OneDriveUploader-I25Y6AJP-GBOBEJQR.cjs +173 -0
  34. package/dist/OneDriveUploader-I25Y6AJP-GBOBEJQR.cjs.map +1 -0
  35. package/dist/ScreenCaptureUploader-WKDO4S75-3TT6GNEN.js +286 -0
  36. package/dist/ScreenCaptureUploader-WKDO4S75-3TT6GNEN.js.map +1 -0
  37. package/dist/ScreenCaptureUploader-WKDO4S75-G7ADH264.cjs +286 -0
  38. package/dist/ScreenCaptureUploader-WKDO4S75-G7ADH264.cjs.map +1 -0
  39. package/dist/chunk-2XFVSPFN.cjs +293 -0
  40. package/dist/chunk-2XFVSPFN.cjs.map +1 -0
  41. package/dist/chunk-7JLN2HMZ.cjs +4296 -0
  42. package/dist/chunk-7JLN2HMZ.cjs.map +1 -0
  43. package/dist/chunk-BVMKSTAE.js +4296 -0
  44. package/dist/chunk-BVMKSTAE.js.map +1 -0
  45. package/dist/chunk-C7QBCXAH.js +39 -0
  46. package/dist/chunk-C7QBCXAH.js.map +1 -0
  47. package/dist/chunk-CR6CXFRP.js +195 -0
  48. package/dist/chunk-CR6CXFRP.js.map +1 -0
  49. package/dist/chunk-ETIJATY7.cjs +39 -0
  50. package/dist/chunk-ETIJATY7.cjs.map +1 -0
  51. package/dist/chunk-FH3LYESR.js +411 -0
  52. package/dist/chunk-FH3LYESR.js.map +1 -0
  53. package/dist/chunk-GKMTOOTQ.cjs +411 -0
  54. package/dist/chunk-GKMTOOTQ.cjs.map +1 -0
  55. package/dist/chunk-KHH3WHWU.js +74 -0
  56. package/dist/chunk-KHH3WHWU.js.map +1 -0
  57. package/dist/chunk-V2O5HRJV.cjs +74 -0
  58. package/dist/chunk-V2O5HRJV.cjs.map +1 -0
  59. package/dist/chunk-WCI3AGJV.js +831 -0
  60. package/dist/chunk-WCI3AGJV.js.map +1 -0
  61. package/dist/chunk-YWJHE7U4.cjs +195 -0
  62. package/dist/chunk-YWJHE7U4.cjs.map +1 -0
  63. package/dist/chunk-ZGWETRKI.js +293 -0
  64. package/dist/chunk-ZGWETRKI.js.map +1 -0
  65. package/dist/chunk-ZKZJ5PPP.cjs +831 -0
  66. package/dist/chunk-ZKZJ5PPP.cjs.map +1 -0
  67. package/dist/filerobot-bridge-52YH7W2M.cjs +92 -0
  68. package/dist/filerobot-bridge-52YH7W2M.cjs.map +1 -0
  69. package/dist/filerobot-bridge-ED4XMHX4.js +92 -0
  70. package/dist/filerobot-bridge-ED4XMHX4.js.map +1 -0
  71. package/dist/filerobot-island.css +97 -0
  72. package/dist/filerobot-island.css.map +1 -0
  73. package/dist/filerobot-island.js +77951 -0
  74. package/dist/filerobot-island.js.map +1 -0
  75. package/dist/index.cjs +5600 -0
  76. package/dist/index.cjs.map +1 -0
  77. package/dist/index.d.cts +1 -0
  78. package/dist/index.d.ts +1 -0
  79. package/dist/index.js +5600 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/styles.d.ts +4 -0
  82. package/dist/tailwind-prefixed.css +2529 -0
  83. package/package.json +130 -0
@@ -0,0 +1,831 @@
1
+ import {
2
+ Icon_default,
3
+ SourceViewHeaderExtraContext,
4
+ searchDriveFiles
5
+ } from "./chunk-BVMKSTAE.js";
6
+ import {
7
+ SourceViewContainer
8
+ } from "./chunk-C7QBCXAH.js";
9
+ import {
10
+ Fragment,
11
+ u,
12
+ useUploaderI18n,
13
+ useUploaderOptions,
14
+ useUploaderRuntime,
15
+ useUploaderSource,
16
+ useUploaderTheme
17
+ } from "./chunk-ZGWETRKI.js";
18
+ import {
19
+ $,
20
+ C,
21
+ compat_module_exports,
22
+ init_compat_module
23
+ } from "./chunk-FH3LYESR.js";
24
+
25
+ // ../react/dist/chunk-6TFTTLOD.js
26
+ init_compat_module();
27
+ import { formatUiMessage as t } from "@useupup/core";
28
+ import { cn } from "@useupup/core/internal";
29
+ init_compat_module();
30
+ init_compat_module();
31
+ init_compat_module();
32
+ import {
33
+ formatUiMessage as t2,
34
+ pluralUiMessage as plural
35
+ } from "@useupup/core";
36
+ import { cn as cn5 } from "@useupup/core/internal";
37
+ import { cn as cn2 } from "@useupup/core/internal";
38
+ import { cn as cn4 } from "@useupup/core/internal";
39
+ import { b64EncodeUnicode, cn as cn3 } from "@useupup/core/internal";
40
+ init_compat_module();
41
+ init_compat_module();
42
+ import { ServerModeDriveController } from "@useupup/core/internal";
43
+ import { errorCodeToMessageKey } from "@useupup/core";
44
+ import { cn as cn6 } from "@useupup/core/internal";
45
+ function DriveAuthFallback({
46
+ providerName,
47
+ onRetry,
48
+ error,
49
+ "data-upup-slot": dataUpupSlot = "drive-auth-fallback"
50
+ }) {
51
+ const { isDark: dark, slotOverrides: slotClasses } = useUploaderTheme();
52
+ const { translations: tr } = useUploaderI18n();
53
+ const attemptedRef = (0, compat_module_exports.useRef)(false);
54
+ (0, compat_module_exports.useEffect)(() => {
55
+ if (attemptedRef.current || error) return;
56
+ attemptedRef.current = true;
57
+ onRetry();
58
+ }, [error, onRetry]);
59
+ return /* @__PURE__ */ u(SourceViewContainer, { "data-upup-slot": dataUpupSlot, children: /* @__PURE__ */ u("div", { className: "upup-flex upup-h-full upup-w-full upup-flex-col upup-items-center upup-justify-center upup-gap-4 upup-p-6 upup-text-center", children: [
60
+ !!error && /* @__PURE__ */ u(
61
+ "p",
62
+ {
63
+ "data-testid": "upup-drive-error",
64
+ "data-upup-slot": "drive-error",
65
+ role: "alert",
66
+ className: "upup-p-4 upup-text-sm upup-text-red-600 dark:upup-text-red-400",
67
+ children: t(tr.driveLoadError, { message: error.message })
68
+ }
69
+ ),
70
+ /* @__PURE__ */ u(
71
+ "p",
72
+ {
73
+ className: cn(
74
+ "upup-text-sm upup-text-[#333]",
75
+ {
76
+ "upup-text-[#FAFAFA] dark:upup-text-[#FAFAFA]": dark
77
+ },
78
+ slotClasses.sourceView
79
+ ),
80
+ children: t(tr.authenticatePrompt, { provider: providerName })
81
+ }
82
+ ),
83
+ /* @__PURE__ */ u(
84
+ "button",
85
+ {
86
+ type: "button",
87
+ className: cn(
88
+ "upup-rounded-md upup-bg-[#0ea5e9] upup-px-4 upup-py-2 upup-text-sm upup-font-medium upup-text-white upup-transition-all upup-duration-300 hover:upup-bg-[#0284c7]",
89
+ {
90
+ "upup-bg-[#38bdf8] hover:upup-bg-[#0ea5e9] dark:upup-bg-[#38bdf8] dark:hover:upup-bg-[#0ea5e9]": dark
91
+ }
92
+ ),
93
+ onClick: onRetry,
94
+ children: t(tr.signInWith, { provider: providerName })
95
+ }
96
+ )
97
+ ] }) });
98
+ }
99
+ function DriveBrowserHeader({
100
+ path,
101
+ setPath,
102
+ user,
103
+ handleSignOut,
104
+ showSearch,
105
+ onSearch,
106
+ searchTerm
107
+ }) {
108
+ const { setActiveSource } = useUploaderSource();
109
+ const { translations: tr } = useUploaderI18n();
110
+ const { isDark: dark, slotOverrides: slotClasses } = useUploaderTheme();
111
+ const headerExtraHost = (0, compat_module_exports.useContext)(SourceViewHeaderExtraContext);
112
+ const [searchOpen, setSearchOpen] = (0, compat_module_exports.useState)(false);
113
+ const searchInputRef = (0, compat_module_exports.useRef)(null);
114
+ (0, compat_module_exports.useEffect)(() => {
115
+ var _a;
116
+ if (searchOpen) (_a = searchInputRef.current) == null ? void 0 : _a.focus();
117
+ }, [searchOpen]);
118
+ if (!user) return null;
119
+ const navigated = path.length > 1;
120
+ const currentFolder = path[path.length - 1];
121
+ const hasFilter = searchTerm.trim().length > 0;
122
+ const searchField = (expand) => /* @__PURE__ */ u(
123
+ "div",
124
+ {
125
+ className: cn2(
126
+ "upup-relative upup-min-w-0 upup-flex-1",
127
+ expand && "upup-fx-search-expand",
128
+ slotClasses.driveSearchContainer
129
+ ),
130
+ children: [
131
+ /* @__PURE__ */ u(
132
+ "input",
133
+ {
134
+ ref: searchInputRef,
135
+ type: "search",
136
+ name: "upup-drive-search",
137
+ "data-testid": "upup-drive-search-input",
138
+ "data-upup-slot": "drive-search-input",
139
+ "aria-label": tr.search,
140
+ className: cn2(
141
+ "upup-w-full upup-rounded-lg upup-px-3 upup-py-1.5 upup-pl-8 upup-text-xs upup-outline-none upup-ring-1 upup-transition-shadow focus:upup-ring-2 focus:upup-ring-[#38bdf8]",
142
+ dark ? "upup-bg-white/[0.06] upup-text-[#e2e8f0] upup-ring-white/[0.1] placeholder:upup-text-[#64748b]" : "upup-bg-white upup-text-[#0f172a] upup-ring-black/[0.08] placeholder:upup-text-[#94a3b8]",
143
+ slotClasses.driveSearchInput
144
+ ),
145
+ placeholder: tr.search,
146
+ value: searchTerm,
147
+ onChange: (e) => {
148
+ onSearch(e.currentTarget.value);
149
+ },
150
+ onKeyDown: (e) => {
151
+ if (e.key === "Escape") setSearchOpen(false);
152
+ },
153
+ onBlur: () => {
154
+ if (!searchTerm) setSearchOpen(false);
155
+ }
156
+ }
157
+ ),
158
+ /* @__PURE__ */ u(
159
+ Icon_default,
160
+ {
161
+ name: "search",
162
+ className: "upup-absolute upup-left-2.5 upup-top-1/2 upup--translate-y-1/2 upup-text-[#939393]"
163
+ }
164
+ )
165
+ ]
166
+ }
167
+ );
168
+ return /* @__PURE__ */ u("div", { "data-upup-slot": "drive-browser-header", children: [
169
+ !!headerExtraHost && $(
170
+ /* @__PURE__ */ u(Fragment, { children: [
171
+ /* @__PURE__ */ u("div", { className: "upup-relative upup-flex upup-h-6 upup-w-6 upup-items-center upup-justify-center upup-overflow-hidden upup-rounded-full", children: [
172
+ !!user.picture && /* @__PURE__ */ u(
173
+ "img",
174
+ {
175
+ alt: user.name,
176
+ src: user.picture,
177
+ className: "upup-bg-center upup-object-cover"
178
+ }
179
+ ),
180
+ !user.picture && /* @__PURE__ */ u(Icon_default, { name: "user", className: "upup-text-xl" })
181
+ ] }),
182
+ /* @__PURE__ */ u(
183
+ "button",
184
+ {
185
+ className: cn2(
186
+ "upup-hover:upup-underline upup-text-xs upup-font-medium upup-text-[#0284c7]",
187
+ {
188
+ "upup-text-[#38bdf8] dark:upup-text-[#38bdf8]": dark
189
+ },
190
+ slotClasses.driveLogoutButton
191
+ ),
192
+ onClick: () => {
193
+ void handleSignOut();
194
+ setActiveSource(void 0);
195
+ },
196
+ children: tr.logOut
197
+ }
198
+ ),
199
+ /* @__PURE__ */ u(
200
+ "span",
201
+ {
202
+ "aria-hidden": "true",
203
+ className: cn2(
204
+ "upup-h-4 upup-w-px",
205
+ dark ? "upup-bg-white/15" : "upup-bg-black/15"
206
+ )
207
+ }
208
+ )
209
+ ] }),
210
+ headerExtraHost
211
+ ),
212
+ (navigated || showSearch) && /* @__PURE__ */ u(
213
+ "div",
214
+ {
215
+ className: cn2(
216
+ "upup-flex upup-items-center upup-gap-2.5 upup-px-3 upup-py-2 upup-text-xs upup-font-medium upup-text-[#333]",
217
+ {
218
+ "upup-text-[#FAFAFA] dark:upup-text-[#FAFAFA]": dark
219
+ },
220
+ slotClasses.driveHeader
221
+ ),
222
+ children: navigated ? /* @__PURE__ */ u(Fragment, { children: [
223
+ /* @__PURE__ */ u(
224
+ "button",
225
+ {
226
+ type: "button",
227
+ "data-testid": "upup-drive-back",
228
+ "data-upup-slot": "drive-back",
229
+ "aria-label": tr.overlayBack,
230
+ onClick: () => {
231
+ setPath((prev) => prev.slice(0, -1));
232
+ },
233
+ className: cn2(
234
+ "upup-fx-hover-lift upup-fx-press upup-flex upup-h-7 upup-w-7 upup-shrink-0 upup-items-center upup-justify-center upup-rounded-lg",
235
+ dark ? "upup-text-[#e2e8f0] hover:upup-bg-white/[0.08]" : "upup-text-[#334155] hover:upup-bg-black/[0.05]"
236
+ ),
237
+ children: /* @__PURE__ */ u(Icon_default, { name: "chevron-left" })
238
+ }
239
+ ),
240
+ !searchOpen && /* @__PURE__ */ u(
241
+ "span",
242
+ {
243
+ "data-upup-slot": "drive-current-folder",
244
+ title: currentFolder == null ? void 0 : currentFolder.name,
245
+ className: "upup-min-w-0 upup-flex-1 upup-truncate upup-font-medium",
246
+ children: currentFolder == null ? void 0 : currentFolder.name
247
+ }
248
+ ),
249
+ showSearch && !searchOpen && /* @__PURE__ */ u(
250
+ "button",
251
+ {
252
+ type: "button",
253
+ "data-testid": "upup-drive-search-toggle",
254
+ "data-upup-slot": "drive-search-toggle",
255
+ "aria-label": tr.search,
256
+ "aria-expanded": false,
257
+ onClick: () => {
258
+ setSearchOpen(true);
259
+ },
260
+ className: cn2(
261
+ "upup-fx-hover-lift upup-fx-press upup-ml-auto upup-flex upup-h-7 upup-w-7 upup-shrink-0 upup-items-center upup-justify-center upup-rounded-lg",
262
+ hasFilter ? "upup-text-[#0ea5e9]" : dark ? "upup-text-[#94a3b8] hover:upup-bg-white/[0.08]" : "upup-text-[#64748b] hover:upup-bg-black/[0.05]"
263
+ ),
264
+ children: /* @__PURE__ */ u(Icon_default, { name: "search" })
265
+ }
266
+ ),
267
+ showSearch && searchOpen && searchField(true)
268
+ ] }) : showSearch && searchField(false)
269
+ }
270
+ )
271
+ ] });
272
+ }
273
+ var handleImgError = (e) => {
274
+ const svg = `<svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M14 3v4a1 1 0 0 0 1 1h4"></path><path d="M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z"></path></svg>`;
275
+ e.currentTarget.src = `data:image/svg+xml;base64,${b64EncodeUnicode(svg)}`;
276
+ e.currentTarget.onerror = null;
277
+ };
278
+ function DriveBrowserIcon({
279
+ file
280
+ }) {
281
+ const { isDark: dark } = useUploaderTheme();
282
+ const isFolder = file.isFolder;
283
+ const src = file.thumbnail;
284
+ if (isFolder)
285
+ return /* @__PURE__ */ u("i", { className: "upup-flex-grow upup-text-lg", children: /* @__PURE__ */ u(Icon_default, { name: "folder-filled", className: "upup-text-[#fbbf24]" }) });
286
+ if (!src)
287
+ return /* @__PURE__ */ u("i", { className: "upup-flex-grow upup-text-lg", children: /* @__PURE__ */ u(
288
+ Icon_default,
289
+ {
290
+ name: "file",
291
+ className: cn3({
292
+ "upup-text-[#6D6D6D] dark:upup-text-[#6D6D6D]": dark
293
+ })
294
+ }
295
+ ) });
296
+ return /* @__PURE__ */ u(
297
+ "img",
298
+ {
299
+ src,
300
+ alt: file.name,
301
+ className: "upup-h-5 upup-w-5 upup-flex-grow upup-rounded-md upup-shadow",
302
+ onError: handleImgError
303
+ }
304
+ );
305
+ }
306
+ function DriveBrowserItem({
307
+ file,
308
+ selectedFiles,
309
+ handleClick
310
+ }) {
311
+ var _a, _b;
312
+ const { isDark: dark, slotOverrides: slotClasses } = useUploaderTheme();
313
+ const isFolder = file.isFolder;
314
+ const isFileSelected = selectedFiles.filter((f) => f.id === file.id).length;
315
+ return /* @__PURE__ */ u(
316
+ "div",
317
+ {
318
+ "data-upup-slot": "drive-browser-item",
319
+ className: cn4(
320
+ // Panel-chrome row (states-tour-3 .st3-prow): translucent card +
321
+ // hairline ring, sky-tinted selection, subtle lift on hover.
322
+ "upup-fx-hover-lift upup-group upup-mb-1.5 upup-flex upup-cursor-pointer upup-items-center upup-justify-between upup-gap-2 upup-rounded-[11px] upup-px-3 upup-py-2.5 upup-ring-1",
323
+ {
324
+ "upup-font-medium": isFolder
325
+ },
326
+ isFileSelected ? dark ? "upup-bg-[#0ea5e9]/10 upup-ring-[#38bdf8]/35" : "upup-bg-[#0ea5e9]/10 upup-ring-[#0ea5e9]/40" : dark ? "upup-bg-white/[0.04] upup-ring-white/[0.06] hover:upup-bg-white/[0.07]" : "upup-bg-white upup-ring-black/[0.07] hover:upup-bg-slate-50",
327
+ {
328
+ [(_a = slotClasses.driveItemContainerDefault) != null ? _a : ""]: !isFileSelected && slotClasses.driveItemContainerDefault,
329
+ [(_b = slotClasses.driveItemContainerSelected) != null ? _b : ""]: isFileSelected && slotClasses.driveItemContainerSelected
330
+ }
331
+ ),
332
+ onClick: () => {
333
+ void handleClick(file);
334
+ },
335
+ children: /* @__PURE__ */ u(
336
+ "div",
337
+ {
338
+ className: cn4(
339
+ "upup-flex upup-items-center upup-gap-2",
340
+ slotClasses.driveItemContainerInner
341
+ ),
342
+ children: [
343
+ /* @__PURE__ */ u(DriveBrowserIcon, { file }),
344
+ /* @__PURE__ */ u(
345
+ "h1",
346
+ {
347
+ className: cn4(
348
+ "upup-text-wrap upup-break-all upup-text-xs",
349
+ {
350
+ "upup-text-[#e0e0e0] dark:upup-text-[#e0e0e0]": dark
351
+ },
352
+ slotClasses.driveItemInnerText
353
+ ),
354
+ children: file.name
355
+ }
356
+ )
357
+ ]
358
+ }
359
+ )
360
+ }
361
+ );
362
+ }
363
+ function filterItems(item, accept) {
364
+ if (item.isFolder) return true;
365
+ if (!accept || accept === "*") return true;
366
+ return accept.split(",").some((pattern) => {
367
+ const p = pattern.trim();
368
+ if (p.startsWith(".")) return item.name.endsWith(p);
369
+ if (p.endsWith("/*"))
370
+ return item.mimeType.startsWith(p.replace("/*", "/"));
371
+ return item.mimeType === p;
372
+ });
373
+ }
374
+ function DriveBrowser({
375
+ isClickLoading = false,
376
+ driveFiles,
377
+ path,
378
+ setPath,
379
+ handleClick,
380
+ selectedFiles,
381
+ showLoader,
382
+ handleSubmit,
383
+ handleCancelDownload,
384
+ onSelectCurrentFolder,
385
+ error,
386
+ hasMore = false,
387
+ isLoadingMore = false,
388
+ loadMore,
389
+ "data-upup-slot": dataUpupSlot = "drive-browser",
390
+ ...rest
391
+ }) {
392
+ var _a, _b;
393
+ const {
394
+ allowedFileTypes,
395
+ icons: { LoaderIcon }
396
+ } = useUploaderOptions();
397
+ const { isDark: dark, slotOverrides: slotClasses } = useUploaderTheme();
398
+ const { translations: tr } = useUploaderI18n();
399
+ const [searchTerm, setSearchTerm] = (0, compat_module_exports.useState)("");
400
+ const items = (_b = (_a = path[path.length - 1]) == null ? void 0 : _a.children) == null ? void 0 : _b.filter(
401
+ (item) => filterItems(item, allowedFileTypes)
402
+ );
403
+ const displayedItems = (0, compat_module_exports.useMemo)(
404
+ () => searchDriveFiles(items != null ? items : [], searchTerm) || [],
405
+ [searchTerm, items]
406
+ );
407
+ const isLoading = !error && (isClickLoading || !driveFiles);
408
+ return /* @__PURE__ */ u(
409
+ SourceViewContainer,
410
+ {
411
+ isLoading,
412
+ "data-upup-slot": dataUpupSlot,
413
+ children: isLoading ? /* @__PURE__ */ u(LoaderIcon, {}) : /* @__PURE__ */ u(
414
+ "div",
415
+ {
416
+ "data-testid": "upup-drive-browser",
417
+ className: "upup-grid upup-h-full upup-w-full upup-grid-rows-[auto,1fr,auto] upup-overflow-auto",
418
+ children: [
419
+ /* @__PURE__ */ u(
420
+ DriveBrowserHeader,
421
+ {
422
+ showSearch: !!(items == null ? void 0 : items.length),
423
+ path,
424
+ setPath,
425
+ searchTerm,
426
+ onSearch: setSearchTerm,
427
+ ...rest
428
+ }
429
+ ),
430
+ !!path && /* @__PURE__ */ u(
431
+ "div",
432
+ {
433
+ className: cn5(
434
+ "upup-h-full upup-overflow-y-auto upup-pt-2",
435
+ {
436
+ "upup-text-[#fafafa] dark:upup-text-[#fafafa]": dark
437
+ },
438
+ slotClasses.driveBody
439
+ ),
440
+ children: [
441
+ !!error && /* @__PURE__ */ u("div", { className: "upup-flex upup-h-full upup-flex-col upup-items-center upup-justify-center upup-px-6 upup-text-center", children: /* @__PURE__ */ u(
442
+ "p",
443
+ {
444
+ "data-testid": "upup-drive-error",
445
+ "data-upup-slot": "drive-error",
446
+ role: "alert",
447
+ className: "upup-text-sm upup-text-red-600 dark:upup-text-red-400",
448
+ children: t2(tr.driveLoadError, {
449
+ message: error.message
450
+ })
451
+ }
452
+ ) }),
453
+ !!displayedItems.length && /* @__PURE__ */ u("ul", { className: "upup-p-2", children: displayedItems.map((file) => {
454
+ return /* @__PURE__ */ u(
455
+ DriveBrowserItem,
456
+ {
457
+ file,
458
+ handleClick: isClickLoading || showLoader ? () => {
459
+ } : handleClick,
460
+ selectedFiles
461
+ },
462
+ file.id
463
+ );
464
+ }) }),
465
+ !displayedItems.length && !error && /* @__PURE__ */ u("div", { className: "upup-flex upup-h-full upup-flex-col upup-items-center upup-justify-center", children: /* @__PURE__ */ u("p", { className: "upup-text-xs upup-opacity-70", children: tr.noAcceptedFilesFound }) }),
466
+ hasMore && /* @__PURE__ */ u(
467
+ "button",
468
+ {
469
+ "data-testid": "upup-drive-load-more",
470
+ "data-upup-slot": "drive-load-more",
471
+ onClick: () => {
472
+ void (loadMore == null ? void 0 : loadMore());
473
+ },
474
+ disabled: isLoadingMore,
475
+ className: "upup-mx-auto upup-my-2 upup-block upup-rounded-md upup-px-3 upup-py-1.5 upup-text-sm upup-text-[#0284c7] disabled:upup-opacity-50",
476
+ children: isLoadingMore ? tr.loading : tr.loadMore
477
+ }
478
+ )
479
+ ]
480
+ }
481
+ ),
482
+ (!!selectedFiles.length || !!onSelectCurrentFolder) && !error && /* @__PURE__ */ u(
483
+ "div",
484
+ {
485
+ className: cn5(
486
+ "upup-flex upup-origin-bottom upup-items-center upup-justify-start upup-gap-4 upup-border-t upup-px-3 upup-py-2",
487
+ dark ? "upup-border-white/[0.08] upup-text-[#fafafa]" : "upup-border-black/[0.06]",
488
+ slotClasses.driveFooter
489
+ ),
490
+ children: [
491
+ !!onSelectCurrentFolder && /* @__PURE__ */ u(
492
+ "button",
493
+ {
494
+ className: cn5(
495
+ "upup-rounded-md upup-bg-transparent upup-px-3 upup-py-2 upup-text-sm upup-font-medium upup-text-[#0284c7] upup-transition-all upup-duration-300",
496
+ {
497
+ "upup-text-[#38bdf8] dark:upup-text-[#38bdf8]": dark
498
+ }
499
+ ),
500
+ onClick: () => {
501
+ void (onSelectCurrentFolder == null ? void 0 : onSelectCurrentFolder());
502
+ },
503
+ disabled: showLoader,
504
+ children: tr.selectThisFolder
505
+ }
506
+ ),
507
+ /* @__PURE__ */ u(
508
+ "button",
509
+ {
510
+ className: cn5(
511
+ "upup-rounded-md upup-bg-[#0ea5e9] upup-px-3 upup-py-2 upup-text-sm upup-font-medium upup-text-white upup-transition-all upup-duration-300",
512
+ {
513
+ "upup-animate-pulse": showLoader,
514
+ "upup-bg-[#38bdf8] dark:upup-bg-[#38bdf8]": dark
515
+ },
516
+ slotClasses.driveAddFilesButton
517
+ ),
518
+ onClick: () => {
519
+ void handleSubmit();
520
+ },
521
+ disabled: showLoader,
522
+ children: t2(
523
+ plural(
524
+ tr,
525
+ "addFiles",
526
+ selectedFiles.length
527
+ ),
528
+ { count: selectedFiles.length }
529
+ )
530
+ }
531
+ ),
532
+ /* @__PURE__ */ u(
533
+ "button",
534
+ {
535
+ className: cn5(
536
+ "upup-ml-auto upup-rounded-md upup-p-1 upup-text-sm upup-text-[#0284c7] upup-transition-all upup-duration-300",
537
+ {
538
+ "upup-text-[#38bdf8] dark:upup-text-[#38bdf8]": dark
539
+ },
540
+ slotClasses.driveCancelFilesButton
541
+ ),
542
+ onClick: handleCancelDownload,
543
+ disabled: showLoader,
544
+ children: tr.cancel
545
+ }
546
+ )
547
+ ]
548
+ }
549
+ )
550
+ ]
551
+ }
552
+ )
553
+ }
554
+ );
555
+ }
556
+ function useServerModeDrive(provider) {
557
+ const { serverUrl } = useUploaderRuntime();
558
+ const latest = (0, compat_module_exports.useRef)({ serverUrl });
559
+ latest.current = { serverUrl };
560
+ const controllerRef = (0, compat_module_exports.useRef)(
561
+ void 0
562
+ );
563
+ if (!controllerRef.current) {
564
+ controllerRef.current = new ServerModeDriveController({
565
+ provider,
566
+ serverUrl: () => latest.current.serverUrl
567
+ });
568
+ }
569
+ const controller = controllerRef.current;
570
+ const snap = C(
571
+ controller.subscribe,
572
+ controller.getSnapshot
573
+ );
574
+ (0, compat_module_exports.useEffect)(() => {
575
+ controller.init();
576
+ return () => {
577
+ controller.destroy();
578
+ };
579
+ }, [controller]);
580
+ return {
581
+ state: snap.state,
582
+ folderId: snap.folderId,
583
+ setFolderId: (id) => {
584
+ controller.setFolderId(id);
585
+ void controller.refresh();
586
+ },
587
+ search: snap.search,
588
+ setSearch: (s) => {
589
+ controller.setSearch(s);
590
+ void controller.refresh();
591
+ },
592
+ refresh: (opts) => controller.refresh(opts),
593
+ transfer: (file) => controller.transfer(file),
594
+ startAuth: () => {
595
+ controller.startAuth();
596
+ }
597
+ };
598
+ }
599
+ var PROVIDER_LABEL = {
600
+ "google-drive": "Google Drive",
601
+ "one-drive": "OneDrive",
602
+ dropbox: "Dropbox",
603
+ box: "Box"
604
+ };
605
+ function ServerModeDriveUploader({
606
+ provider,
607
+ onBack,
608
+ "data-upup-slot": dataUpupSlot = `drive-browser-${provider}`
609
+ }) {
610
+ const { isDark: dark } = useUploaderTheme();
611
+ const {
612
+ icons: { LoaderIcon }
613
+ } = useUploaderOptions();
614
+ const { translator } = useUploaderI18n();
615
+ const { state, search, setSearch, refresh, transfer, startAuth } = useServerModeDrive(provider);
616
+ const [selected, setSelected] = (0, compat_module_exports.useState)(/* @__PURE__ */ new Set());
617
+ const [transferring, setTransferring] = (0, compat_module_exports.useState)(false);
618
+ if (state.status === "reauth") {
619
+ return /* @__PURE__ */ u(
620
+ DriveAuthFallback,
621
+ {
622
+ providerName: PROVIDER_LABEL[provider],
623
+ onRetry: startAuth
624
+ }
625
+ );
626
+ }
627
+ const isLoading = state.status === "loading" || state.status === "idle";
628
+ const files = state.status === "ready" ? state.files : [];
629
+ const toggle = (id) => {
630
+ setSelected((prev) => {
631
+ const next = new Set(prev);
632
+ if (next.has(id)) next.delete(id);
633
+ else next.add(id);
634
+ return next;
635
+ });
636
+ };
637
+ const handleTransfer = async () => {
638
+ setTransferring(true);
639
+ try {
640
+ for (const file of files.filter((f) => selected.has(f.id))) {
641
+ const result = await transfer(file);
642
+ if (result.status === "reauth") {
643
+ startAuth();
644
+ return;
645
+ }
646
+ }
647
+ setSelected(/* @__PURE__ */ new Set());
648
+ onBack == null ? void 0 : onBack();
649
+ } finally {
650
+ setTransferring(false);
651
+ }
652
+ };
653
+ return /* @__PURE__ */ u(
654
+ SourceViewContainer,
655
+ {
656
+ isLoading,
657
+ "data-upup-slot": dataUpupSlot,
658
+ children: isLoading ? /* @__PURE__ */ u(LoaderIcon, {}) : /* @__PURE__ */ u(
659
+ "div",
660
+ {
661
+ "data-testid": "upup-server-drive-browser",
662
+ className: "upup-grid upup-h-full upup-w-full upup-grid-rows-[auto,1fr,auto] upup-overflow-auto",
663
+ children: [
664
+ /* @__PURE__ */ u(
665
+ "div",
666
+ {
667
+ className: cn6(
668
+ "upup-flex upup-items-center upup-gap-2 upup-border-b upup-px-3 upup-py-2.5",
669
+ dark ? "upup-border-white/[0.06] upup-text-[#e2e8f0]" : "upup-border-black/[0.06] upup-text-gray-800"
670
+ ),
671
+ "data-upup-slot": "drive-browser-header",
672
+ children: [
673
+ /* @__PURE__ */ u("span", { className: "upup-text-sm upup-font-medium", children: PROVIDER_LABEL[provider] }),
674
+ /* @__PURE__ */ u(
675
+ "input",
676
+ {
677
+ type: "search",
678
+ name: "upup-drive-search",
679
+ "aria-label": "Search",
680
+ value: search,
681
+ onChange: (e) => {
682
+ setSearch(e.target.value);
683
+ },
684
+ onKeyDown: (e) => {
685
+ if (e.key === "Enter") {
686
+ void refresh({
687
+ search: e.currentTarget.value
688
+ });
689
+ }
690
+ },
691
+ placeholder: "Search\u2026",
692
+ className: cn6(
693
+ "upup-ml-auto upup-rounded upup-border upup-px-2 upup-py-1 upup-text-xs",
694
+ dark ? "upup-border-gray-700 upup-bg-gray-800 upup-text-gray-100" : "upup-border-gray-300 upup-bg-white"
695
+ )
696
+ }
697
+ )
698
+ ]
699
+ }
700
+ ),
701
+ /* @__PURE__ */ u("div", { className: "upup-overflow-auto upup-p-2", children: [
702
+ state.status === "error" && /* @__PURE__ */ u(
703
+ "p",
704
+ {
705
+ "data-testid": "upup-drive-error",
706
+ "data-upup-slot": "drive-error",
707
+ role: "alert",
708
+ className: cn6(
709
+ "upup-p-4 upup-text-sm",
710
+ dark ? "upup-text-red-400" : "upup-text-red-600"
711
+ ),
712
+ children: state.code && translator ? translator(
713
+ `errors.${errorCodeToMessageKey(state.code)}`,
714
+ { code: state.code }
715
+ ) : state.message
716
+ }
717
+ ),
718
+ files.map((file) => {
719
+ const isSelected = selected.has(file.id);
720
+ return /* @__PURE__ */ u(
721
+ "button",
722
+ {
723
+ type: "button",
724
+ onClick: () => {
725
+ file.isFolder ? void refresh({
726
+ folderId: file.id
727
+ }) : toggle(file.id);
728
+ },
729
+ "data-upup-slot": "drive-browser-item",
730
+ "data-selected": isSelected,
731
+ className: cn6(
732
+ // Panel-chrome row (states-tour-3 .st3-prow).
733
+ "upup-fx-hover-lift upup-mb-1.5 upup-flex upup-w-full upup-items-center upup-gap-3 upup-rounded-[11px] upup-px-3 upup-py-2.5 upup-text-left upup-text-sm upup-ring-1",
734
+ isSelected ? "upup-bg-[#0ea5e9]/10 upup-ring-[#38bdf8]/35" : dark ? "upup-bg-white/[0.04] upup-text-[#e2e8f0] upup-ring-white/[0.06] hover:upup-bg-white/[0.07]" : "upup-bg-black/[0.03] upup-text-gray-800 upup-ring-black/[0.06] hover:upup-bg-black/[0.05]"
735
+ ),
736
+ children: [
737
+ /* @__PURE__ */ u(
738
+ "span",
739
+ {
740
+ className: "upup-flex upup-h-[30px] upup-w-[30px] upup-flex-none upup-items-center upup-justify-center upup-rounded-[8px] upup-bg-white/[0.05]",
741
+ "aria-hidden": "true",
742
+ children: file.isFolder ? /* @__PURE__ */ u(
743
+ "svg",
744
+ {
745
+ viewBox: "0 0 24 24",
746
+ width: "17",
747
+ height: "17",
748
+ fill: "none",
749
+ stroke: "#38bdf8",
750
+ strokeWidth: "1.7",
751
+ strokeLinecap: "round",
752
+ strokeLinejoin: "round",
753
+ children: /* @__PURE__ */ u("path", { d: "M3 7a2 2 0 0 1 2-2h4l2 2h6a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" })
754
+ }
755
+ ) : /* @__PURE__ */ u(
756
+ "svg",
757
+ {
758
+ viewBox: "0 0 24 24",
759
+ width: "17",
760
+ height: "17",
761
+ fill: "none",
762
+ stroke: dark ? "#94a3b8" : "#64748b",
763
+ strokeWidth: "1.6",
764
+ strokeLinecap: "round",
765
+ strokeLinejoin: "round",
766
+ children: [
767
+ /* @__PURE__ */ u("path", { d: "M6 3h8l4 4v13a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z" }),
768
+ /* @__PURE__ */ u("path", { d: "M14 3v4h4" })
769
+ ]
770
+ }
771
+ )
772
+ }
773
+ ),
774
+ /* @__PURE__ */ u("span", { className: "upup-flex-1 upup-truncate", children: file.name }),
775
+ file.size != null && !file.isFolder && /* @__PURE__ */ u("span", { className: "upup-text-xs upup-opacity-60", children: formatBytes(file.size) })
776
+ ]
777
+ },
778
+ file.id
779
+ );
780
+ })
781
+ ] }),
782
+ /* @__PURE__ */ u(
783
+ "div",
784
+ {
785
+ className: cn6(
786
+ "upup-flex upup-items-center upup-justify-between upup-gap-2 upup-border-t upup-p-3",
787
+ dark ? "upup-border-white/[0.06]" : "upup-border-black/[0.06]"
788
+ ),
789
+ children: [
790
+ /* @__PURE__ */ u(
791
+ "button",
792
+ {
793
+ type: "button",
794
+ onClick: onBack,
795
+ className: "upup-text-sm upup-opacity-70 hover:upup-opacity-100",
796
+ children: "Cancel"
797
+ }
798
+ ),
799
+ /* @__PURE__ */ u(
800
+ "button",
801
+ {
802
+ type: "button",
803
+ disabled: selected.size === 0 || transferring,
804
+ onClick: () => void handleTransfer(),
805
+ className: "upup-fx-press upup-rounded-lg upup-bg-[#0ea5e9] upup-px-3 upup-py-1.5 upup-text-sm upup-font-medium upup-text-white hover:upup-bg-[#0284c7] disabled:upup-opacity-50",
806
+ children: transferring ? "Uploading\u2026" : `Add files${selected.size ? ` (${selected.size})` : ""}`
807
+ }
808
+ )
809
+ ]
810
+ }
811
+ )
812
+ ]
813
+ }
814
+ )
815
+ }
816
+ );
817
+ }
818
+ function formatBytes(bytes) {
819
+ if (bytes < 1024) return `${bytes} B`;
820
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
821
+ if (bytes < 1024 * 1024 * 1024)
822
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
823
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
824
+ }
825
+
826
+ export {
827
+ DriveAuthFallback,
828
+ DriveBrowser,
829
+ ServerModeDriveUploader
830
+ };
831
+ //# sourceMappingURL=chunk-WCI3AGJV.js.map