dash-core-components 4.0.0-rc3 → 4.0.0-rc5

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 (39) hide show
  1. package/dash_core_components/async-datepicker.js +1 -1
  2. package/dash_core_components/async-datepicker.js.map +1 -1
  3. package/dash_core_components/async-dropdown.js +1 -1
  4. package/dash_core_components/async-dropdown.js.map +1 -1
  5. package/dash_core_components/async-slider.js +1 -1
  6. package/dash_core_components/async-slider.js.map +1 -1
  7. package/dash_core_components/async-upload.js +2 -1
  8. package/dash_core_components/async-upload.js.map +1 -1
  9. package/dash_core_components/dash_core_components-shared.js +1 -1
  10. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  11. package/dash_core_components/dash_core_components.js +1 -1
  12. package/dash_core_components/dash_core_components.js.map +1 -1
  13. package/dash_core_components/proptypes.js +44 -9
  14. package/lib/components/Button.tsx +48 -0
  15. package/lib/components/Input.tsx +13 -234
  16. package/lib/components/RadioItems.tsx +3 -1
  17. package/lib/components/Tooltip.tsx +1 -0
  18. package/lib/components/Upload.react.js +13 -1
  19. package/lib/components/css/button.css +50 -0
  20. package/lib/components/css/calendar.css +24 -6
  21. package/lib/components/css/datepickers.css +43 -43
  22. package/lib/components/css/dcc.css +1 -1
  23. package/lib/components/css/dropdown.css +36 -8
  24. package/lib/components/css/input.css +8 -2
  25. package/lib/components/css/optionslist.css +2 -1
  26. package/lib/components/css/sliders.css +31 -5
  27. package/lib/components/css/tabs.css +3 -3
  28. package/lib/components/css/textarea.css +10 -0
  29. package/lib/components/css/tooltip.css +1 -1
  30. package/lib/fragments/DatePickerRange.tsx +37 -47
  31. package/lib/fragments/DatePickerSingle.tsx +9 -8
  32. package/lib/fragments/Dropdown.tsx +53 -18
  33. package/lib/fragments/RangeSlider.tsx +21 -66
  34. package/lib/fragments/Upload.react.js +243 -1
  35. package/lib/index.ts +2 -0
  36. package/lib/types.ts +307 -1
  37. package/lib/utils/calendar/Calendar.tsx +64 -34
  38. package/lib/utils/optionRendering.tsx +1 -1
  39. package/package.json +1 -1
@@ -47,6 +47,7 @@ const Dropdown = (props: DropdownProps) => {
47
47
  const dropdownContentRef = useRef<HTMLDivElement>(
48
48
  document.createElement('div')
49
49
  );
50
+ const searchInputRef = useRef<HTMLInputElement>(null);
50
51
 
51
52
  const ctx = window.dash_component_api.useDashContext();
52
53
  const loading = ctx.useLoading();
@@ -234,25 +235,36 @@ const Dropdown = (props: DropdownProps) => {
234
235
  }
235
236
  }, [filteredOptions, isOpen]);
236
237
 
237
- // Focus (and scroll) the first selected item when dropdown opens
238
+ // Focus first selected item or search input when dropdown opens
238
239
  useEffect(() => {
239
- if (!isOpen || multi || search_value) {
240
+ if (!isOpen || search_value) {
240
241
  return;
241
242
  }
242
243
 
243
244
  // waiting for the DOM to be ready after the dropdown renders
244
245
  requestAnimationFrame(() => {
245
- const selectedValue = sanitizedValues[0];
246
-
247
- const selectedElement = dropdownContentRef.current.querySelector(
248
- `.dash-options-list-option-checkbox[value="${selectedValue}"]`
249
- );
246
+ // Try to focus the first selected item (for single-select)
247
+ if (!multi) {
248
+ const selectedValue = sanitizedValues[0];
249
+ if (selectedValue) {
250
+ const selectedElement =
251
+ dropdownContentRef.current.querySelector(
252
+ `.dash-options-list-option-checkbox[value="${selectedValue}"]`
253
+ );
254
+
255
+ if (selectedElement instanceof HTMLElement) {
256
+ selectedElement.focus();
257
+ return;
258
+ }
259
+ }
260
+ }
250
261
 
251
- if (selectedElement instanceof HTMLElement) {
252
- selectedElement?.focus();
262
+ // Fallback: focus search input if available and no selected item was focused
263
+ if (searchable && searchInputRef.current) {
264
+ searchInputRef.current.focus();
253
265
  }
254
266
  });
255
- }, [isOpen, multi, displayOptions, sanitizedValues]);
267
+ }, [isOpen, multi, displayOptions]);
256
268
 
257
269
  // Handle keyboard navigation in popover
258
270
  const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
@@ -271,13 +283,13 @@ const Dropdown = (props: DropdownProps) => {
271
283
  // Don't interfere with the event if the user is using Home/End keys on the search input
272
284
  if (
273
285
  ['Home', 'End'].includes(e.key) &&
274
- document.activeElement instanceof HTMLInputElement
286
+ document.activeElement === searchInputRef.current
275
287
  ) {
276
288
  return;
277
289
  }
278
290
 
279
291
  const focusableElements = e.currentTarget.querySelectorAll(
280
- 'input[type="search"], input[type="checkbox"]:not([disabled])'
292
+ 'input[type="search"], input:not([disabled])'
281
293
  ) as NodeListOf<HTMLElement>;
282
294
 
283
295
  // Don't interfere with the event if there aren't any options that the user can interact with
@@ -335,7 +347,7 @@ const Dropdown = (props: DropdownProps) => {
335
347
  } else {
336
348
  focusableElements[nextIndex].scrollIntoView({
337
349
  behavior: 'auto',
338
- block: 'center',
350
+ block: 'nearest',
339
351
  });
340
352
  }
341
353
  }
@@ -354,8 +366,10 @@ const Dropdown = (props: DropdownProps) => {
354
366
  );
355
367
 
356
368
  const accessibleId = id ?? uuid();
369
+ const positioningContainerRef = useRef<HTMLDivElement>(null);
370
+ const canClearValues = clearable && !disabled && !!sanitizedValues.length;
357
371
 
358
- return (
372
+ const popover = (
359
373
  <Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
360
374
  <Popover.Trigger asChild>
361
375
  <button
@@ -364,9 +378,20 @@ const Dropdown = (props: DropdownProps) => {
364
378
  disabled={disabled}
365
379
  type="button"
366
380
  onKeyDown={e => {
367
- if (e.key === 'ArrowDown') {
381
+ if (['ArrowDown', 'Enter'].includes(e.key)) {
382
+ e.preventDefault();
383
+ }
384
+ }}
385
+ onKeyUp={e => {
386
+ if (['ArrowDown', 'Enter'].includes(e.key)) {
368
387
  setIsOpen(true);
369
388
  }
389
+ if (
390
+ ['Delete', 'Backspace'].includes(e.key) &&
391
+ canClearValues
392
+ ) {
393
+ handleClear();
394
+ }
370
395
  }}
371
396
  className={`dash-dropdown ${className ?? ''}`}
372
397
  style={style}
@@ -403,7 +428,7 @@ const Dropdown = (props: DropdownProps) => {
403
428
  )}
404
429
  </span>
405
430
  )}
406
- {clearable && !disabled && !!sanitizedValues.length && (
431
+ {canClearValues && (
407
432
  <a
408
433
  className="dash-dropdown-clear"
409
434
  onClick={e => {
@@ -426,13 +451,16 @@ const Dropdown = (props: DropdownProps) => {
426
451
  // container is required otherwise popover will be rendered
427
452
  // at document root, which may be outside of the Dash app (i.e.
428
453
  // an embedded app)
429
- container={dropdownContainerRef.current?.parentElement}
454
+ container={positioningContainerRef.current}
430
455
  >
431
456
  <Popover.Content
432
457
  ref={dropdownContentRef}
433
458
  className="dash-dropdown-content"
434
459
  align="start"
435
460
  sideOffset={5}
461
+ collisionBoundary={positioningContainerRef.current?.closest(
462
+ '#_dash-app-content'
463
+ )}
436
464
  onOpenAutoFocus={e => e.preventDefault()}
437
465
  onKeyDown={handleKeyDown}
438
466
  style={{
@@ -451,7 +479,7 @@ const Dropdown = (props: DropdownProps) => {
451
479
  value={search_value || ''}
452
480
  autoComplete="off"
453
481
  onChange={e => onInputChange(e.target.value)}
454
- autoFocus
482
+ ref={searchInputRef}
455
483
  />
456
484
  {search_value && (
457
485
  <button
@@ -491,6 +519,7 @@ const Dropdown = (props: DropdownProps) => {
491
519
  options={displayOptions}
492
520
  selected={sanitizedValues}
493
521
  onSelectionChange={updateSelection}
522
+ inputType={multi ? 'checkbox' : 'radio'}
494
523
  className="dash-dropdown-options"
495
524
  optionClassName="dash-dropdown-option"
496
525
  optionStyle={{
@@ -512,6 +541,12 @@ const Dropdown = (props: DropdownProps) => {
512
541
  </Popover.Portal>
513
542
  </Popover.Root>
514
543
  );
544
+
545
+ return (
546
+ <div ref={positioningContainerRef} className="dash-dropdown-wrapper">
547
+ {popover}
548
+ </div>
549
+ );
515
550
  };
516
551
 
517
552
  export default Dropdown;
@@ -45,9 +45,8 @@ export default function RangeSlider(props: RangeSliderProps) {
45
45
  // For range slider, we expect an array of values
46
46
  const [value, setValue] = useState<number[]>(propValue || []);
47
47
 
48
- // Track slider dimension (width for horizontal, height for vertical) for conditional input rendering
48
+ // Track slider dimension (width for horizontal, height for vertical) for marks rendering
49
49
  const [sliderWidth, setSliderWidth] = useState<number | null>(null);
50
- const [showInputs, setShowInputs] = useState<boolean>(value.length === 2);
51
50
 
52
51
  const sliderRef = useRef<HTMLDivElement>(null);
53
52
  const inputRef = useRef<HTMLInputElement>(null);
@@ -64,25 +63,12 @@ export default function RangeSlider(props: RangeSliderProps) {
64
63
  }
65
64
  }, []);
66
65
 
67
- // Dynamic dimension detection using ResizeObserver (width for horizontal, height for vertical)
66
+ // Dynamic dimension detection using ResizeObserver for marks rendering
68
67
  useEffect(() => {
69
68
  if (!sliderRef.current) {
70
69
  return;
71
70
  }
72
71
 
73
- if (step === null) {
74
- // If the user has explicitly disabled stepping (step=None), then
75
- // the slider values are constrained to the given marks and user
76
- // cannot enter arbitrary values via the input element
77
- setShowInputs(false);
78
- return;
79
- }
80
-
81
- if (!value || value.length > 2) {
82
- setShowInputs(false);
83
- return;
84
- }
85
-
86
72
  const measureWidth = () => {
87
73
  if (sliderRef.current) {
88
74
  const rect = sliderRef.current.getBoundingClientRect();
@@ -90,16 +76,6 @@ export default function RangeSlider(props: RangeSliderProps) {
90
76
  const dimension = vertical ? rect.height : rect.width;
91
77
  if (dimension > 0) {
92
78
  setSliderWidth(dimension);
93
-
94
- // eslint-disable-next-line no-magic-numbers
95
- const HIDE_AT_WIDTH = value.length === 1 ? 200 : 250;
96
- // eslint-disable-next-line no-magic-numbers
97
- const SHOW_AT_WIDTH = value.length === 1 ? 300 : 450;
98
- if (showInputs && dimension < HIDE_AT_WIDTH) {
99
- setShowInputs(false);
100
- } else if (!showInputs && dimension >= SHOW_AT_WIDTH) {
101
- setShowInputs(true);
102
- }
103
79
  }
104
80
  }
105
81
  };
@@ -119,7 +95,7 @@ export default function RangeSlider(props: RangeSliderProps) {
119
95
  return () => {
120
96
  resizeObserver.disconnect();
121
97
  };
122
- }, [showInputs, vertical, step, value]);
98
+ }, [vertical]);
123
99
 
124
100
  // Handle prop value changes - equivalent to componentWillReceiveProps
125
101
  useEffect(() => {
@@ -168,49 +144,22 @@ export default function RangeSlider(props: RangeSliderProps) {
168
144
  });
169
145
  }, [min, max, processedMarks, step, sliderWidth]);
170
146
 
171
- // Calculate dynamic input width based on digits needed and container size
147
+ // Calculate dynamic input width based on min/max values
172
148
  const inputWidth = useMemo(() => {
173
- if (!sliderWidth) {
174
- return '64px'; // fallback to current width
175
- }
176
-
177
- // Count digits needed for min and max values
178
- const maxDigits = Math.max(
179
- String(Math.floor(Math.abs(minMaxValues.max_mark))).length,
180
- String(Math.floor(Math.abs(minMaxValues.min_mark))).length
149
+ const maxIntegerChars = Math.max(
150
+ String(Math.floor(minMaxValues.max_mark)).length,
151
+ String(Math.floor(minMaxValues.min_mark)).length
181
152
  );
182
153
 
183
- // Add 1 for minus sign if min is negative
184
- const totalChars = maxDigits + (minMaxValues.min_mark < 0 ? 1 : 0);
185
-
186
- // Calculate width as percentage of container (5% min, 15% max)
187
- /* eslint-disable no-magic-numbers */
188
- const minWidth = sliderWidth * 0.05;
189
- const maxWidth = sliderWidth * 0.15;
190
- const charBasedWidth = totalChars * 12; // approx 12px per character
191
- /* eslint-enable no-magic-numbers */
192
-
193
- const calculatedWidth = Math.max(
194
- minWidth,
195
- Math.min(maxWidth, charBasedWidth)
154
+ const maxDecimalChars = Math.min(
155
+ (String(stepValue).split('.')[1]?.length ?? -1) + 1,
156
+ 3
196
157
  );
197
158
 
198
- // Add padding if box-sizing is border-box
199
- let inputPadding = 0;
200
- if (inputRef.current) {
201
- const computedStyle = window.getComputedStyle(inputRef.current);
202
- if (computedStyle.boxSizing === 'border-box') {
203
- const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
204
- const paddingRight =
205
- parseFloat(computedStyle.paddingRight) || 0;
206
- inputPadding = paddingLeft + paddingRight;
207
- }
208
- }
209
-
210
- const totalWidth = calculatedWidth + inputPadding;
159
+ const totalChars = maxIntegerChars + maxDecimalChars;
211
160
 
212
- return `${totalWidth}px`;
213
- }, [sliderWidth, minMaxValues.min_mark, minMaxValues.max_mark]);
161
+ return `calc(${totalChars}ch + calc(var(--Dash-Spacing) * 2))`;
162
+ }, [minMaxValues.min_mark, minMaxValues.max_mark, stepValue]);
214
163
 
215
164
  const valueIsValid = (val: number): boolean => {
216
165
  // Check if value is within min/max bounds
@@ -312,11 +261,17 @@ export default function RangeSlider(props: RangeSliderProps) {
312
261
 
313
262
  const classNames = ['dash-slider-container', className].filter(Boolean);
314
263
 
264
+ // Determine if inputs should be rendered at all (CSS will handle responsive visibility)
265
+ const shouldShowInputs =
266
+ step !== null && // Not disabled by step=None
267
+ value.length <= 2 && // Only for single or range sliders
268
+ !vertical; // Only for horizontal sliders
269
+
315
270
  return (
316
271
  <LoadingElement>
317
272
  {loadingProps => (
318
273
  <div id={id} className={classNames.join(' ')} {...loadingProps}>
319
- {showInputs && value.length === 2 && !vertical && (
274
+ {shouldShowInputs && value.length === 2 && (
320
275
  <input
321
276
  type="number"
322
277
  className="dash-input-container dash-range-slider-input dash-range-slider-min-input"
@@ -381,7 +336,7 @@ export default function RangeSlider(props: RangeSliderProps) {
381
336
  disabled={disabled}
382
337
  />
383
338
  )}
384
- {showInputs && !vertical && (
339
+ {shouldShowInputs && (
385
340
  <input
386
341
  ref={inputRef}
387
342
  type="number"
@@ -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 _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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,
package/lib/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
+ import Button from './components/Button';
2
3
  import Checklist from './components/Checklist';
3
4
  import Clipboard from './components/Clipboard.react';
4
5
  import ConfirmDialog from './components/ConfirmDialog.react';
@@ -28,6 +29,7 @@ import Upload from './components/Upload.react';
28
29
  import './components/css/dcc.css';
29
30
 
30
31
  export {
32
+ Button,
31
33
  Checklist,
32
34
  Clipboard,
33
35
  ConfirmDialog,