@uipath/apollo-wind 2.68.0 → 2.70.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 (80) hide show
  1. package/dist/components/custom/chat-first-experience.cjs +3 -3
  2. package/dist/components/custom/chat-first-experience.js +3 -3
  3. package/dist/components/custom/demo-composer.cjs +80 -0
  4. package/dist/components/custom/demo-composer.d.ts +11 -0
  5. package/dist/components/custom/demo-composer.js +46 -0
  6. package/dist/components/custom/panel-flow.cjs +2 -2
  7. package/dist/components/custom/panel-flow.js +2 -2
  8. package/dist/components/ui/chat-composer.cjs +429 -0
  9. package/dist/components/ui/chat-composer.d.ts +157 -0
  10. package/dist/components/ui/chat-composer.js +359 -0
  11. package/dist/components/ui/citation.cjs +188 -0
  12. package/dist/components/ui/citation.d.ts +42 -0
  13. package/dist/components/ui/citation.js +148 -0
  14. package/dist/components/ui/code-block.cjs +375 -0
  15. package/dist/components/ui/code-block.d.ts +38 -0
  16. package/dist/components/ui/code-block.js +307 -0
  17. package/dist/components/ui/dropzone-overlay.cjs +142 -0
  18. package/dist/components/ui/dropzone-overlay.d.ts +27 -0
  19. package/dist/components/ui/dropzone-overlay.js +105 -0
  20. package/dist/components/ui/file-upload.cjs +5 -29
  21. package/dist/components/ui/file-upload.js +2 -26
  22. package/dist/components/ui/file-validation.cjs +91 -0
  23. package/dist/components/ui/file-validation.d.ts +24 -0
  24. package/dist/components/ui/file-validation.js +51 -0
  25. package/dist/components/ui/hover-card.cjs +15 -8
  26. package/dist/components/ui/hover-card.d.ts +4 -1
  27. package/dist/components/ui/hover-card.js +16 -9
  28. package/dist/components/ui/index.cjs +330 -198
  29. package/dist/components/ui/index.d.ts +12 -0
  30. package/dist/components/ui/index.js +12 -0
  31. package/dist/components/ui/input-group.cjs +1 -1
  32. package/dist/components/ui/input-group.d.ts +2 -1
  33. package/dist/components/ui/input-group.js +1 -1
  34. package/dist/components/ui/json-tree-view/JsonTree.cjs +2 -2
  35. package/dist/components/ui/json-tree-view/JsonTree.js +1 -1
  36. package/dist/components/ui/json-tree-view/index.cjs +26 -23
  37. package/dist/components/ui/json-tree-view/index.d.ts +2 -2
  38. package/dist/components/ui/json-tree-view/index.js +2 -2
  39. package/dist/components/ui/live-region.cjs +106 -0
  40. package/dist/components/ui/live-region.d.ts +31 -0
  41. package/dist/components/ui/live-region.js +72 -0
  42. package/dist/components/ui/loading-dots.cjs +95 -0
  43. package/dist/components/ui/loading-dots.d.ts +21 -0
  44. package/dist/components/ui/loading-dots.js +55 -0
  45. package/dist/components/ui/markdown.cjs +428 -0
  46. package/dist/components/ui/markdown.d.ts +55 -0
  47. package/dist/components/ui/markdown.js +378 -0
  48. package/dist/components/ui/message-actions.cjs +302 -0
  49. package/dist/components/ui/message-actions.d.ts +102 -0
  50. package/dist/components/ui/message-actions.js +241 -0
  51. package/dist/components/ui/message.cjs +1 -1
  52. package/dist/components/ui/message.d.ts +2 -0
  53. package/dist/components/ui/message.js +1 -1
  54. package/dist/components/ui/sources.cjs +175 -0
  55. package/dist/components/ui/sources.d.ts +44 -0
  56. package/dist/components/ui/sources.js +132 -0
  57. package/dist/components/ui/thinking-indicator.cjs +146 -0
  58. package/dist/components/ui/thinking-indicator.d.ts +38 -0
  59. package/dist/components/ui/thinking-indicator.js +106 -0
  60. package/dist/components/ui/tool-call.cjs +359 -0
  61. package/dist/components/ui/tool-call.d.ts +75 -0
  62. package/dist/components/ui/tool-call.js +301 -0
  63. package/dist/index.cjs +433 -253
  64. package/dist/index.d.ts +24 -0
  65. package/dist/index.js +13 -1
  66. package/dist/lib/index.cjs +8 -1
  67. package/dist/lib/index.d.ts +1 -0
  68. package/dist/lib/index.js +2 -1
  69. package/dist/lib/url.cjs +54 -0
  70. package/dist/lib/url.d.ts +8 -0
  71. package/dist/lib/url.js +17 -0
  72. package/dist/styles.css +363 -35
  73. package/dist/tailwind.utilities.css +21 -0
  74. package/package.json +7 -1
  75. package/dist/components/custom/chat-composer.cjs +0 -134
  76. package/dist/components/custom/chat-composer.d.ts +0 -14
  77. package/dist/components/custom/chat-composer.js +0 -100
  78. /package/dist/{components/ui/json-tree-view → lib}/clipboard.cjs +0 -0
  79. /package/dist/{components/ui/json-tree-view → lib}/clipboard.d.ts +0 -0
  80. /package/dist/{components/ui/json-tree-view → lib}/clipboard.js +0 -0
@@ -0,0 +1,307 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Check, Copy } from "lucide-react";
3
+ import { forwardRef, memo, useEffect, useRef, useState } from "react";
4
+ import bash from "react-syntax-highlighter/dist/esm/languages/prism/bash.js";
5
+ import csharp from "react-syntax-highlighter/dist/esm/languages/prism/csharp.js";
6
+ import css from "react-syntax-highlighter/dist/esm/languages/prism/css.js";
7
+ import diff from "react-syntax-highlighter/dist/esm/languages/prism/diff.js";
8
+ import go from "react-syntax-highlighter/dist/esm/languages/prism/go.js";
9
+ import java from "react-syntax-highlighter/dist/esm/languages/prism/java.js";
10
+ import javascript from "react-syntax-highlighter/dist/esm/languages/prism/javascript.js";
11
+ import json from "react-syntax-highlighter/dist/esm/languages/prism/json.js";
12
+ import prism_jsx from "react-syntax-highlighter/dist/esm/languages/prism/jsx.js";
13
+ import markdown from "react-syntax-highlighter/dist/esm/languages/prism/markdown.js";
14
+ import markup from "react-syntax-highlighter/dist/esm/languages/prism/markup.js";
15
+ import powershell from "react-syntax-highlighter/dist/esm/languages/prism/powershell.js";
16
+ import python from "react-syntax-highlighter/dist/esm/languages/prism/python.js";
17
+ import sql from "react-syntax-highlighter/dist/esm/languages/prism/sql.js";
18
+ import tsx from "react-syntax-highlighter/dist/esm/languages/prism/tsx.js";
19
+ import typescript from "react-syntax-highlighter/dist/esm/languages/prism/typescript.js";
20
+ import vbnet from "react-syntax-highlighter/dist/esm/languages/prism/vbnet.js";
21
+ import yaml from "react-syntax-highlighter/dist/esm/languages/prism/yaml.js";
22
+ import prism_light from "react-syntax-highlighter/dist/esm/prism-light.js";
23
+ import { Button } from "./button.js";
24
+ import { cn } from "../../lib/index.js";
25
+ import { copyTextToClipboard } from "../../lib/clipboard.js";
26
+ const LANGUAGES = {
27
+ bash: bash,
28
+ csharp: csharp,
29
+ css: css,
30
+ diff: diff,
31
+ go: go,
32
+ java: java,
33
+ javascript: javascript,
34
+ json: json,
35
+ jsx: prism_jsx,
36
+ markdown: markdown,
37
+ markup: markup,
38
+ powershell: powershell,
39
+ python: python,
40
+ sql: sql,
41
+ tsx: tsx,
42
+ typescript: typescript,
43
+ vbnet: vbnet,
44
+ yaml: yaml
45
+ };
46
+ for (const [name, grammar] of Object.entries(LANGUAGES))prism_light.registerLanguage(name, grammar);
47
+ const LANGUAGE_ALIASES = {
48
+ 'c#': 'csharp',
49
+ cjs: "javascript",
50
+ cs: 'csharp',
51
+ golang: 'go',
52
+ htm: 'markup',
53
+ html: 'markup',
54
+ js: "javascript",
55
+ md: 'markdown',
56
+ mjs: "javascript",
57
+ patch: 'diff',
58
+ ps: 'powershell',
59
+ ps1: 'powershell',
60
+ pwsh: 'powershell',
61
+ py: 'python',
62
+ sh: 'bash',
63
+ shell: 'bash',
64
+ svg: 'markup',
65
+ ts: "typescript",
66
+ vb: 'vbnet',
67
+ 'vb.net': 'vbnet',
68
+ xml: 'markup',
69
+ yml: 'yaml',
70
+ zsh: 'bash'
71
+ };
72
+ function resolveLanguage(language) {
73
+ const key = language?.trim().toLowerCase();
74
+ if (!key) return;
75
+ const name = LANGUAGE_ALIASES[key] ?? key;
76
+ return name in LANGUAGES ? name : void 0;
77
+ }
78
+ const token = (name)=>`var(--code-${name}, var(--foreground))`;
79
+ const codeBlockTheme = {
80
+ 'code[class*="language-"]': {
81
+ color: token('rest'),
82
+ background: 'none',
83
+ fontFamily: 'var(--font-mono)',
84
+ textAlign: 'left',
85
+ wordSpacing: 'normal',
86
+ wordBreak: 'normal',
87
+ tabSize: 2,
88
+ hyphens: 'none'
89
+ },
90
+ 'pre[class*="language-"]': {
91
+ color: token('rest'),
92
+ background: 'none',
93
+ fontFamily: 'var(--font-mono)',
94
+ fontSize: '0.8125rem',
95
+ lineHeight: 1.6,
96
+ margin: 0,
97
+ padding: '0.75rem 1rem',
98
+ overflow: 'auto',
99
+ tabSize: 2
100
+ },
101
+ comment: {
102
+ color: 'var(--foreground-muted)',
103
+ fontStyle: 'italic'
104
+ },
105
+ prolog: {
106
+ color: 'var(--foreground-muted)',
107
+ fontStyle: 'italic'
108
+ },
109
+ doctype: {
110
+ color: 'var(--foreground-muted)'
111
+ },
112
+ cdata: {
113
+ color: 'var(--foreground-muted)'
114
+ },
115
+ punctuation: {
116
+ color: token('punctuation')
117
+ },
118
+ operator: {
119
+ color: token('key')
120
+ },
121
+ keyword: {
122
+ color: token('key')
123
+ },
124
+ atrule: {
125
+ color: token('key')
126
+ },
127
+ tag: {
128
+ color: token('key')
129
+ },
130
+ property: {
131
+ color: token('key')
132
+ },
133
+ 'attr-name': {
134
+ color: token('key')
135
+ },
136
+ selector: {
137
+ color: token('key')
138
+ },
139
+ string: {
140
+ color: token('string')
141
+ },
142
+ char: {
143
+ color: token('string')
144
+ },
145
+ 'attr-value': {
146
+ color: token('string')
147
+ },
148
+ 'template-string': {
149
+ color: token('string')
150
+ },
151
+ regex: {
152
+ color: token('string')
153
+ },
154
+ url: {
155
+ color: token('string')
156
+ },
157
+ inserted: {
158
+ color: token('string')
159
+ },
160
+ number: {
161
+ color: token('number')
162
+ },
163
+ unit: {
164
+ color: token('number')
165
+ },
166
+ boolean: {
167
+ color: token('literal')
168
+ },
169
+ constant: {
170
+ color: token('literal')
171
+ },
172
+ symbol: {
173
+ color: token('literal')
174
+ },
175
+ builtin: {
176
+ color: token('literal')
177
+ },
178
+ 'class-name': {
179
+ color: token('literal')
180
+ },
181
+ function: {
182
+ color: token('literal')
183
+ },
184
+ entity: {
185
+ color: token('literal')
186
+ },
187
+ deleted: {
188
+ color: 'var(--error, var(--destructive))'
189
+ },
190
+ important: {
191
+ fontWeight: 600
192
+ },
193
+ bold: {
194
+ fontWeight: 600
195
+ },
196
+ italic: {
197
+ fontStyle: 'italic'
198
+ }
199
+ };
200
+ const lineNumberStyle = {
201
+ minWidth: '2.25em',
202
+ paddingRight: '1em',
203
+ color: 'var(--foreground-subtle)',
204
+ textAlign: 'right',
205
+ userSelect: 'none'
206
+ };
207
+ const DEFAULT_CODE_BLOCK_STRINGS = {
208
+ copy: 'Copy code',
209
+ copied: 'Copied',
210
+ plainText: 'Text'
211
+ };
212
+ const COPIED_RESET_MS = 2000;
213
+ const CodeBlockHeader = /*#__PURE__*/ forwardRef(({ code, language, strings, className, children, ...props }, ref)=>{
214
+ const text = {
215
+ ...DEFAULT_CODE_BLOCK_STRINGS,
216
+ ...strings
217
+ };
218
+ const [copied, setCopied] = useState(false);
219
+ const timer = useRef(void 0);
220
+ useEffect(()=>()=>clearTimeout(timer.current), []);
221
+ const handleCopy = async ()=>{
222
+ if (!await copyTextToClipboard(code)) return;
223
+ setCopied(true);
224
+ clearTimeout(timer.current);
225
+ timer.current = setTimeout(()=>setCopied(false), COPIED_RESET_MS);
226
+ };
227
+ return /*#__PURE__*/ jsxs("div", {
228
+ ref: ref,
229
+ "data-slot": "code-block-header",
230
+ className: cn('flex items-center justify-between gap-2 border-b border-border-subtle py-1 pr-1 pl-4', className),
231
+ ...props,
232
+ children: [
233
+ /*#__PURE__*/ jsx("span", {
234
+ "data-slot": "code-block-language",
235
+ className: "min-w-0 truncate text-xs font-medium text-muted-foreground",
236
+ children: language?.trim() || text.plainText
237
+ }),
238
+ /*#__PURE__*/ jsxs("div", {
239
+ className: "flex shrink-0 items-center gap-1",
240
+ children: [
241
+ children,
242
+ /*#__PURE__*/ jsx(Button, {
243
+ "data-slot": "code-block-copy",
244
+ "data-copied": copied || void 0,
245
+ variant: "ghost",
246
+ size: "2xs",
247
+ icon: true,
248
+ "aria-label": text.copy,
249
+ title: copied ? text.copied : text.copy,
250
+ onClick: handleCopy,
251
+ children: copied ? /*#__PURE__*/ jsx(Check, {
252
+ "aria-hidden": true
253
+ }) : /*#__PURE__*/ jsx(Copy, {
254
+ "aria-hidden": true
255
+ })
256
+ }),
257
+ /*#__PURE__*/ jsx("output", {
258
+ className: "sr-only",
259
+ children: copied ? text.copied : ''
260
+ })
261
+ ]
262
+ })
263
+ ]
264
+ });
265
+ });
266
+ CodeBlockHeader.displayName = 'CodeBlockHeader';
267
+ const code_block_CodeBlockBody = /*#__PURE__*/ memo(function({ code, language, wrap, showLineNumbers }) {
268
+ return /*#__PURE__*/ jsx(prism_light, {
269
+ language: language ?? 'text',
270
+ style: codeBlockTheme,
271
+ wrapLongLines: wrap,
272
+ showLineNumbers: showLineNumbers,
273
+ lineNumberStyle: lineNumberStyle,
274
+ "data-slot": "code-block-body",
275
+ "data-wrap": wrap,
276
+ tabIndex: wrap ? void 0 : 0,
277
+ className: "outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
278
+ children: code
279
+ });
280
+ });
281
+ const CodeBlock = /*#__PURE__*/ forwardRef(({ code, language, wrap = false, showLineNumbers = false, hideHeader = false, actions, strings, className, ...props }, ref)=>{
282
+ const source = code.replace(/\n$/, '');
283
+ const resolved = resolveLanguage(language);
284
+ return /*#__PURE__*/ jsxs("div", {
285
+ ref: ref,
286
+ "data-slot": "code-block",
287
+ "data-language": resolved ?? 'text',
288
+ className: cn('min-w-0 overflow-hidden rounded-lg border border-border-subtle bg-surface-overlay text-foreground', className),
289
+ ...props,
290
+ children: [
291
+ !hideHeader && /*#__PURE__*/ jsx(CodeBlockHeader, {
292
+ code: source,
293
+ language: language,
294
+ strings: strings,
295
+ children: actions
296
+ }),
297
+ /*#__PURE__*/ jsx(code_block_CodeBlockBody, {
298
+ code: source,
299
+ language: resolved,
300
+ wrap: wrap,
301
+ showLineNumbers: showLineNumbers
302
+ })
303
+ ]
304
+ });
305
+ });
306
+ CodeBlock.displayName = 'CodeBlock';
307
+ export { CodeBlock, CodeBlockHeader, DEFAULT_CODE_BLOCK_STRINGS };
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ "use client";
3
+ var __webpack_require__ = {};
4
+ (()=>{
5
+ __webpack_require__.d = (exports1, definition)=>{
6
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ get: definition[key]
9
+ });
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.r = (exports1)=>{
17
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
18
+ value: 'Module'
19
+ });
20
+ Object.defineProperty(exports1, '__esModule', {
21
+ value: true
22
+ });
23
+ };
24
+ })();
25
+ var __webpack_exports__ = {};
26
+ __webpack_require__.r(__webpack_exports__);
27
+ __webpack_require__.d(__webpack_exports__, {
28
+ DropzoneOverlay: ()=>DropzoneOverlay,
29
+ DEFAULT_DROPZONE_OVERLAY_STRINGS: ()=>DEFAULT_DROPZONE_OVERLAY_STRINGS
30
+ });
31
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
32
+ const external_lucide_react_namespaceObject = require("lucide-react");
33
+ const external_react_namespaceObject = require("react");
34
+ const index_cjs_namespaceObject = require("../../lib/index.cjs");
35
+ const external_file_validation_cjs_namespaceObject = require("./file-validation.cjs");
36
+ const DEFAULT_DROPZONE_OVERLAY_STRINGS = {
37
+ dropHint: 'Drop files to attach'
38
+ };
39
+ function hasFiles(dataTransfer) {
40
+ return Array.from(dataTransfer?.types ?? []).includes('Files');
41
+ }
42
+ function filesFrom(data) {
43
+ if (!data) return [];
44
+ const files = Array.from(data.files ?? []);
45
+ if (files.length > 0) return files;
46
+ return Array.from(data.items ?? []).filter((item)=>'file' === item.kind).map((item)=>item.getAsFile()).filter((file)=>null !== file);
47
+ }
48
+ const DropzoneOverlay = /*#__PURE__*/ external_react_namespaceObject.forwardRef(({ className, children, onFiles, accept, maxSize, maxFiles, disabled = false, enablePaste = false, strings, onDragEnter, onDragOver, onDragLeave, onDrop, onPaste, ...props }, ref)=>{
49
+ const text = external_react_namespaceObject.useMemo(()=>({
50
+ ...DEFAULT_DROPZONE_OVERLAY_STRINGS,
51
+ ...strings
52
+ }), [
53
+ strings
54
+ ]);
55
+ const [dragging, setDragging] = external_react_namespaceObject.useState(false);
56
+ const depth = external_react_namespaceObject.useRef(0);
57
+ external_react_namespaceObject.useEffect(()=>{
58
+ if (disabled) {
59
+ depth.current = 0;
60
+ setDragging(false);
61
+ }
62
+ }, [
63
+ disabled
64
+ ]);
65
+ const deliver = (files)=>{
66
+ if (0 === files.length) return;
67
+ const { accepted, rejected } = (0, external_file_validation_cjs_namespaceObject.validateFiles)(files, {
68
+ accept,
69
+ maxSize,
70
+ maxFiles
71
+ });
72
+ onFiles?.(accepted, rejected);
73
+ };
74
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
75
+ ref: ref,
76
+ "data-slot": "dropzone",
77
+ "data-dragging": dragging ? '' : void 0,
78
+ className: (0, index_cjs_namespaceObject.cn)('relative', className),
79
+ onDragEnter: (event)=>{
80
+ onDragEnter?.(event);
81
+ if (disabled || !hasFiles(event.dataTransfer)) return;
82
+ event.preventDefault();
83
+ depth.current += 1;
84
+ setDragging(true);
85
+ },
86
+ onDragOver: (event)=>{
87
+ onDragOver?.(event);
88
+ if (disabled || !hasFiles(event.dataTransfer)) return;
89
+ event.preventDefault();
90
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
91
+ },
92
+ onDragLeave: (event)=>{
93
+ onDragLeave?.(event);
94
+ if (disabled || !hasFiles(event.dataTransfer)) return;
95
+ depth.current = Math.max(0, depth.current - 1);
96
+ if (0 === depth.current) setDragging(false);
97
+ },
98
+ onDrop: (event)=>{
99
+ onDrop?.(event);
100
+ depth.current = 0;
101
+ setDragging(false);
102
+ if (disabled || event.defaultPrevented || !hasFiles(event.dataTransfer)) return;
103
+ event.preventDefault();
104
+ deliver(filesFrom(event.dataTransfer));
105
+ },
106
+ onPaste: (event)=>{
107
+ onPaste?.(event);
108
+ if (disabled || !enablePaste || event.defaultPrevented) return;
109
+ const files = filesFrom(event.clipboardData);
110
+ if (0 === files.length) return;
111
+ event.preventDefault();
112
+ deliver(files);
113
+ },
114
+ ...props,
115
+ children: [
116
+ children,
117
+ dragging && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
118
+ "data-slot": "dropzone-overlay",
119
+ className: "pointer-events-none absolute inset-0 z-30 flex flex-col items-center justify-center gap-2 rounded-[inherit] border-2 border-dashed border-primary bg-background/85 text-sm font-medium text-foreground backdrop-blur-sm animate-in fade-in-0 motion-reduce:animate-none",
120
+ children: [
121
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_lucide_react_namespaceObject.Upload, {
122
+ className: "size-6 text-primary",
123
+ "aria-hidden": "true"
124
+ }),
125
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
126
+ children: text.dropHint
127
+ })
128
+ ]
129
+ })
130
+ ]
131
+ });
132
+ });
133
+ DropzoneOverlay.displayName = 'DropzoneOverlay';
134
+ exports.DEFAULT_DROPZONE_OVERLAY_STRINGS = __webpack_exports__.DEFAULT_DROPZONE_OVERLAY_STRINGS;
135
+ exports.DropzoneOverlay = __webpack_exports__.DropzoneOverlay;
136
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
137
+ "DEFAULT_DROPZONE_OVERLAY_STRINGS",
138
+ "DropzoneOverlay"
139
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
140
+ Object.defineProperty(exports, '__esModule', {
141
+ value: true
142
+ });
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { type FileRejection, type FileValidationOptions } from './file-validation';
3
+ /**
4
+ * Turns a region, such as a chat panel or a composer, into a file drop target. While files are
5
+ * dragged over it an overlay covers the region with a hint; dropped (or, with `enablePaste`,
6
+ * pasted) files are checked against `accept`, `maxSize` and `maxFiles` and handed to `onFiles`.
7
+ */
8
+ export interface DropzoneOverlayStrings {
9
+ /** Shown on the overlay while files are dragged over the region. */
10
+ dropHint: string;
11
+ }
12
+ export declare const DEFAULT_DROPZONE_OVERLAY_STRINGS: DropzoneOverlayStrings;
13
+ export interface DropzoneOverlayProps extends React.HTMLAttributes<HTMLDivElement>, FileValidationOptions {
14
+ /**
15
+ * Called once per drop or paste, with the files that passed the checks and those that did not.
16
+ * `maxFiles` counts each drop or paste on its own; pass what is left of a total cap.
17
+ */
18
+ onFiles?: (accepted: File[], rejected: FileRejection[]) => void;
19
+ /** Ignores drags, drops and pastes. */
20
+ disabled?: boolean;
21
+ /** Also takes files pasted anywhere inside the region. Pastes without files are left alone. */
22
+ enablePaste?: boolean;
23
+ /** Overrides for any subset of the English strings. */
24
+ strings?: Partial<DropzoneOverlayStrings>;
25
+ }
26
+ declare const DropzoneOverlay: React.ForwardRefExoticComponent<DropzoneOverlayProps & React.RefAttributes<HTMLDivElement>>;
27
+ export { DropzoneOverlay };
@@ -0,0 +1,105 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { Upload } from "lucide-react";
4
+ import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
5
+ import { cn } from "../../lib/index.js";
6
+ import { validateFiles } from "./file-validation.js";
7
+ const DEFAULT_DROPZONE_OVERLAY_STRINGS = {
8
+ dropHint: 'Drop files to attach'
9
+ };
10
+ function hasFiles(dataTransfer) {
11
+ return Array.from(dataTransfer?.types ?? []).includes('Files');
12
+ }
13
+ function filesFrom(data) {
14
+ if (!data) return [];
15
+ const files = Array.from(data.files ?? []);
16
+ if (files.length > 0) return files;
17
+ return Array.from(data.items ?? []).filter((item)=>'file' === item.kind).map((item)=>item.getAsFile()).filter((file)=>null !== file);
18
+ }
19
+ const DropzoneOverlay = /*#__PURE__*/ forwardRef(({ className, children, onFiles, accept, maxSize, maxFiles, disabled = false, enablePaste = false, strings, onDragEnter, onDragOver, onDragLeave, onDrop, onPaste, ...props }, ref)=>{
20
+ const text = useMemo(()=>({
21
+ ...DEFAULT_DROPZONE_OVERLAY_STRINGS,
22
+ ...strings
23
+ }), [
24
+ strings
25
+ ]);
26
+ const [dragging, setDragging] = useState(false);
27
+ const depth = useRef(0);
28
+ useEffect(()=>{
29
+ if (disabled) {
30
+ depth.current = 0;
31
+ setDragging(false);
32
+ }
33
+ }, [
34
+ disabled
35
+ ]);
36
+ const deliver = (files)=>{
37
+ if (0 === files.length) return;
38
+ const { accepted, rejected } = validateFiles(files, {
39
+ accept,
40
+ maxSize,
41
+ maxFiles
42
+ });
43
+ onFiles?.(accepted, rejected);
44
+ };
45
+ return /*#__PURE__*/ jsxs("div", {
46
+ ref: ref,
47
+ "data-slot": "dropzone",
48
+ "data-dragging": dragging ? '' : void 0,
49
+ className: cn('relative', className),
50
+ onDragEnter: (event)=>{
51
+ onDragEnter?.(event);
52
+ if (disabled || !hasFiles(event.dataTransfer)) return;
53
+ event.preventDefault();
54
+ depth.current += 1;
55
+ setDragging(true);
56
+ },
57
+ onDragOver: (event)=>{
58
+ onDragOver?.(event);
59
+ if (disabled || !hasFiles(event.dataTransfer)) return;
60
+ event.preventDefault();
61
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
62
+ },
63
+ onDragLeave: (event)=>{
64
+ onDragLeave?.(event);
65
+ if (disabled || !hasFiles(event.dataTransfer)) return;
66
+ depth.current = Math.max(0, depth.current - 1);
67
+ if (0 === depth.current) setDragging(false);
68
+ },
69
+ onDrop: (event)=>{
70
+ onDrop?.(event);
71
+ depth.current = 0;
72
+ setDragging(false);
73
+ if (disabled || event.defaultPrevented || !hasFiles(event.dataTransfer)) return;
74
+ event.preventDefault();
75
+ deliver(filesFrom(event.dataTransfer));
76
+ },
77
+ onPaste: (event)=>{
78
+ onPaste?.(event);
79
+ if (disabled || !enablePaste || event.defaultPrevented) return;
80
+ const files = filesFrom(event.clipboardData);
81
+ if (0 === files.length) return;
82
+ event.preventDefault();
83
+ deliver(files);
84
+ },
85
+ ...props,
86
+ children: [
87
+ children,
88
+ dragging && /*#__PURE__*/ jsxs("div", {
89
+ "data-slot": "dropzone-overlay",
90
+ className: "pointer-events-none absolute inset-0 z-30 flex flex-col items-center justify-center gap-2 rounded-[inherit] border-2 border-dashed border-primary bg-background/85 text-sm font-medium text-foreground backdrop-blur-sm animate-in fade-in-0 motion-reduce:animate-none",
91
+ children: [
92
+ /*#__PURE__*/ jsx(Upload, {
93
+ className: "size-6 text-primary",
94
+ "aria-hidden": "true"
95
+ }),
96
+ /*#__PURE__*/ jsx("span", {
97
+ children: text.dropHint
98
+ })
99
+ ]
100
+ })
101
+ ]
102
+ });
103
+ });
104
+ DropzoneOverlay.displayName = 'DropzoneOverlay';
105
+ export { DEFAULT_DROPZONE_OVERLAY_STRINGS, DropzoneOverlay };
@@ -32,6 +32,7 @@ const external_lucide_react_namespaceObject = require("lucide-react");
32
32
  const external_react_namespaceObject = require("react");
33
33
  const external_button_cjs_namespaceObject = require("./button.cjs");
34
34
  const index_cjs_namespaceObject = require("../../lib/index.cjs");
35
+ const external_file_validation_cjs_namespaceObject = require("./file-validation.cjs");
35
36
  const external_form_field_cjs_namespaceObject = require("./form-field.cjs");
36
37
  const file_upload_FileUpload = /*#__PURE__*/ external_react_namespaceObject.forwardRef(function({ id, ariaLabel, onFilesChange, accept, multiple = false, disabled = false, maxSize, className, showPreview = false, errors, onBlur, error, errorId, 'aria-invalid': ariaInvalid, 'aria-describedby': ariaDescribedBy, 'aria-errormessage': ariaErrorMessage }, ref) {
37
38
  const generatedId = external_react_namespaceObject.useId();
@@ -47,31 +48,18 @@ const file_upload_FileUpload = /*#__PURE__*/ external_react_namespaceObject.forw
47
48
  const [fileErrors, setFileErrors] = external_react_namespaceObject.useState(new Map());
48
49
  const [previews, setPreviews] = external_react_namespaceObject.useState([]);
49
50
  const inputRef = external_react_namespaceObject.useRef(null);
50
- const isFileTypeAccepted = (file)=>{
51
- if (!accept) return true;
52
- const acceptedTypes = accept.split(',').map((type)=>type.trim().toLowerCase());
53
- for (const acceptedType of acceptedTypes)if (acceptedType.endsWith('/*')) {
54
- const baseType = acceptedType.slice(0, -2);
55
- if (file.type.toLowerCase().startsWith(baseType)) return true;
56
- } else if (acceptedType.includes('/')) {
57
- if (file.type.toLowerCase() === acceptedType) return true;
58
- } else if (acceptedType.startsWith('.')) {
59
- if (file.name.toLowerCase().endsWith(acceptedType)) return true;
60
- }
61
- return false;
62
- };
63
51
  const validateFiles = (fileList, startIndex, existingErrors)=>{
64
52
  const validFiles = [];
65
53
  const errors = multiple ? new Map(existingErrors) : new Map();
66
54
  for (const file of fileList){
67
55
  const fileIndex = startIndex + validFiles.length;
68
- if (!isFileTypeAccepted(file)) {
56
+ if (!(0, external_file_validation_cjs_namespaceObject.isFileTypeAccepted)(file, accept)) {
69
57
  errors.set(fileIndex, 'File type not accepted');
70
58
  validFiles.push(file);
71
59
  continue;
72
60
  }
73
61
  if (maxSize && file.size > maxSize) {
74
- errors.set(fileIndex, `Exceeds maximum size of ${formatFileSize(maxSize)}`);
62
+ errors.set(fileIndex, `Exceeds maximum size of ${(0, external_file_validation_cjs_namespaceObject.formatFileSize)(maxSize)}`);
75
63
  validFiles.push(file);
76
64
  continue;
77
65
  }
@@ -157,18 +145,6 @@ const file_upload_FileUpload = /*#__PURE__*/ external_react_namespaceObject.forw
157
145
  const handleClick = ()=>{
158
146
  if (!disabled) inputRef.current?.click();
159
147
  };
160
- const formatFileSize = (bytes)=>{
161
- if (0 === bytes) return '0 Bytes';
162
- const k = 1024;
163
- const sizes = [
164
- 'Bytes',
165
- 'KB',
166
- 'MB',
167
- 'GB'
168
- ];
169
- const i = Math.floor(Math.log(bytes) / Math.log(k));
170
- return `${Math.round(bytes / k ** i * 100) / 100} ${sizes[i]}`;
171
- };
172
148
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("fieldset", {
173
149
  ref: ref,
174
150
  "data-slot": "file-upload",
@@ -233,7 +209,7 @@ const file_upload_FileUpload = /*#__PURE__*/ external_react_namespaceObject.forw
233
209
  className: "text-xs text-muted-foreground future:text-foreground-muted",
234
210
  children: [
235
211
  "Max size: ",
236
- formatFileSize(maxSize)
212
+ (0, external_file_validation_cjs_namespaceObject.formatFileSize)(maxSize)
237
213
  ]
238
214
  })
239
215
  ]
@@ -269,7 +245,7 @@ const file_upload_FileUpload = /*#__PURE__*/ external_react_namespaceObject.forw
269
245
  }),
270
246
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("p", {
271
247
  className: "text-xs text-muted-foreground",
272
- children: formatFileSize(file.size)
248
+ children: (0, external_file_validation_cjs_namespaceObject.formatFileSize)(file.size)
273
249
  })
274
250
  ]
275
251
  })