dash-core-components 4.0.0-rc4 → 4.0.0-rc6
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/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-slider.js +1 -1
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/async-upload.js +2 -1
- package/dash_core_components/async-upload.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/lib/components/Input.tsx +13 -3
- package/lib/components/Tabs.tsx +1 -1
- package/lib/components/Tooltip.tsx +1 -0
- package/lib/components/Upload.react.js +13 -1
- package/lib/components/css/button.css +5 -10
- package/lib/components/css/calendar.css +25 -7
- package/lib/components/css/datepickers.css +98 -39
- package/lib/components/css/dcc.css +2 -2
- package/lib/components/css/dropdown.css +25 -11
- package/lib/components/css/input.css +8 -2
- package/lib/components/css/optionslist.css +2 -1
- package/lib/components/css/sliders.css +15 -6
- package/lib/components/css/textarea.css +10 -0
- package/lib/components/css/tooltip.css +1 -1
- package/lib/fragments/DatePickerRange.tsx +57 -50
- package/lib/fragments/DatePickerSingle.tsx +33 -10
- package/lib/fragments/Dropdown.tsx +19 -5
- package/lib/fragments/RangeSlider.tsx +1 -2
- package/lib/fragments/Upload.react.js +243 -1
- package/lib/utils/calendar/Calendar.tsx +62 -32
- package/package.json +1 -1
|
@@ -51,6 +51,8 @@ const DatePickerRange = ({
|
|
|
51
51
|
end_date_id,
|
|
52
52
|
start_date_placeholder_text = 'Start Date',
|
|
53
53
|
end_date_placeholder_text = 'End Date',
|
|
54
|
+
with_portal = false,
|
|
55
|
+
with_full_screen_portal = false,
|
|
54
56
|
}: DatePickerRangeProps) => {
|
|
55
57
|
const [internalStartDate, setInternalStartDate] = useState(
|
|
56
58
|
strAsDate(start_date)
|
|
@@ -102,6 +104,7 @@ const DatePickerRange = ({
|
|
|
102
104
|
const startInputRef = useRef<HTMLInputElement | null>(null);
|
|
103
105
|
const endInputRef = useRef<HTMLInputElement | null>(null);
|
|
104
106
|
const calendarRef = useRef<CalendarHandle>(null);
|
|
107
|
+
const hasPortal = with_portal || with_full_screen_portal;
|
|
105
108
|
|
|
106
109
|
useEffect(() => {
|
|
107
110
|
setInternalStartDate(strAsDate(start_date));
|
|
@@ -150,17 +153,23 @@ const DatePickerRange = ({
|
|
|
150
153
|
}
|
|
151
154
|
}, [internalStartDate, internalEndDate, updatemode]);
|
|
152
155
|
|
|
156
|
+
const isDateAllowed = useCallback(
|
|
157
|
+
(date?: Date): date is Date => {
|
|
158
|
+
return (
|
|
159
|
+
!!date && !isDateDisabled(date, minDate, maxDate, disabledDates)
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
[minDate, maxDate, disabledDates]
|
|
163
|
+
);
|
|
164
|
+
|
|
153
165
|
const sendStartInputAsDate = useCallback(
|
|
154
166
|
(focusCalendar = false) => {
|
|
155
167
|
if (startInputValue) {
|
|
156
168
|
setInternalStartDate(undefined);
|
|
157
169
|
}
|
|
158
170
|
const parsed = strAsDate(startInputValue, display_format);
|
|
159
|
-
const isValid =
|
|
160
|
-
parsed &&
|
|
161
|
-
!isDateDisabled(parsed, minDate, maxDate, disabledDates);
|
|
162
171
|
|
|
163
|
-
if (
|
|
172
|
+
if (isDateAllowed(parsed)) {
|
|
164
173
|
setInternalStartDate(parsed);
|
|
165
174
|
if (focusCalendar) {
|
|
166
175
|
calendarRef.current?.focusDate(parsed);
|
|
@@ -178,14 +187,7 @@ const DatePickerRange = ({
|
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
},
|
|
181
|
-
[
|
|
182
|
-
startInputValue,
|
|
183
|
-
display_format,
|
|
184
|
-
start_date,
|
|
185
|
-
minDate,
|
|
186
|
-
maxDate,
|
|
187
|
-
disabledDates,
|
|
188
|
-
]
|
|
190
|
+
[startInputValue, display_format, start_date, isDateAllowed]
|
|
189
191
|
);
|
|
190
192
|
|
|
191
193
|
const sendEndInputAsDate = useCallback(
|
|
@@ -194,11 +196,8 @@ const DatePickerRange = ({
|
|
|
194
196
|
setInternalEndDate(undefined);
|
|
195
197
|
}
|
|
196
198
|
const parsed = strAsDate(endInputValue, display_format);
|
|
197
|
-
const isValid =
|
|
198
|
-
parsed &&
|
|
199
|
-
!isDateDisabled(parsed, minDate, maxDate, disabledDates);
|
|
200
199
|
|
|
201
|
-
if (
|
|
200
|
+
if (isDateAllowed(parsed)) {
|
|
202
201
|
setInternalEndDate(parsed);
|
|
203
202
|
if (focusCalendar) {
|
|
204
203
|
calendarRef.current?.focusDate(parsed);
|
|
@@ -216,14 +215,7 @@ const DatePickerRange = ({
|
|
|
216
215
|
}
|
|
217
216
|
}
|
|
218
217
|
},
|
|
219
|
-
[
|
|
220
|
-
endInputValue,
|
|
221
|
-
display_format,
|
|
222
|
-
end_date,
|
|
223
|
-
minDate,
|
|
224
|
-
maxDate,
|
|
225
|
-
disabledDates,
|
|
226
|
-
]
|
|
218
|
+
[endInputValue, display_format, end_date, isDateAllowed]
|
|
227
219
|
);
|
|
228
220
|
|
|
229
221
|
const clearSelection = useCallback(
|
|
@@ -242,15 +234,14 @@ const DatePickerRange = ({
|
|
|
242
234
|
|
|
243
235
|
const handleStartInputKeyDown = useCallback(
|
|
244
236
|
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
245
|
-
if (['ArrowUp', 'ArrowDown'].includes(e.key)) {
|
|
237
|
+
if (['ArrowUp', 'ArrowDown', 'Enter'].includes(e.key)) {
|
|
246
238
|
e.preventDefault();
|
|
247
|
-
sendStartInputAsDate(true);
|
|
248
239
|
if (!isCalendarOpen) {
|
|
249
|
-
|
|
250
|
-
// it opens with the correct date showing
|
|
251
|
-
setTimeout(() => setIsCalendarOpen(true), 0);
|
|
240
|
+
setIsCalendarOpen(true);
|
|
252
241
|
}
|
|
253
|
-
|
|
242
|
+
// Wait for calendar to mount before focusing
|
|
243
|
+
requestAnimationFrame(() => sendStartInputAsDate(true));
|
|
244
|
+
} else if (e.key === 'Tab') {
|
|
254
245
|
sendStartInputAsDate();
|
|
255
246
|
}
|
|
256
247
|
},
|
|
@@ -259,15 +250,14 @@ const DatePickerRange = ({
|
|
|
259
250
|
|
|
260
251
|
const handleEndInputKeyDown = useCallback(
|
|
261
252
|
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
262
|
-
if (['ArrowUp', 'ArrowDown'].includes(e.key)) {
|
|
253
|
+
if (['ArrowUp', 'ArrowDown', 'Enter'].includes(e.key)) {
|
|
263
254
|
e.preventDefault();
|
|
264
|
-
sendEndInputAsDate(true);
|
|
265
255
|
if (!isCalendarOpen) {
|
|
266
|
-
|
|
267
|
-
// it opens with the correct date showing
|
|
268
|
-
setTimeout(() => setIsCalendarOpen(true), 0);
|
|
256
|
+
setIsCalendarOpen(true);
|
|
269
257
|
}
|
|
270
|
-
|
|
258
|
+
// Wait for calendar to mount before focusing
|
|
259
|
+
requestAnimationFrame(() => sendEndInputAsDate(true));
|
|
260
|
+
} else if (e.key === 'Tab') {
|
|
271
261
|
sendEndInputAsDate();
|
|
272
262
|
}
|
|
273
263
|
},
|
|
@@ -346,13 +336,11 @@ const DatePickerRange = ({
|
|
|
346
336
|
id={start_date_id || accessibleId}
|
|
347
337
|
inputClassName="dash-datepicker-input dash-datepicker-start-date"
|
|
348
338
|
value={startInputValue}
|
|
349
|
-
onChange={e => setStartInputValue(e.target
|
|
339
|
+
onChange={e => setStartInputValue(e.target?.value)}
|
|
350
340
|
onKeyDown={handleStartInputKeyDown}
|
|
351
341
|
onFocus={() => {
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
internalStartDate
|
|
355
|
-
);
|
|
342
|
+
if (isCalendarOpen) {
|
|
343
|
+
sendStartInputAsDate();
|
|
356
344
|
}
|
|
357
345
|
}}
|
|
358
346
|
placeholder={start_date_placeholder_text}
|
|
@@ -360,7 +348,7 @@ const DatePickerRange = ({
|
|
|
360
348
|
dir={direction}
|
|
361
349
|
aria-label={start_date_placeholder_text}
|
|
362
350
|
/>
|
|
363
|
-
<ArrowIcon />
|
|
351
|
+
<ArrowIcon className="dash-datepicker-range-arrow" />
|
|
364
352
|
<AutosizeInput
|
|
365
353
|
inputRef={node => {
|
|
366
354
|
endInputRef.current = node;
|
|
@@ -369,13 +357,11 @@ const DatePickerRange = ({
|
|
|
369
357
|
id={end_date_id || accessibleId + '-end-date'}
|
|
370
358
|
inputClassName="dash-datepicker-input dash-datepicker-end-date"
|
|
371
359
|
value={endInputValue}
|
|
372
|
-
onChange={e => setEndInputValue(e.target
|
|
360
|
+
onChange={e => setEndInputValue(e.target?.value)}
|
|
373
361
|
onKeyDown={handleEndInputKeyDown}
|
|
374
362
|
onFocus={() => {
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
internalEndDate
|
|
378
|
-
);
|
|
363
|
+
if (isCalendarOpen) {
|
|
364
|
+
sendEndInputAsDate();
|
|
379
365
|
}
|
|
380
366
|
}}
|
|
381
367
|
placeholder={end_date_placeholder_text}
|
|
@@ -398,9 +384,21 @@ const DatePickerRange = ({
|
|
|
398
384
|
|
|
399
385
|
<Popover.Portal container={containerRef.current}>
|
|
400
386
|
<Popover.Content
|
|
401
|
-
className=
|
|
402
|
-
|
|
403
|
-
|
|
387
|
+
className={`dash-datepicker-content${
|
|
388
|
+
hasPortal ? ' dash-datepicker-portal' : ''
|
|
389
|
+
}${
|
|
390
|
+
with_full_screen_portal
|
|
391
|
+
? ' dash-datepicker-fullscreen'
|
|
392
|
+
: ''
|
|
393
|
+
}`}
|
|
394
|
+
align={hasPortal ? 'center' : 'start'}
|
|
395
|
+
sideOffset={hasPortal ? 0 : 5}
|
|
396
|
+
avoidCollisions={!hasPortal}
|
|
397
|
+
onInteractOutside={
|
|
398
|
+
with_full_screen_portal
|
|
399
|
+
? e => e.preventDefault()
|
|
400
|
+
: undefined
|
|
401
|
+
}
|
|
404
402
|
onOpenAutoFocus={e => e.preventDefault()}
|
|
405
403
|
onCloseAutoFocus={e => {
|
|
406
404
|
e.preventDefault();
|
|
@@ -421,6 +419,15 @@ const DatePickerRange = ({
|
|
|
421
419
|
}
|
|
422
420
|
}}
|
|
423
421
|
>
|
|
422
|
+
{with_full_screen_portal && (
|
|
423
|
+
<button
|
|
424
|
+
className="dash-datepicker-close-button"
|
|
425
|
+
onClick={() => setIsCalendarOpen(false)}
|
|
426
|
+
aria-label="Close calendar"
|
|
427
|
+
>
|
|
428
|
+
<Cross1Icon />
|
|
429
|
+
</button>
|
|
430
|
+
)}
|
|
424
431
|
<Calendar
|
|
425
432
|
ref={calendarRef}
|
|
426
433
|
initialVisibleDate={initialCalendarDate}
|
|
@@ -39,6 +39,8 @@ const DatePickerSingle = ({
|
|
|
39
39
|
day_size = 34,
|
|
40
40
|
number_of_months_shown = 1,
|
|
41
41
|
calendar_orientation,
|
|
42
|
+
with_portal = false,
|
|
43
|
+
with_full_screen_portal = false,
|
|
42
44
|
}: DatePickerSingleProps) => {
|
|
43
45
|
const [internalDate, setInternalDate] = useState(strAsDate(date));
|
|
44
46
|
const direction = is_RTL
|
|
@@ -61,6 +63,7 @@ const DatePickerSingle = ({
|
|
|
61
63
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
62
64
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
63
65
|
const calendarRef = useRef<CalendarHandle>(null);
|
|
66
|
+
const hasPortal = with_portal || with_full_screen_portal;
|
|
64
67
|
|
|
65
68
|
useEffect(() => {
|
|
66
69
|
setInternalDate(strAsDate(date));
|
|
@@ -124,15 +127,14 @@ const DatePickerSingle = ({
|
|
|
124
127
|
|
|
125
128
|
const handleInputKeyDown = useCallback(
|
|
126
129
|
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
127
|
-
if (['ArrowUp', 'ArrowDown'].includes(e.key)) {
|
|
130
|
+
if (['ArrowUp', 'ArrowDown', 'Enter'].includes(e.key)) {
|
|
128
131
|
e.preventDefault();
|
|
129
|
-
parseUserInput(true);
|
|
130
132
|
if (!isCalendarOpen) {
|
|
131
|
-
|
|
132
|
-
// it opens with the correct date showing
|
|
133
|
-
setTimeout(() => setIsCalendarOpen(true), 0);
|
|
133
|
+
setIsCalendarOpen(true);
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
// Wait for calendar to mount before focusing
|
|
136
|
+
requestAnimationFrame(() => parseUserInput(true));
|
|
137
|
+
} else if (e.key === 'Tab') {
|
|
136
138
|
parseUserInput();
|
|
137
139
|
}
|
|
138
140
|
},
|
|
@@ -178,7 +180,7 @@ const DatePickerSingle = ({
|
|
|
178
180
|
id={accessibleId}
|
|
179
181
|
inputClassName="dash-datepicker-input dash-datepicker-end-date"
|
|
180
182
|
value={inputValue}
|
|
181
|
-
onChange={e => setInputValue(e.target
|
|
183
|
+
onChange={e => setInputValue(e.target?.value)}
|
|
182
184
|
onKeyDown={handleInputKeyDown}
|
|
183
185
|
placeholder={placeholder}
|
|
184
186
|
disabled={disabled}
|
|
@@ -201,9 +203,21 @@ const DatePickerSingle = ({
|
|
|
201
203
|
|
|
202
204
|
<Popover.Portal container={containerRef.current}>
|
|
203
205
|
<Popover.Content
|
|
204
|
-
className=
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
className={`dash-datepicker-content${
|
|
207
|
+
hasPortal ? ' dash-datepicker-portal' : ''
|
|
208
|
+
}${
|
|
209
|
+
with_full_screen_portal
|
|
210
|
+
? ' dash-datepicker-fullscreen'
|
|
211
|
+
: ''
|
|
212
|
+
}`}
|
|
213
|
+
align={hasPortal ? 'center' : 'start'}
|
|
214
|
+
sideOffset={hasPortal ? 0 : 5}
|
|
215
|
+
avoidCollisions={!hasPortal}
|
|
216
|
+
onInteractOutside={
|
|
217
|
+
with_full_screen_portal
|
|
218
|
+
? e => e.preventDefault()
|
|
219
|
+
: undefined
|
|
220
|
+
}
|
|
207
221
|
onOpenAutoFocus={e => e.preventDefault()}
|
|
208
222
|
onCloseAutoFocus={e => {
|
|
209
223
|
e.preventDefault();
|
|
@@ -213,6 +227,15 @@ const DatePickerSingle = ({
|
|
|
213
227
|
}
|
|
214
228
|
}}
|
|
215
229
|
>
|
|
230
|
+
{with_full_screen_portal && (
|
|
231
|
+
<button
|
|
232
|
+
className="dash-datepicker-close-button"
|
|
233
|
+
onClick={() => setIsCalendarOpen(false)}
|
|
234
|
+
aria-label="Close calendar"
|
|
235
|
+
>
|
|
236
|
+
<Cross1Icon />
|
|
237
|
+
</button>
|
|
238
|
+
)}
|
|
216
239
|
<Calendar
|
|
217
240
|
ref={calendarRef}
|
|
218
241
|
initialVisibleDate={initialMonth}
|
|
@@ -283,7 +283,7 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
283
283
|
// Don't interfere with the event if the user is using Home/End keys on the search input
|
|
284
284
|
if (
|
|
285
285
|
['Home', 'End'].includes(e.key) &&
|
|
286
|
-
document.activeElement
|
|
286
|
+
document.activeElement === searchInputRef.current
|
|
287
287
|
) {
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
@@ -367,6 +367,7 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
367
367
|
|
|
368
368
|
const accessibleId = id ?? uuid();
|
|
369
369
|
const positioningContainerRef = useRef<HTMLDivElement>(null);
|
|
370
|
+
const canClearValues = clearable && !disabled && !!sanitizedValues.length;
|
|
370
371
|
|
|
371
372
|
const popover = (
|
|
372
373
|
<Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
|
|
@@ -377,13 +378,22 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
377
378
|
disabled={disabled}
|
|
378
379
|
type="button"
|
|
379
380
|
onKeyDown={e => {
|
|
380
|
-
if (e.key
|
|
381
|
+
if (['ArrowDown', 'Enter'].includes(e.key)) {
|
|
381
382
|
e.preventDefault();
|
|
383
|
+
}
|
|
384
|
+
}}
|
|
385
|
+
onKeyUp={e => {
|
|
386
|
+
if (['ArrowDown', 'Enter'].includes(e.key)) {
|
|
382
387
|
setIsOpen(true);
|
|
383
388
|
}
|
|
389
|
+
if (
|
|
390
|
+
['Delete', 'Backspace'].includes(e.key) &&
|
|
391
|
+
canClearValues
|
|
392
|
+
) {
|
|
393
|
+
handleClear();
|
|
394
|
+
}
|
|
384
395
|
}}
|
|
385
396
|
className={`dash-dropdown ${className ?? ''}`}
|
|
386
|
-
style={style}
|
|
387
397
|
aria-labelledby={`${accessibleId}-value-count ${accessibleId}-value`}
|
|
388
398
|
aria-haspopup="listbox"
|
|
389
399
|
aria-expanded={isOpen}
|
|
@@ -417,7 +427,7 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
417
427
|
)}
|
|
418
428
|
</span>
|
|
419
429
|
)}
|
|
420
|
-
{
|
|
430
|
+
{canClearValues && (
|
|
421
431
|
<a
|
|
422
432
|
className="dash-dropdown-clear"
|
|
423
433
|
onClick={e => {
|
|
@@ -529,7 +539,11 @@ const Dropdown = (props: DropdownProps) => {
|
|
|
529
539
|
);
|
|
530
540
|
|
|
531
541
|
return (
|
|
532
|
-
<div
|
|
542
|
+
<div
|
|
543
|
+
ref={positioningContainerRef}
|
|
544
|
+
className="dash-dropdown-wrapper"
|
|
545
|
+
style={style}
|
|
546
|
+
>
|
|
533
547
|
{popover}
|
|
534
548
|
</div>
|
|
535
549
|
);
|
|
@@ -157,9 +157,8 @@ export default function RangeSlider(props: RangeSliderProps) {
|
|
|
157
157
|
);
|
|
158
158
|
|
|
159
159
|
const totalChars = maxIntegerChars + maxDecimalChars;
|
|
160
|
-
const charWidth = 12;
|
|
161
160
|
|
|
162
|
-
return
|
|
161
|
+
return `calc(${totalChars}ch + calc(var(--Dash-Spacing) * 2))`;
|
|
163
162
|
}, [minMaxValues.min_mark, minMaxValues.max_mark, stepValue]);
|
|
164
163
|
|
|
165
164
|
const valueIsValid = (val: number): boolean => {
|
|
@@ -9,11 +9,242 @@ var _reactDropzone = _interopRequireDefault(require("react-dropzone"));
|
|
|
9
9
|
var _Upload = require("../components/Upload.react");
|
|
10
10
|
var _LoadingElement = _interopRequireDefault(require("../utils/LoadingElement"));
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
|
|
13
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
14
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
15
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
16
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
19
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
13
20
|
class Upload extends _react.Component {
|
|
14
21
|
constructor() {
|
|
15
22
|
super();
|
|
16
23
|
this.onDrop = this.onDrop.bind(this);
|
|
24
|
+
this.getDataTransferItems = this.getDataTransferItems.bind(this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Check if file matches the accept criteria
|
|
28
|
+
fileMatchesAccept(file, accept) {
|
|
29
|
+
if (!accept) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
var acceptList = Array.isArray(accept) ? accept : accept.split(',');
|
|
33
|
+
var fileName = file.name.toLowerCase();
|
|
34
|
+
var fileType = file.type.toLowerCase();
|
|
35
|
+
return acceptList.some(acceptItem => {
|
|
36
|
+
var item = acceptItem.trim().toLowerCase();
|
|
37
|
+
|
|
38
|
+
// Exact MIME type match
|
|
39
|
+
if (item === fileType) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Wildcard MIME type (e.g., image/*)
|
|
44
|
+
if (item.endsWith('/*')) {
|
|
45
|
+
var wildcardSuffixLength = 2;
|
|
46
|
+
var baseType = item.slice(0, -wildcardSuffixLength);
|
|
47
|
+
return fileType.startsWith(baseType + '/');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// File extension match (e.g., .jpg)
|
|
51
|
+
if (item.startsWith('.')) {
|
|
52
|
+
return fileName.endsWith(item);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Recursively traverse folder structure and extract all files
|
|
59
|
+
traverseFileTree(item) {
|
|
60
|
+
var _arguments = arguments,
|
|
61
|
+
_this = this;
|
|
62
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
63
|
+
var path, accept, files, dirReader;
|
|
64
|
+
return _regenerator().w(function (_context2) {
|
|
65
|
+
while (1) switch (_context2.n) {
|
|
66
|
+
case 0:
|
|
67
|
+
path = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : '';
|
|
68
|
+
accept = _this.props.accept;
|
|
69
|
+
files = [];
|
|
70
|
+
if (!item.isFile) {
|
|
71
|
+
_context2.n = 1;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return _context2.a(2, new Promise(resolve => {
|
|
75
|
+
item.file(file => {
|
|
76
|
+
// Check if file matches accept criteria
|
|
77
|
+
if (!_this.fileMatchesAccept(file, accept)) {
|
|
78
|
+
resolve([]);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Preserve folder structure in file name
|
|
83
|
+
var relativePath = path + file.name;
|
|
84
|
+
Object.defineProperty(file, 'name', {
|
|
85
|
+
writable: true,
|
|
86
|
+
value: relativePath
|
|
87
|
+
});
|
|
88
|
+
resolve([file]);
|
|
89
|
+
});
|
|
90
|
+
}));
|
|
91
|
+
case 1:
|
|
92
|
+
if (!item.isDirectory) {
|
|
93
|
+
_context2.n = 2;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
dirReader = item.createReader();
|
|
97
|
+
return _context2.a(2, new Promise(resolve => {
|
|
98
|
+
var readEntries = () => {
|
|
99
|
+
dirReader.readEntries(/*#__PURE__*/function () {
|
|
100
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(entries) {
|
|
101
|
+
var _iterator, _step, entry, entryFiles, _t;
|
|
102
|
+
return _regenerator().w(function (_context) {
|
|
103
|
+
while (1) switch (_context.p = _context.n) {
|
|
104
|
+
case 0:
|
|
105
|
+
if (!(entries.length === 0)) {
|
|
106
|
+
_context.n = 1;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
resolve(files);
|
|
110
|
+
_context.n = 10;
|
|
111
|
+
break;
|
|
112
|
+
case 1:
|
|
113
|
+
_iterator = _createForOfIteratorHelper(entries);
|
|
114
|
+
_context.p = 2;
|
|
115
|
+
_iterator.s();
|
|
116
|
+
case 3:
|
|
117
|
+
if ((_step = _iterator.n()).done) {
|
|
118
|
+
_context.n = 6;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
entry = _step.value;
|
|
122
|
+
_context.n = 4;
|
|
123
|
+
return _this.traverseFileTree(entry, path + item.name + '/');
|
|
124
|
+
case 4:
|
|
125
|
+
entryFiles = _context.v;
|
|
126
|
+
files.push(...entryFiles);
|
|
127
|
+
case 5:
|
|
128
|
+
_context.n = 3;
|
|
129
|
+
break;
|
|
130
|
+
case 6:
|
|
131
|
+
_context.n = 8;
|
|
132
|
+
break;
|
|
133
|
+
case 7:
|
|
134
|
+
_context.p = 7;
|
|
135
|
+
_t = _context.v;
|
|
136
|
+
_iterator.e(_t);
|
|
137
|
+
case 8:
|
|
138
|
+
_context.p = 8;
|
|
139
|
+
_iterator.f();
|
|
140
|
+
return _context.f(8);
|
|
141
|
+
case 9:
|
|
142
|
+
// Continue reading (directories may have more than 100 entries)
|
|
143
|
+
readEntries();
|
|
144
|
+
case 10:
|
|
145
|
+
return _context.a(2);
|
|
146
|
+
}
|
|
147
|
+
}, _callee, null, [[2, 7, 8, 9]]);
|
|
148
|
+
}));
|
|
149
|
+
return function (_x) {
|
|
150
|
+
return _ref.apply(this, arguments);
|
|
151
|
+
};
|
|
152
|
+
}());
|
|
153
|
+
};
|
|
154
|
+
readEntries();
|
|
155
|
+
}));
|
|
156
|
+
case 2:
|
|
157
|
+
return _context2.a(2, files);
|
|
158
|
+
}
|
|
159
|
+
}, _callee2);
|
|
160
|
+
}))();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Custom data transfer handler that supports folders
|
|
164
|
+
getDataTransferItems(event) {
|
|
165
|
+
var _this2 = this;
|
|
166
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
167
|
+
var multiple, items, files, _i, _items, item, entry, entryFiles, file;
|
|
168
|
+
return _regenerator().w(function (_context3) {
|
|
169
|
+
while (1) switch (_context3.n) {
|
|
170
|
+
case 0:
|
|
171
|
+
multiple = _this2.props.multiple; // If multiple is not enabled, use default behavior (files only)
|
|
172
|
+
if (multiple) {
|
|
173
|
+
_context3.n = 3;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (!event.dataTransfer) {
|
|
177
|
+
_context3.n = 1;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
return _context3.a(2, Array.from(event.dataTransfer.files));
|
|
181
|
+
case 1:
|
|
182
|
+
if (!(event.target && event.target.files)) {
|
|
183
|
+
_context3.n = 2;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
return _context3.a(2, Array.from(event.target.files));
|
|
187
|
+
case 2:
|
|
188
|
+
return _context3.a(2, []);
|
|
189
|
+
case 3:
|
|
190
|
+
if (!(event.dataTransfer && event.dataTransfer.items)) {
|
|
191
|
+
_context3.n = 9;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
items = Array.from(event.dataTransfer.items);
|
|
195
|
+
files = [];
|
|
196
|
+
_i = 0, _items = items;
|
|
197
|
+
case 4:
|
|
198
|
+
if (!(_i < _items.length)) {
|
|
199
|
+
_context3.n = 8;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
item = _items[_i];
|
|
203
|
+
if (!(item.kind === 'file')) {
|
|
204
|
+
_context3.n = 7;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
entry = item.webkitGetAsEntry ? item.webkitGetAsEntry() : null;
|
|
208
|
+
if (!entry) {
|
|
209
|
+
_context3.n = 6;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
_context3.n = 5;
|
|
213
|
+
return _this2.traverseFileTree(entry);
|
|
214
|
+
case 5:
|
|
215
|
+
entryFiles = _context3.v;
|
|
216
|
+
files.push(...entryFiles);
|
|
217
|
+
_context3.n = 7;
|
|
218
|
+
break;
|
|
219
|
+
case 6:
|
|
220
|
+
// Fallback for browsers without webkitGetAsEntry
|
|
221
|
+
file = item.getAsFile();
|
|
222
|
+
if (file) {
|
|
223
|
+
files.push(file);
|
|
224
|
+
}
|
|
225
|
+
case 7:
|
|
226
|
+
_i++;
|
|
227
|
+
_context3.n = 4;
|
|
228
|
+
break;
|
|
229
|
+
case 8:
|
|
230
|
+
return _context3.a(2, files);
|
|
231
|
+
case 9:
|
|
232
|
+
if (!(event.target && event.target.files)) {
|
|
233
|
+
_context3.n = 10;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
return _context3.a(2, Array.from(event.target.files));
|
|
237
|
+
case 10:
|
|
238
|
+
if (!(event.dataTransfer && event.dataTransfer.files)) {
|
|
239
|
+
_context3.n = 11;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
return _context3.a(2, Array.from(event.dataTransfer.files));
|
|
243
|
+
case 11:
|
|
244
|
+
return _context3.a(2, []);
|
|
245
|
+
}
|
|
246
|
+
}, _callee3);
|
|
247
|
+
}))();
|
|
17
248
|
}
|
|
18
249
|
onDrop(files) {
|
|
19
250
|
var _this$props = this.props,
|
|
@@ -61,6 +292,7 @@ class Upload extends _react.Component {
|
|
|
61
292
|
max_size = _this$props2.max_size,
|
|
62
293
|
min_size = _this$props2.min_size,
|
|
63
294
|
multiple = _this$props2.multiple,
|
|
295
|
+
enable_folder_selection = _this$props2.enable_folder_selection,
|
|
64
296
|
className = _this$props2.className,
|
|
65
297
|
className_active = _this$props2.className_active,
|
|
66
298
|
className_reject = _this$props2.className_reject,
|
|
@@ -72,6 +304,14 @@ class Upload extends _react.Component {
|
|
|
72
304
|
var activeStyle = className_active ? undefined : style_active;
|
|
73
305
|
var disabledStyle = className_disabled ? undefined : style_disabled;
|
|
74
306
|
var rejectStyle = className_reject ? undefined : style_reject;
|
|
307
|
+
|
|
308
|
+
// Enable folder selection in file picker when explicitly requested
|
|
309
|
+
// Note: This makes individual files unselectable in the file picker
|
|
310
|
+
var inputProps = multiple && enable_folder_selection ? {
|
|
311
|
+
webkitdirectory: 'true',
|
|
312
|
+
directory: 'true',
|
|
313
|
+
mozdirectory: 'true'
|
|
314
|
+
} : {};
|
|
75
315
|
return /*#__PURE__*/_react.default.createElement(_LoadingElement.default, {
|
|
76
316
|
id: id
|
|
77
317
|
}, /*#__PURE__*/_react.default.createElement(_reactDropzone.default, {
|
|
@@ -82,6 +322,8 @@ class Upload extends _react.Component {
|
|
|
82
322
|
maxSize: max_size === -1 ? Infinity : max_size,
|
|
83
323
|
minSize: min_size,
|
|
84
324
|
multiple: multiple,
|
|
325
|
+
inputProps: inputProps,
|
|
326
|
+
getDataTransferItems: this.getDataTransferItems,
|
|
85
327
|
className: className,
|
|
86
328
|
activeClassName: className_active,
|
|
87
329
|
rejectClassName: className_reject,
|