@uipath/apollo-wind 2.69.0 → 2.71.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 (91) hide show
  1. package/dist/components/custom/demo-composer.cjs +80 -0
  2. package/dist/components/custom/demo-composer.d.ts +11 -0
  3. package/dist/components/custom/demo-composer.js +46 -0
  4. package/dist/components/custom/panel-flow.cjs +2 -2
  5. package/dist/components/custom/panel-flow.js +2 -2
  6. package/dist/components/forms/field-control.cjs +3 -2
  7. package/dist/components/forms/field-control.js +3 -2
  8. package/dist/components/forms/validation-converter.cjs +14 -5
  9. package/dist/components/forms/validation-converter.js +14 -5
  10. package/dist/components/ui/chat-composer.cjs +429 -0
  11. package/dist/components/ui/chat-composer.d.ts +157 -0
  12. package/dist/components/ui/chat-composer.js +359 -0
  13. package/dist/components/ui/chat-hero.cjs +244 -0
  14. package/dist/components/ui/chat-hero.d.ts +51 -0
  15. package/dist/components/ui/chat-hero.js +189 -0
  16. package/dist/components/ui/citation.cjs +188 -0
  17. package/dist/components/ui/citation.d.ts +42 -0
  18. package/dist/components/ui/citation.js +148 -0
  19. package/dist/components/ui/date-picker.cjs +6 -5
  20. package/dist/components/ui/date-picker.js +7 -6
  21. package/dist/components/ui/datetime-picker.cjs +7 -10
  22. package/dist/components/ui/datetime-picker.js +8 -11
  23. package/dist/components/ui/dropzone-overlay.cjs +142 -0
  24. package/dist/components/ui/dropzone-overlay.d.ts +27 -0
  25. package/dist/components/ui/dropzone-overlay.js +105 -0
  26. package/dist/components/ui/file-upload.cjs +5 -29
  27. package/dist/components/ui/file-upload.js +2 -26
  28. package/dist/components/ui/file-validation.cjs +91 -0
  29. package/dist/components/ui/file-validation.d.ts +24 -0
  30. package/dist/components/ui/file-validation.js +51 -0
  31. package/dist/components/ui/hover-card.cjs +15 -8
  32. package/dist/components/ui/hover-card.d.ts +4 -1
  33. package/dist/components/ui/hover-card.js +16 -9
  34. package/dist/components/ui/index.cjs +304 -216
  35. package/dist/components/ui/index.d.ts +8 -0
  36. package/dist/components/ui/index.js +8 -0
  37. package/dist/components/ui/input-group.cjs +1 -1
  38. package/dist/components/ui/input-group.d.ts +2 -1
  39. package/dist/components/ui/input-group.js +1 -1
  40. package/dist/components/ui/message-actions.cjs +302 -0
  41. package/dist/components/ui/message-actions.d.ts +102 -0
  42. package/dist/components/ui/message-actions.js +241 -0
  43. package/dist/components/ui/message.cjs +1 -1
  44. package/dist/components/ui/message.d.ts +2 -0
  45. package/dist/components/ui/message.js +1 -1
  46. package/dist/components/ui/prompt-suggestions.cjs +133 -0
  47. package/dist/components/ui/prompt-suggestions.d.ts +52 -0
  48. package/dist/components/ui/prompt-suggestions.js +90 -0
  49. package/dist/components/ui/quick-form-field/components/field-header.cjs +9 -4
  50. package/dist/components/ui/quick-form-field/components/field-header.d.ts +4 -1
  51. package/dist/components/ui/quick-form-field/components/field-header.js +9 -4
  52. package/dist/components/ui/quick-form-field/components/lock-toggle-button.cjs +2 -2
  53. package/dist/components/ui/quick-form-field/components/lock-toggle-button.d.ts +5 -4
  54. package/dist/components/ui/quick-form-field/components/lock-toggle-button.js +2 -2
  55. package/dist/components/ui/quick-form-field/index.d.ts +1 -1
  56. package/dist/components/ui/quick-form-field/quick-form-field.cjs +158 -222
  57. package/dist/components/ui/quick-form-field/quick-form-field.d.ts +6 -4
  58. package/dist/components/ui/quick-form-field/quick-form-field.js +159 -223
  59. package/dist/components/ui/quick-form-field/types.cjs +2 -2
  60. package/dist/components/ui/quick-form-field/types.d.ts +39 -32
  61. package/dist/components/ui/quick-form-field/types.js +2 -2
  62. package/dist/components/ui/quick-form-field/utils.cjs +5 -59
  63. package/dist/components/ui/quick-form-field/utils.d.ts +2 -24
  64. package/dist/components/ui/quick-form-field/utils.js +3 -48
  65. package/dist/components/ui/sources.cjs +175 -0
  66. package/dist/components/ui/sources.d.ts +44 -0
  67. package/dist/components/ui/sources.js +132 -0
  68. package/dist/index.cjs +156 -7
  69. package/dist/index.d.ts +17 -1
  70. package/dist/index.js +9 -1
  71. package/dist/lib/date-value.cjs +46 -0
  72. package/dist/lib/date-value.d.ts +8 -0
  73. package/dist/lib/date-value.js +12 -0
  74. package/dist/lib/index.cjs +8 -1
  75. package/dist/lib/index.d.ts +1 -0
  76. package/dist/lib/index.js +2 -1
  77. package/dist/lib/url.cjs +54 -0
  78. package/dist/lib/url.d.ts +8 -0
  79. package/dist/lib/url.js +17 -0
  80. package/dist/styles.css +239 -78
  81. package/dist/tailwind.utilities.css +15 -0
  82. package/package.json +1 -1
  83. package/dist/components/custom/chat-composer.cjs +0 -134
  84. package/dist/components/custom/chat-composer.d.ts +0 -14
  85. package/dist/components/custom/chat-composer.js +0 -100
  86. package/dist/components/custom/chat-first-experience.cjs +0 -87
  87. package/dist/components/custom/chat-first-experience.d.ts +0 -24
  88. package/dist/components/custom/chat-first-experience.js +0 -53
  89. package/dist/components/custom/chat-prompt-suggestions.cjs +0 -49
  90. package/dist/components/custom/chat-prompt-suggestions.d.ts +0 -18
  91. package/dist/components/custom/chat-prompt-suggestions.js +0 -15
@@ -47,19 +47,15 @@ const datetime_picker_DateTimePicker = /*#__PURE__*/ external_react_namespaceObj
47
47
  };
48
48
  const generatedId = external_react_namespaceObject.useId();
49
49
  const validationId = errorId ?? `${id ?? `datetime-picker-${generatedId.replace(/:/g, '')}`}-error`;
50
- const [selectedDate, setSelectedDate] = external_react_namespaceObject.useState(value);
51
- const [timeValue, setTimeValue] = external_react_namespaceObject.useState(value ? (0, external_date_fns_namespaceObject.format)(value, 'HH:mm') : '');
52
- const valueTime = value?.getTime();
50
+ const date = value instanceof Date && (0, external_date_fns_namespaceObject.isValid)(value) ? value : void 0;
51
+ const [selectedDate, setSelectedDate] = external_react_namespaceObject.useState(date);
52
+ const [timeValue, setTimeValue] = external_react_namespaceObject.useState(date ? (0, external_date_fns_namespaceObject.format)(date, 'HH:mm') : '');
53
+ const valueTime = date?.getTime();
53
54
  const [seededTime, setSeededTime] = external_react_namespaceObject.useState(valueTime);
54
55
  if (!Object.is(valueTime, seededTime)) {
55
56
  setSeededTime(valueTime);
56
- if (void 0 === value) {
57
- setSelectedDate(void 0);
58
- setTimeValue('');
59
- } else if (!Number.isNaN(valueTime)) {
60
- setSelectedDate(value);
61
- setTimeValue((0, external_date_fns_namespaceObject.format)(value, 'HH:mm'));
62
- }
57
+ setSelectedDate(date);
58
+ setTimeValue(date ? (0, external_date_fns_namespaceObject.format)(date, 'HH:mm') : '');
63
59
  }
64
60
  const handleDateSelect = (date)=>{
65
61
  if (!date) return;
@@ -67,6 +63,7 @@ const datetime_picker_DateTimePicker = /*#__PURE__*/ external_react_namespaceObj
67
63
  date.setHours(selectedDate.getHours());
68
64
  date.setMinutes(selectedDate.getMinutes());
69
65
  date.setSeconds(selectedDate.getSeconds());
66
+ date.setMilliseconds(selectedDate.getMilliseconds());
70
67
  }
71
68
  setSelectedDate(date);
72
69
  onValueChange?.(date);
@@ -1,5 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { format } from "date-fns";
2
+ import { format, isValid } from "date-fns";
3
3
  import { CalendarIcon, Clock } from "lucide-react";
4
4
  import { forwardRef, useId, useState } from "react";
5
5
  import { Button } from "./button.js";
@@ -19,19 +19,15 @@ const datetime_picker_DateTimePicker = /*#__PURE__*/ forwardRef(function({ value
19
19
  };
20
20
  const generatedId = useId();
21
21
  const validationId = errorId ?? `${id ?? `datetime-picker-${generatedId.replace(/:/g, '')}`}-error`;
22
- const [selectedDate, setSelectedDate] = useState(value);
23
- const [timeValue, setTimeValue] = useState(value ? format(value, 'HH:mm') : '');
24
- const valueTime = value?.getTime();
22
+ const date = value instanceof Date && isValid(value) ? value : void 0;
23
+ const [selectedDate, setSelectedDate] = useState(date);
24
+ const [timeValue, setTimeValue] = useState(date ? format(date, 'HH:mm') : '');
25
+ const valueTime = date?.getTime();
25
26
  const [seededTime, setSeededTime] = useState(valueTime);
26
27
  if (!Object.is(valueTime, seededTime)) {
27
28
  setSeededTime(valueTime);
28
- if (void 0 === value) {
29
- setSelectedDate(void 0);
30
- setTimeValue('');
31
- } else if (!Number.isNaN(valueTime)) {
32
- setSelectedDate(value);
33
- setTimeValue(format(value, 'HH:mm'));
34
- }
29
+ setSelectedDate(date);
30
+ setTimeValue(date ? format(date, 'HH:mm') : '');
35
31
  }
36
32
  const handleDateSelect = (date)=>{
37
33
  if (!date) return;
@@ -39,6 +35,7 @@ const datetime_picker_DateTimePicker = /*#__PURE__*/ forwardRef(function({ value
39
35
  date.setHours(selectedDate.getHours());
40
36
  date.setMinutes(selectedDate.getMinutes());
41
37
  date.setSeconds(selectedDate.getSeconds());
38
+ date.setMilliseconds(selectedDate.getMilliseconds());
42
39
  }
43
40
  setSelectedDate(date);
44
41
  onValueChange?.(date);
@@ -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
  })
@@ -4,6 +4,7 @@ import { Upload, X } from "lucide-react";
4
4
  import { forwardRef, useId, useRef, useState } from "react";
5
5
  import { Button } from "./button.js";
6
6
  import { cn } from "../../lib/index.js";
7
+ import { formatFileSize, isFileTypeAccepted } from "./file-validation.js";
7
8
  import { FormFieldError } from "./form-field.js";
8
9
  const file_upload_FileUpload = /*#__PURE__*/ 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) {
9
10
  const generatedId = useId();
@@ -19,25 +20,12 @@ const file_upload_FileUpload = /*#__PURE__*/ forwardRef(function({ id, ariaLabel
19
20
  const [fileErrors, setFileErrors] = useState(new Map());
20
21
  const [previews, setPreviews] = useState([]);
21
22
  const inputRef = useRef(null);
22
- const isFileTypeAccepted = (file)=>{
23
- if (!accept) return true;
24
- const acceptedTypes = accept.split(',').map((type)=>type.trim().toLowerCase());
25
- for (const acceptedType of acceptedTypes)if (acceptedType.endsWith('/*')) {
26
- const baseType = acceptedType.slice(0, -2);
27
- if (file.type.toLowerCase().startsWith(baseType)) return true;
28
- } else if (acceptedType.includes('/')) {
29
- if (file.type.toLowerCase() === acceptedType) return true;
30
- } else if (acceptedType.startsWith('.')) {
31
- if (file.name.toLowerCase().endsWith(acceptedType)) return true;
32
- }
33
- return false;
34
- };
35
23
  const validateFiles = (fileList, startIndex, existingErrors)=>{
36
24
  const validFiles = [];
37
25
  const errors = multiple ? new Map(existingErrors) : new Map();
38
26
  for (const file of fileList){
39
27
  const fileIndex = startIndex + validFiles.length;
40
- if (!isFileTypeAccepted(file)) {
28
+ if (!isFileTypeAccepted(file, accept)) {
41
29
  errors.set(fileIndex, 'File type not accepted');
42
30
  validFiles.push(file);
43
31
  continue;
@@ -129,18 +117,6 @@ const file_upload_FileUpload = /*#__PURE__*/ forwardRef(function({ id, ariaLabel
129
117
  const handleClick = ()=>{
130
118
  if (!disabled) inputRef.current?.click();
131
119
  };
132
- const formatFileSize = (bytes)=>{
133
- if (0 === bytes) return '0 Bytes';
134
- const k = 1024;
135
- const sizes = [
136
- 'Bytes',
137
- 'KB',
138
- 'MB',
139
- 'GB'
140
- ];
141
- const i = Math.floor(Math.log(bytes) / Math.log(k));
142
- return `${Math.round(bytes / k ** i * 100) / 100} ${sizes[i]}`;
143
- };
144
120
  return /*#__PURE__*/ jsxs("fieldset", {
145
121
  ref: ref,
146
122
  "data-slot": "file-upload",
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ formatFileSize: ()=>formatFileSize,
28
+ isFileTypeAccepted: ()=>isFileTypeAccepted,
29
+ validateFiles: ()=>validateFiles
30
+ });
31
+ function acceptEntries(accept) {
32
+ const list = Array.isArray(accept) ? accept : accept.split(',');
33
+ return list.map((entry)=>entry.trim().toLowerCase()).filter(Boolean);
34
+ }
35
+ function isFileTypeAccepted(file, accept) {
36
+ if (!accept) return true;
37
+ const entries = acceptEntries(accept);
38
+ if (0 === entries.length) return true;
39
+ const type = file.type.toLowerCase();
40
+ const name = file.name.toLowerCase();
41
+ return entries.some((entry)=>{
42
+ if (entry.endsWith('/*')) return type.startsWith(entry.slice(0, -1));
43
+ if (entry.includes('/')) return type === entry;
44
+ if (entry.startsWith('.')) return name.endsWith(entry);
45
+ return false;
46
+ });
47
+ }
48
+ function validateFiles(files, { accept, maxSize, maxFiles } = {}) {
49
+ const accepted = [];
50
+ const rejected = [];
51
+ for (const file of files)if (isFileTypeAccepted(file, accept)) if (void 0 !== maxSize && file.size > maxSize) rejected.push({
52
+ file,
53
+ reason: 'size'
54
+ });
55
+ else if (void 0 !== maxFiles && accepted.length >= maxFiles) rejected.push({
56
+ file,
57
+ reason: 'count'
58
+ });
59
+ else accepted.push(file);
60
+ else rejected.push({
61
+ file,
62
+ reason: 'type'
63
+ });
64
+ return {
65
+ accepted,
66
+ rejected
67
+ };
68
+ }
69
+ function formatFileSize(bytes) {
70
+ if (0 === bytes) return '0 Bytes';
71
+ const k = 1024;
72
+ const sizes = [
73
+ 'Bytes',
74
+ 'KB',
75
+ 'MB',
76
+ 'GB'
77
+ ];
78
+ const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
79
+ return `${Math.round(bytes / k ** i * 100) / 100} ${sizes[i]}`;
80
+ }
81
+ exports.formatFileSize = __webpack_exports__.formatFileSize;
82
+ exports.isFileTypeAccepted = __webpack_exports__.isFileTypeAccepted;
83
+ exports.validateFiles = __webpack_exports__.validateFiles;
84
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
85
+ "formatFileSize",
86
+ "isFileTypeAccepted",
87
+ "validateFiles"
88
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
89
+ Object.defineProperty(exports, '__esModule', {
90
+ value: true
91
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * File checks shared by FileUpload, ChatComposerAttachButton and DropzoneOverlay. `accept` matches
3
+ * MIME wildcards (`image/*`), exact MIME types (`image/png`) and extensions (`.pdf`).
4
+ */
5
+ export type FileRejectionReason = 'type' | 'size' | 'count';
6
+ export interface FileRejection {
7
+ file: File;
8
+ reason: FileRejectionReason;
9
+ }
10
+ export interface FileValidationOptions {
11
+ /** A comma-separated `accept` string, or a list of its entries. Omit to accept any type. */
12
+ accept?: string | string[];
13
+ /** Largest accepted size, in bytes. */
14
+ maxSize?: number;
15
+ /** Most files accepted in one batch; the rest are rejected with `count`. */
16
+ maxFiles?: number;
17
+ }
18
+ export declare function isFileTypeAccepted(file: File, accept?: string | string[]): boolean;
19
+ /** Splits a batch into accepted files and rejections, checking type, then size, then count. */
20
+ export declare function validateFiles(files: File[], { accept, maxSize, maxFiles }?: FileValidationOptions): {
21
+ accepted: File[];
22
+ rejected: FileRejection[];
23
+ };
24
+ export declare function formatFileSize(bytes: number): string;
@@ -0,0 +1,51 @@
1
+ function acceptEntries(accept) {
2
+ const list = Array.isArray(accept) ? accept : accept.split(',');
3
+ return list.map((entry)=>entry.trim().toLowerCase()).filter(Boolean);
4
+ }
5
+ function isFileTypeAccepted(file, accept) {
6
+ if (!accept) return true;
7
+ const entries = acceptEntries(accept);
8
+ if (0 === entries.length) return true;
9
+ const type = file.type.toLowerCase();
10
+ const name = file.name.toLowerCase();
11
+ return entries.some((entry)=>{
12
+ if (entry.endsWith('/*')) return type.startsWith(entry.slice(0, -1));
13
+ if (entry.includes('/')) return type === entry;
14
+ if (entry.startsWith('.')) return name.endsWith(entry);
15
+ return false;
16
+ });
17
+ }
18
+ function validateFiles(files, { accept, maxSize, maxFiles } = {}) {
19
+ const accepted = [];
20
+ const rejected = [];
21
+ for (const file of files)if (isFileTypeAccepted(file, accept)) if (void 0 !== maxSize && file.size > maxSize) rejected.push({
22
+ file,
23
+ reason: 'size'
24
+ });
25
+ else if (void 0 !== maxFiles && accepted.length >= maxFiles) rejected.push({
26
+ file,
27
+ reason: 'count'
28
+ });
29
+ else accepted.push(file);
30
+ else rejected.push({
31
+ file,
32
+ reason: 'type'
33
+ });
34
+ return {
35
+ accepted,
36
+ rejected
37
+ };
38
+ }
39
+ function formatFileSize(bytes) {
40
+ if (0 === bytes) return '0 Bytes';
41
+ const k = 1024;
42
+ const sizes = [
43
+ 'Bytes',
44
+ 'KB',
45
+ 'MB',
46
+ 'GB'
47
+ ];
48
+ const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
49
+ return `${Math.round(bytes / k ** i * 100) / 100} ${sizes[i]}`;
50
+ }
51
+ export { formatFileSize, isFileTypeAccepted, validateFiles };