@epicbagel/saas-kit 1.1.0 → 1.2.1
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 +36 -4
- package/THIRD_PARTY_NOTICES.md +217 -0
- package/dist/chunk-KADJ56AH.cjs +416 -0
- package/dist/chunk-M7FYGAGO.js +416 -0
- package/dist/primitives/chat.cjs +23 -6
- package/dist/primitives/chat.d.cts +19 -0
- package/dist/primitives/chat.d.ts +19 -0
- package/dist/primitives/chat.js +22 -5
- package/dist/primitives/file-dropzone.cjs +8 -2
- package/dist/primitives/file-dropzone.d.cts +66 -3
- package/dist/primitives/file-dropzone.d.ts +66 -3
- package/dist/primitives/file-dropzone.js +9 -3
- package/package.json +1 -1
- package/dist/chunk-6V4XMQ6D.js +0 -118
- package/dist/chunk-I5UQSBBZ.cjs +0 -118
package/README.md
CHANGED
|
@@ -100,10 +100,42 @@ public in 1.1.0, and these were the decisions about its props then:
|
|
|
100
100
|
`voiceAlign` (the voice hero is centred) and `ChatInput`'s `rows` and
|
|
101
101
|
`minHeightClassName` (use `size`).
|
|
102
102
|
- **Kept** as they were: the `embedded`, `application` and
|
|
103
|
-
`workspace` layouts, the voice-first empty state, the file drop
|
|
104
|
-
|
|
103
|
+
`workspace` layouts, the voice-first empty state, the empty-state file drop
|
|
104
|
+
target (`emptyFileDropzone`; since 1.2.0 the whole conversation takes
|
|
105
|
+
drops too, below), `compactEmptyState`, `threadMaxHeight` and the rest.
|
|
106
|
+
|
|
107
|
+
### File drop (1.2.0)
|
|
108
|
+
|
|
109
|
+
- **Drop anywhere on the conversation.** With `onFilesSelected`, a file
|
|
110
|
+
dragged over a Chat raises a "Drop to attach" overlay, and the drop hands
|
|
111
|
+
every file to `onFilesSelected`, the callback the composer's + menu calls:
|
|
112
|
+
your validation, your staged files, your errors. Nothing is filtered on the
|
|
113
|
+
way. `fileDrop` is `"conversation"` (the default), `"page"` (drops anywhere
|
|
114
|
+
in the document land in this Chat) or `false`; `fileDropLabel` and
|
|
115
|
+
`fileDropDescription` word the overlay. The voice-first hero switches to
|
|
116
|
+
the text composer on a drop, so the staged files show; drops are ignored
|
|
117
|
+
while `emptyPendingContent` stands in for the composer, and still stage
|
|
118
|
+
while a reply is pending, as the + menu does.
|
|
119
|
+
- **A dropped file never opens in the browser.** The guard
|
|
120
|
+
(`primitives/file-dropzone`) cancels any file drop that no drop target
|
|
121
|
+
takes, leaving native file inputs their own drops. `FileDropzone`,
|
|
122
|
+
`FileDropArea` and a Chat with `onFilesSelected` install it while they are
|
|
123
|
+
mounted (`useFileDropGuard`). To cover every page, call
|
|
124
|
+
`installFileDropGuard()` once in your app's entry, before rendering: it
|
|
125
|
+
lives outside React, so it still holds on an error boundary's fallback or
|
|
126
|
+
after a render error unmounts the root.
|
|
127
|
+
- **`FileDropArea`** is the region behind it, for any surface that takes
|
|
128
|
+
files: `onFiles` (the picker's callback), `disabled`, `scope`
|
|
129
|
+
(`"area"` | `"page"`), `label`, `description` and `icon`. Its overlay is
|
|
130
|
+
`aria-hidden`, so keep a picker in the region as the accessible path. The
|
|
131
|
+
label always shows: an area taller than the viewport centres it in the
|
|
132
|
+
part on screen, and `scope="page"` covers the viewport itself. The overlay
|
|
133
|
+
lowers when the drag ends, including a drag cancelled with Escape that
|
|
134
|
+
fires no `dragleave` (after a second without a `dragover`).
|
|
135
|
+
- The drop handling follows AI SDK Elements' `PromptInput` and its
|
|
136
|
+
`globalDrop` (Apache-2.0; see `THIRD_PARTY_NOTICES.md`).
|
|
105
137
|
|
|
106
138
|
## License
|
|
107
139
|
|
|
108
|
-
MIT. Some components and styles are adapted from shadcn/ui
|
|
109
|
-
`THIRD_PARTY_NOTICES.md`.
|
|
140
|
+
MIT. Some components and styles are adapted from shadcn/ui, and the file
|
|
141
|
+
drop handling from AI SDK Elements (Apache-2.0); see `THIRD_PARTY_NOTICES.md`.
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -51,3 +51,220 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
51
51
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
52
52
|
SOFTWARE.
|
|
53
53
|
```
|
|
54
|
+
|
|
55
|
+
## AI SDK Elements
|
|
56
|
+
|
|
57
|
+
Source: https://github.com/vercel/ai-elements (`packages/elements/src/prompt-input.tsx`,
|
|
58
|
+
commit `ca8be600`)
|
|
59
|
+
|
|
60
|
+
The file drop handling in these modules follows the `PromptInput` component of
|
|
61
|
+
AI SDK Elements: a drag that carries files is accepted, its drop hands over the
|
|
62
|
+
dropped files, and the `globalDrop` option takes drops anywhere in the
|
|
63
|
+
document. The code was modified: nothing is filtered, a drag shows an overlay,
|
|
64
|
+
drags that start in the page are ignored, and a window-level guard cancels any
|
|
65
|
+
file drop that nothing takes. The compiled output under `dist/` includes code
|
|
66
|
+
derived from it.
|
|
67
|
+
|
|
68
|
+
- `primitives/file-dropzone`: `FileDropArea` (its `scope="page"` is
|
|
69
|
+
`globalDrop`) and `useFileDropGuard`
|
|
70
|
+
- `primitives/chat`: the conversation's file drop (`fileDrop`), built on
|
|
71
|
+
`FileDropArea`
|
|
72
|
+
|
|
73
|
+
AI SDK Elements carries this notice:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Copyright 2023 Vercel, Inc.
|
|
77
|
+
|
|
78
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
79
|
+
you may not use this file except in compliance with the License.
|
|
80
|
+
You may obtain a copy of the License at
|
|
81
|
+
|
|
82
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
83
|
+
|
|
84
|
+
Unless required by applicable law or agreed to in writing, software
|
|
85
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
86
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
87
|
+
See the License for the specific language governing permissions and
|
|
88
|
+
limitations under the License.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The Apache License, Version 2.0:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
Apache License
|
|
95
|
+
Version 2.0, January 2004
|
|
96
|
+
http://www.apache.org/licenses/
|
|
97
|
+
|
|
98
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
99
|
+
|
|
100
|
+
1. Definitions.
|
|
101
|
+
|
|
102
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
103
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
104
|
+
|
|
105
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
106
|
+
the copyright owner that is granting the License.
|
|
107
|
+
|
|
108
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
109
|
+
other entities that control, are controlled by, or are under common
|
|
110
|
+
control with that entity. For the purposes of this definition,
|
|
111
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
112
|
+
direction or management of such entity, whether by contract or
|
|
113
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
114
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
115
|
+
|
|
116
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
117
|
+
exercising permissions granted by this License.
|
|
118
|
+
|
|
119
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
120
|
+
including but not limited to software source code, documentation
|
|
121
|
+
source, and configuration files.
|
|
122
|
+
|
|
123
|
+
"Object" form shall mean any form resulting from mechanical
|
|
124
|
+
transformation or translation of a Source form, including but
|
|
125
|
+
not limited to compiled object code, generated documentation,
|
|
126
|
+
and conversions to other media types.
|
|
127
|
+
|
|
128
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
129
|
+
Object form, made available under the License, as indicated by a
|
|
130
|
+
copyright notice that is included in or attached to the work
|
|
131
|
+
(an example is provided in the Appendix below).
|
|
132
|
+
|
|
133
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
134
|
+
form, that is based on (or derived from) the Work and for which the
|
|
135
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
136
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
137
|
+
of this License, Derivative Works shall not include works that remain
|
|
138
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
139
|
+
the Work and Derivative Works thereof.
|
|
140
|
+
|
|
141
|
+
"Contribution" shall mean any work of authorship, including
|
|
142
|
+
the original version of the Work and any modifications or additions
|
|
143
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
144
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
145
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
146
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
147
|
+
means any form of electronic, verbal, or written communication sent
|
|
148
|
+
to the Licensor or its representatives, including but not limited to
|
|
149
|
+
communication on electronic mailing lists, source code control systems,
|
|
150
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
151
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
152
|
+
excluding communication that is conspicuously marked or otherwise
|
|
153
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
154
|
+
|
|
155
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
156
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
157
|
+
subsequently incorporated within the Work.
|
|
158
|
+
|
|
159
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
160
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
161
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
162
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
163
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
164
|
+
Work and such Derivative Works in Source or Object form.
|
|
165
|
+
|
|
166
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
167
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
168
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
169
|
+
(except as stated in this section) patent license to make, have made,
|
|
170
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
171
|
+
where such license applies only to those patent claims licensable
|
|
172
|
+
by such Contributor that are necessarily infringed by their
|
|
173
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
174
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
175
|
+
institute patent litigation against any entity (including a
|
|
176
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
177
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
178
|
+
or contributory patent infringement, then any patent licenses
|
|
179
|
+
granted to You under this License for that Work shall terminate
|
|
180
|
+
as of the date such litigation is filed.
|
|
181
|
+
|
|
182
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
183
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
184
|
+
modifications, and in Source or Object form, provided that You
|
|
185
|
+
meet the following conditions:
|
|
186
|
+
|
|
187
|
+
(a) You must give any other recipients of the Work or
|
|
188
|
+
Derivative Works a copy of this License; and
|
|
189
|
+
|
|
190
|
+
(b) You must cause any modified files to carry prominent notices
|
|
191
|
+
stating that You changed the files; and
|
|
192
|
+
|
|
193
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
194
|
+
that You distribute, all copyright, patent, trademark, and
|
|
195
|
+
attribution notices from the Source form of the Work,
|
|
196
|
+
excluding those notices that do not pertain to any part of
|
|
197
|
+
the Derivative Works; and
|
|
198
|
+
|
|
199
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
200
|
+
distribution, then any Derivative Works that You distribute must
|
|
201
|
+
include a readable copy of the attribution notices contained
|
|
202
|
+
within such NOTICE file, excluding those notices that do not
|
|
203
|
+
pertain to any part of the Derivative Works, in at least one
|
|
204
|
+
of the following places: within a NOTICE text file distributed
|
|
205
|
+
as part of the Derivative Works; within the Source form or
|
|
206
|
+
documentation, if provided along with the Derivative Works; or,
|
|
207
|
+
within a display generated by the Derivative Works, if and
|
|
208
|
+
wherever such third-party notices normally appear. The contents
|
|
209
|
+
of the NOTICE file are for informational purposes only and
|
|
210
|
+
do not modify the License. You may add Your own attribution
|
|
211
|
+
notices within Derivative Works that You distribute, alongside
|
|
212
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
213
|
+
that such additional attribution notices cannot be construed
|
|
214
|
+
as modifying the License.
|
|
215
|
+
|
|
216
|
+
You may add Your own copyright statement to Your modifications and
|
|
217
|
+
may provide additional or different license terms and conditions
|
|
218
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
219
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
220
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
221
|
+
the conditions stated in this License.
|
|
222
|
+
|
|
223
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
224
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
225
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
226
|
+
this License, without any additional terms or conditions.
|
|
227
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
228
|
+
the terms of any separate license agreement you may have executed
|
|
229
|
+
with Licensor regarding such Contributions.
|
|
230
|
+
|
|
231
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
232
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
233
|
+
except as required for reasonable and customary use in describing the
|
|
234
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
235
|
+
|
|
236
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
237
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
238
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
239
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
240
|
+
implied, including, without limitation, any warranties or conditions
|
|
241
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
242
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
243
|
+
appropriateness of using or redistributing the Work and assume any
|
|
244
|
+
risks associated with Your exercise of permissions under this License.
|
|
245
|
+
|
|
246
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
247
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
248
|
+
unless required by applicable law (such as deliberate and grossly
|
|
249
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
250
|
+
liable to You for damages, including any direct, indirect, special,
|
|
251
|
+
incidental, or consequential damages of any character arising as a
|
|
252
|
+
result of this License or out of the use or inability to use the
|
|
253
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
254
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
255
|
+
other commercial damages or losses), even if such Contributor
|
|
256
|
+
has been advised of the possibility of such damages.
|
|
257
|
+
|
|
258
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
259
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
260
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
261
|
+
or other liability obligations and/or rights consistent with this
|
|
262
|
+
License. However, in accepting such obligations, You may act only
|
|
263
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
264
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
265
|
+
defend, and hold each Contributor harmless for any liability
|
|
266
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
267
|
+
of your accepting any such warranty or additional liability.
|
|
268
|
+
|
|
269
|
+
END OF TERMS AND CONDITIONS
|
|
270
|
+
```
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk373W6VADcjs = require('./chunk-373W6VAD.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkU2NES7VRcjs = require('./chunk-U2NES7VR.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkL4DH72UFcjs = require('./chunk-L4DH72UF.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkKWLSBTB2cjs = require('./chunk-KWLSBTB2.cjs');
|
|
16
|
+
|
|
17
|
+
// src/primitives/file-dropzone.tsx
|
|
18
|
+
var _lucidereact = require('lucide-react');
|
|
19
|
+
var _reactdom = require('react-dom');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _react = require('react');
|
|
27
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
28
|
+
function FileDropzone({
|
|
29
|
+
onFile,
|
|
30
|
+
onFiles,
|
|
31
|
+
multiple = false,
|
|
32
|
+
accept,
|
|
33
|
+
disabled = false,
|
|
34
|
+
busy: externalBusy = false,
|
|
35
|
+
label = "Drop a file, or choose one",
|
|
36
|
+
description,
|
|
37
|
+
busyLabel = "Reading file\u2026",
|
|
38
|
+
icon,
|
|
39
|
+
variant = "dropzone",
|
|
40
|
+
className
|
|
41
|
+
}) {
|
|
42
|
+
const inputRef = _react.useRef.call(void 0, null);
|
|
43
|
+
const [dragging, setDragging] = _react.useState.call(void 0, false);
|
|
44
|
+
const [internalBusy, setInternalBusy] = _react.useState.call(void 0, false);
|
|
45
|
+
const busy = externalBusy || internalBusy;
|
|
46
|
+
useFileDropGuard();
|
|
47
|
+
async function select(files) {
|
|
48
|
+
if (files.length === 0 || disabled || busy) return;
|
|
49
|
+
setInternalBusy(true);
|
|
50
|
+
try {
|
|
51
|
+
if (multiple) {
|
|
52
|
+
await _optionalChain([onFiles, 'optionalCall', _ => _(files)]);
|
|
53
|
+
} else {
|
|
54
|
+
const first = files[0];
|
|
55
|
+
if (first) await _optionalChain([onFile, 'optionalCall', _2 => _2(first)]);
|
|
56
|
+
}
|
|
57
|
+
} finally {
|
|
58
|
+
setInternalBusy(false);
|
|
59
|
+
if (inputRef.current) inputRef.current.value = "";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function onDrop(event) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
setDragging(false);
|
|
65
|
+
void select(Array.from(_nullishCoalesce(event.dataTransfer.files, () => ( []))));
|
|
66
|
+
}
|
|
67
|
+
const trigger = /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
68
|
+
_chunkL4DH72UFcjs.Button,
|
|
69
|
+
{
|
|
70
|
+
type: "button",
|
|
71
|
+
"data-file-dropzone": "true",
|
|
72
|
+
variant: "outline",
|
|
73
|
+
size: variant === "icon" ? "icon" : "default",
|
|
74
|
+
"aria-label": variant === "icon" ? String(busy ? busyLabel : label) : void 0,
|
|
75
|
+
disabled: disabled || busy,
|
|
76
|
+
onClick: () => _optionalChain([inputRef, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.click, 'call', _5 => _5()]),
|
|
77
|
+
onDragEnter: (event) => {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
setDragging(true);
|
|
80
|
+
},
|
|
81
|
+
onDragOver: (event) => {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
setDragging(true);
|
|
84
|
+
},
|
|
85
|
+
onDragLeave: () => setDragging(false),
|
|
86
|
+
onDrop,
|
|
87
|
+
className: _chunkKWLSBTB2cjs.cn.call(void 0,
|
|
88
|
+
variant === "dropzone" ? "h-auto w-full flex-col whitespace-normal border-2 border-dashed px-6 py-8 text-center" : variant === "button" ? "w-fit" : "",
|
|
89
|
+
dragging && "border-primary bg-primary/5",
|
|
90
|
+
className
|
|
91
|
+
),
|
|
92
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
93
|
+
FileDropPrompt,
|
|
94
|
+
{
|
|
95
|
+
variant,
|
|
96
|
+
icon: busy ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Loader2, { className: "h-5 w-5 animate-spin" }) : _nullishCoalesce(icon, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.FileUp, { className: "h-5 w-5" }))),
|
|
97
|
+
label: busy ? busyLabel : label,
|
|
98
|
+
description
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
104
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
105
|
+
"input",
|
|
106
|
+
{
|
|
107
|
+
ref: inputRef,
|
|
108
|
+
type: "file",
|
|
109
|
+
accept,
|
|
110
|
+
multiple,
|
|
111
|
+
disabled: disabled || busy,
|
|
112
|
+
onChange: (event) => void select(Array.from(_nullishCoalesce(event.target.files, () => ( [])))),
|
|
113
|
+
className: "sr-only",
|
|
114
|
+
tabIndex: -1,
|
|
115
|
+
"aria-hidden": "true"
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
variant === "icon" && description ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkU2NES7VRcjs.Tooltip, { children: [
|
|
119
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkU2NES7VRcjs.TooltipTrigger, { asChild: true, children: trigger }),
|
|
120
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkU2NES7VRcjs.TooltipContent, { children: description })
|
|
121
|
+
] }) : trigger
|
|
122
|
+
] });
|
|
123
|
+
}
|
|
124
|
+
function carriesFiles(data) {
|
|
125
|
+
if (!data) return false;
|
|
126
|
+
return Array.from(_nullishCoalesce(data.types, () => ( []))).includes("Files") || (_nullishCoalesce(_optionalChain([data, 'access', _6 => _6.files, 'optionalAccess', _7 => _7.length]), () => ( 0))) > 0;
|
|
127
|
+
}
|
|
128
|
+
function isNativeFileInput(target) {
|
|
129
|
+
const element = target;
|
|
130
|
+
return _optionalChain([element, 'optionalAccess', _8 => _8.tagName]) === "INPUT" && element.type === "file";
|
|
131
|
+
}
|
|
132
|
+
var inPageDrag = false;
|
|
133
|
+
var inPageDragUsers = 0;
|
|
134
|
+
var markInPageDrag = () => {
|
|
135
|
+
inPageDrag = true;
|
|
136
|
+
};
|
|
137
|
+
var clearInPageDrag = () => {
|
|
138
|
+
inPageDrag = false;
|
|
139
|
+
};
|
|
140
|
+
var clearAfterDrop = () => {
|
|
141
|
+
window.setTimeout(clearInPageDrag, 0);
|
|
142
|
+
};
|
|
143
|
+
var clearOnMove = () => {
|
|
144
|
+
if (inPageDrag) inPageDrag = false;
|
|
145
|
+
};
|
|
146
|
+
function trackInPageDrags() {
|
|
147
|
+
if (inPageDragUsers++ === 0) {
|
|
148
|
+
window.addEventListener("dragstart", markInPageDrag, true);
|
|
149
|
+
window.addEventListener("dragend", clearInPageDrag, true);
|
|
150
|
+
window.addEventListener("drop", clearAfterDrop);
|
|
151
|
+
window.addEventListener("mousemove", clearOnMove, { passive: true });
|
|
152
|
+
}
|
|
153
|
+
return () => {
|
|
154
|
+
if (--inPageDragUsers > 0) return;
|
|
155
|
+
window.removeEventListener("dragstart", markInPageDrag, true);
|
|
156
|
+
window.removeEventListener("dragend", clearInPageDrag, true);
|
|
157
|
+
window.removeEventListener("drop", clearAfterDrop);
|
|
158
|
+
window.removeEventListener("mousemove", clearOnMove);
|
|
159
|
+
inPageDrag = false;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function isUnclaimedFileDrag(event) {
|
|
163
|
+
return !event.defaultPrevented && !inPageDrag && carriesFiles(event.dataTransfer) && !isNativeFileInput(event.target);
|
|
164
|
+
}
|
|
165
|
+
function installFileDropGuard() {
|
|
166
|
+
if (typeof window === "undefined") return () => void 0;
|
|
167
|
+
const release = trackInPageDrags();
|
|
168
|
+
const onDragOver = (event) => {
|
|
169
|
+
if (!isUnclaimedFileDrag(event)) return;
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = "none";
|
|
172
|
+
};
|
|
173
|
+
const onDrop = (event) => {
|
|
174
|
+
if (isUnclaimedFileDrag(event)) event.preventDefault();
|
|
175
|
+
};
|
|
176
|
+
window.addEventListener("dragover", onDragOver);
|
|
177
|
+
window.addEventListener("drop", onDrop);
|
|
178
|
+
let installed = true;
|
|
179
|
+
return () => {
|
|
180
|
+
if (!installed) return;
|
|
181
|
+
installed = false;
|
|
182
|
+
window.removeEventListener("dragover", onDragOver);
|
|
183
|
+
window.removeEventListener("drop", onDrop);
|
|
184
|
+
release();
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function useFileDropGuard(enabled = true) {
|
|
188
|
+
_react.useEffect.call(void 0, () => enabled ? installFileDropGuard() : void 0, [enabled]);
|
|
189
|
+
}
|
|
190
|
+
function FileDropPrompt({
|
|
191
|
+
icon,
|
|
192
|
+
label,
|
|
193
|
+
description,
|
|
194
|
+
variant = "dropzone"
|
|
195
|
+
}) {
|
|
196
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
197
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: _chunkKWLSBTB2cjs.cn.call(void 0,
|
|
198
|
+
"flex items-center justify-center text-muted-foreground",
|
|
199
|
+
variant === "dropzone" && "mb-2 h-10 w-10 rounded-full bg-muted"
|
|
200
|
+
), children: icon }),
|
|
201
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: variant === "icon" ? "sr-only" : "font-medium", children: label }),
|
|
202
|
+
description && variant === "dropzone" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk373W6VADcjs.Text, { variant: "muted", className: "mt-1 max-w-md text-xs", children: description })
|
|
203
|
+
] });
|
|
204
|
+
}
|
|
205
|
+
var DRAG_HEARTBEAT_MS = 1e3;
|
|
206
|
+
function visibleBand(element) {
|
|
207
|
+
const rect = element.getBoundingClientRect();
|
|
208
|
+
const viewport = window.innerHeight;
|
|
209
|
+
if (rect.top >= 0 && rect.bottom <= viewport) return null;
|
|
210
|
+
const top = Math.max(rect.top, 0);
|
|
211
|
+
const bottom = Math.min(rect.bottom, viewport);
|
|
212
|
+
return bottom > top ? { top: top - rect.top, height: bottom - top } : null;
|
|
213
|
+
}
|
|
214
|
+
var FileDropArea = _react.forwardRef.call(void 0, function FileDropArea2({
|
|
215
|
+
onFiles,
|
|
216
|
+
disabled = false,
|
|
217
|
+
scope = "area",
|
|
218
|
+
label = "Drop to attach",
|
|
219
|
+
description,
|
|
220
|
+
icon,
|
|
221
|
+
className,
|
|
222
|
+
children,
|
|
223
|
+
onDragEnter,
|
|
224
|
+
onDragOver,
|
|
225
|
+
onDragLeave,
|
|
226
|
+
...props
|
|
227
|
+
}, ref) {
|
|
228
|
+
const active = Boolean(onFiles) && !disabled;
|
|
229
|
+
const [dragging, setDragging] = _react.useState.call(void 0, false);
|
|
230
|
+
const [band, setBand] = _react.useState.call(void 0, null);
|
|
231
|
+
const root = _react.useRef.call(void 0, null);
|
|
232
|
+
const entered = _react.useRef.call(void 0, []);
|
|
233
|
+
useFileDropGuard(Boolean(onFiles));
|
|
234
|
+
const setRoot = _react.useCallback.call(void 0,
|
|
235
|
+
(node) => {
|
|
236
|
+
root.current = node;
|
|
237
|
+
if (typeof ref === "function") ref(node);
|
|
238
|
+
else if (ref) ref.current = node;
|
|
239
|
+
},
|
|
240
|
+
[ref]
|
|
241
|
+
);
|
|
242
|
+
const reset = _react.useCallback.call(void 0, () => {
|
|
243
|
+
entered.current = [];
|
|
244
|
+
setDragging(false);
|
|
245
|
+
}, []);
|
|
246
|
+
const enter = _react.useCallback.call(void 0, (target) => {
|
|
247
|
+
if (target && !entered.current.includes(target)) entered.current.push(target);
|
|
248
|
+
setDragging(true);
|
|
249
|
+
}, []);
|
|
250
|
+
const leave = _react.useCallback.call(void 0, (target, container) => {
|
|
251
|
+
entered.current = entered.current.filter(
|
|
252
|
+
(node) => node !== target && node instanceof Node && node.isConnected && container.contains(node)
|
|
253
|
+
);
|
|
254
|
+
if (entered.current.length === 0) setDragging(false);
|
|
255
|
+
}, []);
|
|
256
|
+
const deliver = _react.useCallback.call(void 0,
|
|
257
|
+
(data) => {
|
|
258
|
+
const files = Array.from(_nullishCoalesce(_optionalChain([data, 'optionalAccess', _9 => _9.files]), () => ( [])));
|
|
259
|
+
if (files.length > 0) void _optionalChain([onFiles, 'optionalCall', _10 => _10(files)]);
|
|
260
|
+
},
|
|
261
|
+
[onFiles]
|
|
262
|
+
);
|
|
263
|
+
_react.useEffect.call(void 0, () => {
|
|
264
|
+
if (scope !== "page" || !active) return;
|
|
265
|
+
const onEnter = (event) => {
|
|
266
|
+
if (!isUnclaimedFileDrag(event)) return;
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
enter(event.target);
|
|
269
|
+
};
|
|
270
|
+
const onOver = (event) => {
|
|
271
|
+
if (!isUnclaimedFileDrag(event)) return;
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = "copy";
|
|
274
|
+
if (entered.current.length === 0) enter(event.target);
|
|
275
|
+
};
|
|
276
|
+
const onLeave = (event) => leave(event.target, document);
|
|
277
|
+
const onDrop = (event) => {
|
|
278
|
+
reset();
|
|
279
|
+
if (!isUnclaimedFileDrag(event)) return;
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
deliver(event.dataTransfer);
|
|
282
|
+
};
|
|
283
|
+
document.addEventListener("dragenter", onEnter);
|
|
284
|
+
document.addEventListener("dragover", onOver);
|
|
285
|
+
document.addEventListener("dragleave", onLeave);
|
|
286
|
+
document.addEventListener("drop", onDrop);
|
|
287
|
+
return () => {
|
|
288
|
+
document.removeEventListener("dragenter", onEnter);
|
|
289
|
+
document.removeEventListener("dragover", onOver);
|
|
290
|
+
document.removeEventListener("dragleave", onLeave);
|
|
291
|
+
document.removeEventListener("drop", onDrop);
|
|
292
|
+
};
|
|
293
|
+
}, [active, deliver, enter, leave, reset, scope]);
|
|
294
|
+
_react.useEffect.call(void 0, () => {
|
|
295
|
+
if (!dragging) return;
|
|
296
|
+
let heartbeat = window.setTimeout(reset, DRAG_HEARTBEAT_MS);
|
|
297
|
+
const onDragOverAnywhere = () => {
|
|
298
|
+
window.clearTimeout(heartbeat);
|
|
299
|
+
heartbeat = window.setTimeout(reset, DRAG_HEARTBEAT_MS);
|
|
300
|
+
};
|
|
301
|
+
const onLeaveWindow = (event) => {
|
|
302
|
+
if (event.relatedTarget) return;
|
|
303
|
+
const { clientX: x, clientY: y } = event;
|
|
304
|
+
if (x <= 0 || y <= 0 || x >= window.innerWidth || y >= window.innerHeight) reset();
|
|
305
|
+
};
|
|
306
|
+
window.addEventListener("dragover", onDragOverAnywhere, true);
|
|
307
|
+
window.addEventListener("drop", reset);
|
|
308
|
+
window.addEventListener("dragend", reset);
|
|
309
|
+
window.addEventListener("dragleave", onLeaveWindow);
|
|
310
|
+
window.addEventListener("mousemove", reset, { passive: true });
|
|
311
|
+
return () => {
|
|
312
|
+
window.clearTimeout(heartbeat);
|
|
313
|
+
window.removeEventListener("dragover", onDragOverAnywhere, true);
|
|
314
|
+
window.removeEventListener("drop", reset);
|
|
315
|
+
window.removeEventListener("dragend", reset);
|
|
316
|
+
window.removeEventListener("dragleave", onLeaveWindow);
|
|
317
|
+
window.removeEventListener("mousemove", reset);
|
|
318
|
+
};
|
|
319
|
+
}, [dragging, reset]);
|
|
320
|
+
const showOverlay = dragging && active;
|
|
321
|
+
_react.useEffect.call(void 0, () => {
|
|
322
|
+
if (!showOverlay || scope !== "area") return;
|
|
323
|
+
const measure = () => {
|
|
324
|
+
if (root.current) setBand(visibleBand(root.current));
|
|
325
|
+
};
|
|
326
|
+
measure();
|
|
327
|
+
window.addEventListener("scroll", measure, { capture: true, passive: true });
|
|
328
|
+
window.addEventListener("resize", measure);
|
|
329
|
+
return () => {
|
|
330
|
+
window.removeEventListener("scroll", measure, { capture: true });
|
|
331
|
+
window.removeEventListener("resize", measure);
|
|
332
|
+
setBand(null);
|
|
333
|
+
};
|
|
334
|
+
}, [scope, showOverlay]);
|
|
335
|
+
const handlesHere = active && scope === "area";
|
|
336
|
+
const prompt = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FileDropPrompt, { icon: _nullishCoalesce(icon, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.FileUp, { className: "h-5 w-5" }))), label, description });
|
|
337
|
+
let overlay = null;
|
|
338
|
+
if (showOverlay && scope === "page" && typeof document !== "undefined") {
|
|
339
|
+
overlay = _reactdom.createPortal.call(void 0,
|
|
340
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
341
|
+
"div",
|
|
342
|
+
{
|
|
343
|
+
"data-slot": "file-drop-overlay",
|
|
344
|
+
"data-scope": "page",
|
|
345
|
+
"aria-hidden": "true",
|
|
346
|
+
className: "pointer-events-none fixed inset-0 z-50 bg-background/80 p-3 supports-backdrop-filter:backdrop-blur-sm motion-safe:animate-in motion-safe:fade-in-0",
|
|
347
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-full flex-col items-center justify-center rounded-xl border-2 border-dashed border-primary p-6 text-center text-sm", children: prompt })
|
|
348
|
+
}
|
|
349
|
+
),
|
|
350
|
+
document.body
|
|
351
|
+
);
|
|
352
|
+
} else if (showOverlay && scope === "area") {
|
|
353
|
+
overlay = /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
354
|
+
"div",
|
|
355
|
+
{
|
|
356
|
+
"data-slot": "file-drop-overlay",
|
|
357
|
+
"data-scope": "area",
|
|
358
|
+
"aria-hidden": "true",
|
|
359
|
+
className: "absolute inset-0 z-30 rounded-[inherit] border-2 border-dashed border-primary bg-background/90 text-sm supports-backdrop-filter:backdrop-blur-sm motion-safe:animate-in motion-safe:fade-in-0 [&_*]:pointer-events-none",
|
|
360
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
361
|
+
"div",
|
|
362
|
+
{
|
|
363
|
+
"data-slot": "file-drop-prompt",
|
|
364
|
+
className: "absolute inset-x-0 flex flex-col items-center justify-center p-6 text-center",
|
|
365
|
+
style: _nullishCoalesce(band, () => ( { top: 0, height: "100%" })),
|
|
366
|
+
children: prompt
|
|
367
|
+
}
|
|
368
|
+
)
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
373
|
+
"div",
|
|
374
|
+
{
|
|
375
|
+
ref: setRoot,
|
|
376
|
+
"data-file-drop": showOverlay ? "active" : void 0,
|
|
377
|
+
className: _chunkKWLSBTB2cjs.cn.call(void 0, "relative", className),
|
|
378
|
+
...props,
|
|
379
|
+
onDragEnter: (event) => {
|
|
380
|
+
_optionalChain([onDragEnter, 'optionalCall', _11 => _11(event)]);
|
|
381
|
+
if (!handlesHere || !isUnclaimedFileDrag(event.nativeEvent)) return;
|
|
382
|
+
event.preventDefault();
|
|
383
|
+
enter(event.target);
|
|
384
|
+
},
|
|
385
|
+
onDragOver: (event) => {
|
|
386
|
+
_optionalChain([onDragOver, 'optionalCall', _12 => _12(event)]);
|
|
387
|
+
if (!handlesHere || !isUnclaimedFileDrag(event.nativeEvent)) return;
|
|
388
|
+
event.preventDefault();
|
|
389
|
+
event.dataTransfer.dropEffect = "copy";
|
|
390
|
+
if (entered.current.length === 0) enter(event.target);
|
|
391
|
+
},
|
|
392
|
+
onDragLeave: (event) => {
|
|
393
|
+
_optionalChain([onDragLeave, 'optionalCall', _13 => _13(event)]);
|
|
394
|
+
if (scope === "area") leave(event.target, event.currentTarget);
|
|
395
|
+
},
|
|
396
|
+
onDrop: (event) => {
|
|
397
|
+
if (scope !== "area") return;
|
|
398
|
+
reset();
|
|
399
|
+
if (!onFiles || !isUnclaimedFileDrag(event.nativeEvent)) return;
|
|
400
|
+
event.preventDefault();
|
|
401
|
+
if (!disabled) deliver(event.dataTransfer);
|
|
402
|
+
},
|
|
403
|
+
children: [
|
|
404
|
+
children,
|
|
405
|
+
overlay
|
|
406
|
+
]
|
|
407
|
+
}
|
|
408
|
+
);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
exports.FileDropzone = FileDropzone; exports.installFileDropGuard = installFileDropGuard; exports.useFileDropGuard = useFileDropGuard; exports.FileDropArea = FileDropArea;
|