@uipath/apollo-wind 2.69.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 (53) 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/dropzone-overlay.cjs +142 -0
  15. package/dist/components/ui/dropzone-overlay.d.ts +27 -0
  16. package/dist/components/ui/dropzone-overlay.js +105 -0
  17. package/dist/components/ui/file-upload.cjs +5 -29
  18. package/dist/components/ui/file-upload.js +2 -26
  19. package/dist/components/ui/file-validation.cjs +91 -0
  20. package/dist/components/ui/file-validation.d.ts +24 -0
  21. package/dist/components/ui/file-validation.js +51 -0
  22. package/dist/components/ui/hover-card.cjs +15 -8
  23. package/dist/components/ui/hover-card.d.ts +4 -1
  24. package/dist/components/ui/hover-card.js +16 -9
  25. package/dist/components/ui/index.cjs +280 -214
  26. package/dist/components/ui/index.d.ts +6 -0
  27. package/dist/components/ui/index.js +6 -0
  28. package/dist/components/ui/input-group.cjs +1 -1
  29. package/dist/components/ui/input-group.d.ts +2 -1
  30. package/dist/components/ui/input-group.js +1 -1
  31. package/dist/components/ui/message-actions.cjs +302 -0
  32. package/dist/components/ui/message-actions.d.ts +102 -0
  33. package/dist/components/ui/message-actions.js +241 -0
  34. package/dist/components/ui/message.cjs +1 -1
  35. package/dist/components/ui/message.d.ts +2 -0
  36. package/dist/components/ui/message.js +1 -1
  37. package/dist/components/ui/sources.cjs +175 -0
  38. package/dist/components/ui/sources.d.ts +44 -0
  39. package/dist/components/ui/sources.js +132 -0
  40. package/dist/index.cjs +117 -6
  41. package/dist/index.d.ts +12 -0
  42. package/dist/index.js +7 -1
  43. package/dist/lib/index.cjs +8 -1
  44. package/dist/lib/index.d.ts +1 -0
  45. package/dist/lib/index.js +2 -1
  46. package/dist/lib/url.cjs +54 -0
  47. package/dist/lib/url.d.ts +8 -0
  48. package/dist/lib/url.js +17 -0
  49. package/dist/styles.css +157 -35
  50. package/package.json +1 -1
  51. package/dist/components/custom/chat-composer.cjs +0 -134
  52. package/dist/components/custom/chat-composer.d.ts +0 -14
  53. package/dist/components/custom/chat-composer.js +0 -100
@@ -0,0 +1,188 @@
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
+ Citation: ()=>Citation,
29
+ citationVariants: ()=>citationVariants,
30
+ DEFAULT_CITATION_STRINGS: ()=>DEFAULT_CITATION_STRINGS
31
+ });
32
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
33
+ const external_class_variance_authority_namespaceObject = require("class-variance-authority");
34
+ const external_react_namespaceObject = require("react");
35
+ const index_cjs_namespaceObject = require("../../lib/index.cjs");
36
+ const external_hover_card_cjs_namespaceObject = require("./hover-card.cjs");
37
+ const DEFAULT_CITATION_STRINGS = {
38
+ label: (index, title)=>title ? `Citation ${index}: ${title}` : `Citation ${index}`
39
+ };
40
+ const citationVariants = (0, external_class_variance_authority_namespaceObject.cva)('mx-0.5 inline-flex cursor-pointer items-center justify-center rounded-full bg-muted align-text-top font-medium leading-none text-muted-foreground tabular-nums transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-accent data-[state=open]:text-accent-foreground', {
41
+ variants: {
42
+ size: {
43
+ default: 'h-4.5 min-w-4.5 px-1.5 text-[11px]',
44
+ sm: 'h-4 min-w-4 px-1 text-[10px]',
45
+ lg: 'h-5 min-w-5 px-1.5 text-xs'
46
+ }
47
+ },
48
+ defaultVariants: {
49
+ size: 'default'
50
+ }
51
+ });
52
+ const Citation = /*#__PURE__*/ external_react_namespaceObject.forwardRef(({ className, size = 'default', index, title, snippet, source, href, onSelect, onClick, onFocus, onBlur, onPointerEnter, onPointerLeave, preview = true, previewSide = 'top', onActiveChange, strings, 'aria-label': ariaLabel, children, ...props }, ref)=>{
53
+ const text = {
54
+ ...DEFAULT_CITATION_STRINGS,
55
+ ...strings
56
+ };
57
+ const [open, setOpen] = external_react_namespaceObject.useState(false);
58
+ const activity = external_react_namespaceObject.useRef({
59
+ hovered: false,
60
+ focused: false,
61
+ previewOpen: false
62
+ });
63
+ const active = external_react_namespaceObject.useRef(false);
64
+ const onActiveChangeRef = external_react_namespaceObject.useRef(onActiveChange);
65
+ onActiveChangeRef.current = onActiveChange;
66
+ const updateActivity = (patch)=>{
67
+ Object.assign(activity.current, patch);
68
+ const { hovered, focused, previewOpen } = activity.current;
69
+ const next = hovered || focused || previewOpen;
70
+ if (next === active.current) return;
71
+ active.current = next;
72
+ onActiveChangeRef.current?.(next);
73
+ };
74
+ const dismissed = external_react_namespaceObject.useRef(false);
75
+ const setPreviewOpen = (next)=>{
76
+ if (next && dismissed.current) return;
77
+ setOpen(next);
78
+ updateActivity({
79
+ previewOpen: next
80
+ });
81
+ };
82
+ external_react_namespaceObject.useEffect(()=>()=>{
83
+ if (active.current) onActiveChangeRef.current?.(false);
84
+ }, []);
85
+ const name = ariaLabel ?? text.label(String(index), title || void 0);
86
+ const hasPreview = preview && Boolean(title || snippet || source);
87
+ const button = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
88
+ ref: ref,
89
+ type: "button",
90
+ "data-slot": "citation",
91
+ "data-size": size,
92
+ "aria-label": name,
93
+ className: (0, index_cjs_namespaceObject.cn)(citationVariants({
94
+ size
95
+ }), className),
96
+ onClick: (event)=>{
97
+ onClick?.(event);
98
+ if (hasPreview) {
99
+ dismissed.current = true;
100
+ setPreviewOpen(false);
101
+ }
102
+ if (!event.defaultPrevented) onSelect?.({
103
+ index,
104
+ title,
105
+ snippet,
106
+ source,
107
+ href: (0, index_cjs_namespaceObject.safeHref)(href)
108
+ }, event);
109
+ },
110
+ onFocus: (event)=>{
111
+ onFocus?.(event);
112
+ if (!event.currentTarget.matches(':focus-visible')) return;
113
+ updateActivity({
114
+ focused: true
115
+ });
116
+ if (hasPreview) setPreviewOpen(true);
117
+ },
118
+ onBlur: (event)=>{
119
+ onBlur?.(event);
120
+ dismissed.current = false;
121
+ updateActivity({
122
+ focused: false
123
+ });
124
+ },
125
+ onPointerEnter: (event)=>{
126
+ onPointerEnter?.(event);
127
+ updateActivity({
128
+ hovered: true
129
+ });
130
+ },
131
+ onPointerLeave: (event)=>{
132
+ onPointerLeave?.(event);
133
+ dismissed.current = false;
134
+ updateActivity({
135
+ hovered: false
136
+ });
137
+ },
138
+ ...props,
139
+ children: children ?? index
140
+ });
141
+ if (!hasPreview) return button;
142
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_hover_card_cjs_namespaceObject.HoverCard, {
143
+ open: open,
144
+ onOpenChange: setPreviewOpen,
145
+ openDelay: 300,
146
+ closeDelay: 150,
147
+ children: [
148
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_hover_card_cjs_namespaceObject.HoverCardTrigger, {
149
+ asChild: true,
150
+ children: button
151
+ }),
152
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_hover_card_cjs_namespaceObject.HoverCardContent, {
153
+ "data-slot": "citation-preview",
154
+ side: previewSide,
155
+ className: "flex w-72 flex-col gap-1 p-3 text-sm",
156
+ children: [
157
+ source && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
158
+ "data-slot": "citation-source",
159
+ className: "truncate text-xs text-muted-foreground",
160
+ children: source
161
+ }),
162
+ title && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
163
+ "data-slot": "citation-title",
164
+ className: "line-clamp-2 font-medium",
165
+ children: title
166
+ }),
167
+ snippet && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
168
+ "data-slot": "citation-snippet",
169
+ className: "line-clamp-3 text-xs leading-relaxed text-muted-foreground",
170
+ children: snippet
171
+ })
172
+ ]
173
+ })
174
+ ]
175
+ });
176
+ });
177
+ Citation.displayName = 'Citation';
178
+ exports.Citation = __webpack_exports__.Citation;
179
+ exports.DEFAULT_CITATION_STRINGS = __webpack_exports__.DEFAULT_CITATION_STRINGS;
180
+ exports.citationVariants = __webpack_exports__.citationVariants;
181
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
182
+ "Citation",
183
+ "DEFAULT_CITATION_STRINGS",
184
+ "citationVariants"
185
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
186
+ Object.defineProperty(exports, '__esModule', {
187
+ value: true
188
+ });
@@ -0,0 +1,42 @@
1
+ import { type VariantProps } from 'class-variance-authority';
2
+ import * as React from 'react';
3
+ import { HoverCardContent } from './hover-card';
4
+ /**
5
+ * An inline citation marker for chat prose, with a hover and focus preview of the source. It does
6
+ * not navigate on its own: `onSelect` receives the citation and the event, so a host can run its
7
+ * `citation-click` pre-hook and decide whether to open `href`. The payload drops an `href` that is
8
+ * not http(s), mailto, tel or relative, so it is safe to open.
9
+ */
10
+ export interface CitationData {
11
+ /** The source number, usually 1-based. Shown in the pill unless `children` are given. */
12
+ index: number | string;
13
+ title?: string;
14
+ snippet?: string;
15
+ /** Where it came from: a domain, a file name or a page reference. */
16
+ source?: string;
17
+ href?: string;
18
+ }
19
+ export interface CitationStrings {
20
+ /** Accessible name of the pill. */
21
+ label: (index: string, title?: string) => string;
22
+ }
23
+ export declare const DEFAULT_CITATION_STRINGS: CitationStrings;
24
+ declare const citationVariants: (props?: ({
25
+ size?: "default" | "lg" | "sm" | null | undefined;
26
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
27
+ export interface CitationProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onSelect' | 'title'>, CitationData, VariantProps<typeof citationVariants> {
28
+ onSelect?: (citation: CitationData, event: React.MouseEvent<HTMLButtonElement>) => void;
29
+ /** Set false to skip the preview card even when there is content for it. */
30
+ preview?: boolean;
31
+ previewSide?: React.ComponentPropsWithoutRef<typeof HoverCardContent>['side'];
32
+ /**
33
+ * Called when the citation becomes active or inactive, so a host can mark the cited text. It
34
+ * activates at once on hover or keyboard focus, and deactivates once neither applies and its
35
+ * preview, if shown, has closed. The preview's close delay means one citation can deactivate after the next
36
+ * activates. Also called with `false` if it unmounts active.
37
+ */
38
+ onActiveChange?: (active: boolean) => void;
39
+ strings?: Partial<CitationStrings>;
40
+ }
41
+ declare const Citation: React.ForwardRefExoticComponent<CitationProps & React.RefAttributes<HTMLButtonElement>>;
42
+ export { Citation, citationVariants };
@@ -0,0 +1,148 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { cva } from "class-variance-authority";
4
+ import { forwardRef, useEffect, useRef, useState } from "react";
5
+ import { cn, safeHref } from "../../lib/index.js";
6
+ import { HoverCard, HoverCardContent, HoverCardTrigger } from "./hover-card.js";
7
+ const DEFAULT_CITATION_STRINGS = {
8
+ label: (index, title)=>title ? `Citation ${index}: ${title}` : `Citation ${index}`
9
+ };
10
+ const citationVariants = cva('mx-0.5 inline-flex cursor-pointer items-center justify-center rounded-full bg-muted align-text-top font-medium leading-none text-muted-foreground tabular-nums transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-accent data-[state=open]:text-accent-foreground', {
11
+ variants: {
12
+ size: {
13
+ default: 'h-4.5 min-w-4.5 px-1.5 text-[11px]',
14
+ sm: 'h-4 min-w-4 px-1 text-[10px]',
15
+ lg: 'h-5 min-w-5 px-1.5 text-xs'
16
+ }
17
+ },
18
+ defaultVariants: {
19
+ size: 'default'
20
+ }
21
+ });
22
+ const Citation = /*#__PURE__*/ forwardRef(({ className, size = 'default', index, title, snippet, source, href, onSelect, onClick, onFocus, onBlur, onPointerEnter, onPointerLeave, preview = true, previewSide = 'top', onActiveChange, strings, 'aria-label': ariaLabel, children, ...props }, ref)=>{
23
+ const text = {
24
+ ...DEFAULT_CITATION_STRINGS,
25
+ ...strings
26
+ };
27
+ const [open, setOpen] = useState(false);
28
+ const activity = useRef({
29
+ hovered: false,
30
+ focused: false,
31
+ previewOpen: false
32
+ });
33
+ const active = useRef(false);
34
+ const onActiveChangeRef = useRef(onActiveChange);
35
+ onActiveChangeRef.current = onActiveChange;
36
+ const updateActivity = (patch)=>{
37
+ Object.assign(activity.current, patch);
38
+ const { hovered, focused, previewOpen } = activity.current;
39
+ const next = hovered || focused || previewOpen;
40
+ if (next === active.current) return;
41
+ active.current = next;
42
+ onActiveChangeRef.current?.(next);
43
+ };
44
+ const dismissed = useRef(false);
45
+ const setPreviewOpen = (next)=>{
46
+ if (next && dismissed.current) return;
47
+ setOpen(next);
48
+ updateActivity({
49
+ previewOpen: next
50
+ });
51
+ };
52
+ useEffect(()=>()=>{
53
+ if (active.current) onActiveChangeRef.current?.(false);
54
+ }, []);
55
+ const name = ariaLabel ?? text.label(String(index), title || void 0);
56
+ const hasPreview = preview && Boolean(title || snippet || source);
57
+ const button = /*#__PURE__*/ jsx("button", {
58
+ ref: ref,
59
+ type: "button",
60
+ "data-slot": "citation",
61
+ "data-size": size,
62
+ "aria-label": name,
63
+ className: cn(citationVariants({
64
+ size
65
+ }), className),
66
+ onClick: (event)=>{
67
+ onClick?.(event);
68
+ if (hasPreview) {
69
+ dismissed.current = true;
70
+ setPreviewOpen(false);
71
+ }
72
+ if (!event.defaultPrevented) onSelect?.({
73
+ index,
74
+ title,
75
+ snippet,
76
+ source,
77
+ href: safeHref(href)
78
+ }, event);
79
+ },
80
+ onFocus: (event)=>{
81
+ onFocus?.(event);
82
+ if (!event.currentTarget.matches(':focus-visible')) return;
83
+ updateActivity({
84
+ focused: true
85
+ });
86
+ if (hasPreview) setPreviewOpen(true);
87
+ },
88
+ onBlur: (event)=>{
89
+ onBlur?.(event);
90
+ dismissed.current = false;
91
+ updateActivity({
92
+ focused: false
93
+ });
94
+ },
95
+ onPointerEnter: (event)=>{
96
+ onPointerEnter?.(event);
97
+ updateActivity({
98
+ hovered: true
99
+ });
100
+ },
101
+ onPointerLeave: (event)=>{
102
+ onPointerLeave?.(event);
103
+ dismissed.current = false;
104
+ updateActivity({
105
+ hovered: false
106
+ });
107
+ },
108
+ ...props,
109
+ children: children ?? index
110
+ });
111
+ if (!hasPreview) return button;
112
+ return /*#__PURE__*/ jsxs(HoverCard, {
113
+ open: open,
114
+ onOpenChange: setPreviewOpen,
115
+ openDelay: 300,
116
+ closeDelay: 150,
117
+ children: [
118
+ /*#__PURE__*/ jsx(HoverCardTrigger, {
119
+ asChild: true,
120
+ children: button
121
+ }),
122
+ /*#__PURE__*/ jsxs(HoverCardContent, {
123
+ "data-slot": "citation-preview",
124
+ side: previewSide,
125
+ className: "flex w-72 flex-col gap-1 p-3 text-sm",
126
+ children: [
127
+ source && /*#__PURE__*/ jsx("span", {
128
+ "data-slot": "citation-source",
129
+ className: "truncate text-xs text-muted-foreground",
130
+ children: source
131
+ }),
132
+ title && /*#__PURE__*/ jsx("span", {
133
+ "data-slot": "citation-title",
134
+ className: "line-clamp-2 font-medium",
135
+ children: title
136
+ }),
137
+ snippet && /*#__PURE__*/ jsx("span", {
138
+ "data-slot": "citation-snippet",
139
+ className: "line-clamp-3 text-xs leading-relaxed text-muted-foreground",
140
+ children: snippet
141
+ })
142
+ ]
143
+ })
144
+ ]
145
+ });
146
+ });
147
+ Citation.displayName = 'Citation';
148
+ export { Citation, DEFAULT_CITATION_STRINGS, citationVariants };
@@ -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 };