ywana-core8 0.1.83 → 0.1.84

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.
@@ -1,5 +1,5 @@
1
1
  import 'material-design-icons-iconfont/dist/material-design-icons.css';
2
- import React, { useContext, useMemo, useCallback, useState, useEffect, useRef, Fragment as Fragment$2 } from 'react';
2
+ import React, { useContext, useMemo, useCallback, useState, useEffect, useRef, Fragment as Fragment$2, createContext } from 'react';
3
3
  import ResumableJS from 'resumablejs';
4
4
  import RSwitch from 'react-switch';
5
5
  import { Store, ReactNotifications } from 'react-notifications-component';
@@ -11341,10 +11341,20 @@ Token.defaultProps = {
11341
11341
  variant: 'default'
11342
11342
  };
11343
11343
 
11344
- var _excluded$4 = ["nodes", "children", "searchable", "searchPlaceholder", "searchBy", "filterable", "sortable", "sortBy", "sortDirection", "multiSelect", "onMultiSelect", "expandAll", "collapseAll", "onExpandAll", "onCollapseAll", "disabled", "loading", "empty", "emptyMessage", "emptyIcon", "className", "style", "ariaLabel"],
11344
+ var _excluded$4 = ["nodes", "children", "searchable", "searchPlaceholder", "searchBy", "filterable", "sortable", "sortBy", "sortDirection", "multiSelect", "onMultiSelect", "showExpandIcon", "onExpandAll", "onCollapseAll", "disabled", "loading", "empty", "emptyMessage", "emptyIcon", "className", "style", "ariaLabel"],
11345
11345
  _excluded2$1 = ["id", "icon", "label", "tooltip", "open", "children", "actions", "onSelect", "disabled", "draggable", "onDragStart", "onDragEnd", "onDrop", "expandable", "level", "hasChildren", "loading", "badge", "className", "style"],
11346
11346
  _excluded3 = ["id", "icon", "label", "actions", "onSelect", "selected", "onCheck", "checked", "disabled", "draggable", "onDragStart", "onDragEnd", "onDrop", "level", "badge", "tooltip", "className", "style"];
11347
11347
 
11348
+ // Context for tree state
11349
+ var TreeContext = createContext({
11350
+ multiSelect: false,
11351
+ selectedItems: [],
11352
+ onMultiSelect: null,
11353
+ searchTerm: '',
11354
+ forceExpandAll: false,
11355
+ forceCollapseAll: false
11356
+ });
11357
+
11348
11358
  /**
11349
11359
  * Enhanced Tree component with improved functionality while maintaining 100% compatibility
11350
11360
  */
@@ -11356,13 +11366,13 @@ var Tree = function Tree(props) {
11356
11366
  searchable = _props$searchable === void 0 ? false : _props$searchable,
11357
11367
  _props$searchPlacehol = props.searchPlaceholder,
11358
11368
  searchPlaceholder = _props$searchPlacehol === void 0 ? "Search..." : _props$searchPlacehol,
11369
+ _props$searchBy = props.searchBy,
11370
+ searchBy = _props$searchBy === void 0 ? ['label'] : _props$searchBy,
11359
11371
  _props$multiSelect = props.multiSelect,
11360
11372
  multiSelect = _props$multiSelect === void 0 ? false : _props$multiSelect,
11361
11373
  onMultiSelect = props.onMultiSelect,
11362
- _props$expandAll = props.expandAll,
11363
- expandAll = _props$expandAll === void 0 ? false : _props$expandAll,
11364
- _props$collapseAll = props.collapseAll,
11365
- collapseAll = _props$collapseAll === void 0 ? false : _props$collapseAll,
11374
+ _props$showExpandIcon = props.showExpandIcon,
11375
+ showExpandIcon = _props$showExpandIcon === void 0 ? false : _props$showExpandIcon,
11366
11376
  onExpandAll = props.onExpandAll,
11367
11377
  onCollapseAll = props.onCollapseAll,
11368
11378
  _props$disabled = props.disabled,
@@ -11383,8 +11393,18 @@ var Tree = function Tree(props) {
11383
11393
  searchTerm = _useState[0],
11384
11394
  setSearchTerm = _useState[1];
11385
11395
  var _useState2 = useState([]),
11396
+ selectedItems = _useState2[0],
11386
11397
  setSelectedItems = _useState2[1];
11387
11398
  useState(new Set());
11399
+ var _useState4 = useState(false),
11400
+ allExpanded = _useState4[0],
11401
+ setAllExpanded = _useState4[1];
11402
+ var _useState5 = useState(false),
11403
+ forceExpandAll = _useState5[0],
11404
+ setForceExpandAll = _useState5[1];
11405
+ var _useState6 = useState(false),
11406
+ forceCollapseAll = _useState6[0],
11407
+ setForceCollapseAll = _useState6[1];
11388
11408
  var treeRef = useRef(null);
11389
11409
 
11390
11410
  // Validate props
@@ -11397,8 +11417,70 @@ var Tree = function Tree(props) {
11397
11417
  setSearchTerm(value);
11398
11418
  }, []);
11399
11419
 
11420
+ // Apply expansion state to nodes based on current tree state
11421
+ var applyExpansionState = useCallback(function (nodeElements) {
11422
+ return React.Children.toArray(nodeElements).map(function (child) {
11423
+ var _child$type;
11424
+ if (!React.isValidElement(child)) return child;
11425
+
11426
+ // If it's a TreeNode, apply the current expansion state
11427
+ if (((_child$type = child.type) == null ? void 0 : _child$type.displayName) === 'TreeNode' || child.props.hasOwnProperty('open')) {
11428
+ var processedChildren = child.props.children ? applyExpansionState(child.props.children) : child.props.children;
11429
+ return React.cloneElement(child, _extends({}, child.props, {
11430
+ open: allExpanded,
11431
+ // Apply current expansion state
11432
+ children: processedChildren
11433
+ }));
11434
+ }
11435
+ return child;
11436
+ });
11437
+ }, [allExpanded]);
11438
+
11439
+ // Filter nodes based on search term and auto-expand matching nodes
11440
+ var filterNodes = useCallback(function (nodeElements, searchTerm) {
11441
+ if (!searchTerm.trim()) {
11442
+ // When search is cleared, apply current expansion state
11443
+ return applyExpansionState(nodeElements);
11444
+ }
11445
+ return React.Children.toArray(nodeElements).map(function (child) {
11446
+ if (!React.isValidElement(child)) return child;
11447
+
11448
+ // Check if current node matches search
11449
+ var label = child.props.label || '';
11450
+ var matches = searchBy.some(function (field) {
11451
+ var value = child.props[field] || label;
11452
+ return typeof value === 'string' && value.toLowerCase().includes(searchTerm.toLowerCase());
11453
+ });
11454
+
11455
+ // Check if any children match (recursive)
11456
+ var hasMatchingChildren = false;
11457
+ var filteredChildren = child.props.children;
11458
+ if (child.props.children) {
11459
+ filteredChildren = filterNodes(child.props.children, searchTerm);
11460
+ hasMatchingChildren = React.Children.count(filteredChildren) > 0;
11461
+ }
11462
+
11463
+ // If current node or children match, include it and auto-expand
11464
+ if (matches || hasMatchingChildren) {
11465
+ var _child$type2;
11466
+ // Clone the element and force it to be open if it's a TreeNode
11467
+ if (((_child$type2 = child.type) == null ? void 0 : _child$type2.displayName) === 'TreeNode' || child.props.hasOwnProperty('open')) {
11468
+ return React.cloneElement(child, _extends({}, child.props, {
11469
+ open: true,
11470
+ // Auto-expand nodes with matches during search
11471
+ children: filteredChildren
11472
+ }));
11473
+ }
11474
+ return React.cloneElement(child, _extends({}, child.props, {
11475
+ children: filteredChildren
11476
+ }));
11477
+ }
11478
+ return null;
11479
+ }).filter(Boolean);
11480
+ }, [searchBy, applyExpansionState]);
11481
+
11400
11482
  // Handle multi-selection
11401
- useCallback(function (id, selected) {
11483
+ var handleMultiSelect = useCallback(function (id, selected) {
11402
11484
  if (!multiSelect) return;
11403
11485
  setSelectedItems(function (prev) {
11404
11486
  var newSelected = selected ? [].concat(prev, [id]) : prev.filter(function (item) {
@@ -11411,15 +11493,26 @@ var Tree = function Tree(props) {
11411
11493
  });
11412
11494
  }, [multiSelect, onMultiSelect]);
11413
11495
 
11414
- // Handle expand/collapse all
11415
- var handleExpandAll = useCallback(function () {
11416
- if (onExpandAll) onExpandAll();
11417
- // Implementation would depend on tree structure
11418
- }, [onExpandAll]);
11419
- var handleCollapseAll = useCallback(function () {
11420
- if (onCollapseAll) onCollapseAll();
11421
- // Implementation would depend on tree structure
11422
- }, [onCollapseAll]);
11496
+ // Handle expand/collapse toggle - using context to propagate to all TreeNodes
11497
+ var handleExpandToggle = useCallback(function () {
11498
+ var newState = !allExpanded;
11499
+ setAllExpanded(newState);
11500
+ if (newState) {
11501
+ if (onExpandAll) onExpandAll();
11502
+ // Trigger expand all via context
11503
+ setForceExpandAll(true);
11504
+ setTimeout(function () {
11505
+ return setForceExpandAll(false);
11506
+ }, 100);
11507
+ } else {
11508
+ if (onCollapseAll) onCollapseAll();
11509
+ // Trigger collapse all via context
11510
+ setForceCollapseAll(true);
11511
+ setTimeout(function () {
11512
+ return setForceCollapseAll(false);
11513
+ }, 100);
11514
+ }
11515
+ }, [allExpanded, onExpandAll, onCollapseAll]);
11423
11516
 
11424
11517
  // Generate CSS classes
11425
11518
  var cssClasses = ['tree', disabled && 'tree--disabled', loading && 'tree--loading', searchable && 'tree--searchable', multiSelect && 'tree--multi-select', className].filter(Boolean).join(' ');
@@ -11467,11 +11560,23 @@ var Tree = function Tree(props) {
11467
11560
  size: "large"
11468
11561
  }), /*#__PURE__*/React.createElement(Text, null, emptyMessage)));
11469
11562
  }
11470
- return /*#__PURE__*/React.createElement("div", _extends({
11563
+ var contextValue = {
11564
+ multiSelect: multiSelect,
11565
+ selectedItems: selectedItems,
11566
+ onMultiSelect: handleMultiSelect,
11567
+ searchTerm: searchTerm,
11568
+ forceExpandAll: forceExpandAll,
11569
+ forceCollapseAll: forceCollapseAll
11570
+ };
11571
+ return /*#__PURE__*/React.createElement(TreeContext.Provider, {
11572
+ value: contextValue
11573
+ }, /*#__PURE__*/React.createElement("div", _extends({
11471
11574
  className: cssClasses,
11472
11575
  style: style,
11473
11576
  ref: treeRef
11474
- }, ariaAttributes, restProps), searchable && /*#__PURE__*/React.createElement("div", {
11577
+ }, ariaAttributes, restProps), (searchable || showExpandIcon) && /*#__PURE__*/React.createElement("div", {
11578
+ className: "tree__header " + (!searchable && showExpandIcon ? 'tree__header--expand-only' : '')
11579
+ }, searchable && /*#__PURE__*/React.createElement("div", {
11475
11580
  className: "tree__search"
11476
11581
  }, /*#__PURE__*/React.createElement(TextField, {
11477
11582
  id: "tree-search",
@@ -11481,29 +11586,17 @@ var Tree = function Tree(props) {
11481
11586
  icon: "search",
11482
11587
  outlined: true,
11483
11588
  size: "small"
11484
- })), (expandAll || collapseAll) && /*#__PURE__*/React.createElement("div", {
11485
- className: "tree__controls"
11486
- }, expandAll && /*#__PURE__*/React.createElement("button", {
11487
- className: "tree__control-button",
11488
- onClick: handleExpandAll,
11489
- "aria-label": "Expand all nodes"
11589
+ })), showExpandIcon && /*#__PURE__*/React.createElement("div", {
11590
+ className: "tree__expand-control"
11490
11591
  }, /*#__PURE__*/React.createElement(Icon, {
11491
- icon: "unfold_more",
11492
- size: "small"
11493
- }), /*#__PURE__*/React.createElement(Text, {
11494
- size: "sm"
11495
- }, "Expand All")), collapseAll && /*#__PURE__*/React.createElement("button", {
11496
- className: "tree__control-button",
11497
- onClick: handleCollapseAll,
11498
- "aria-label": "Collapse all nodes"
11499
- }, /*#__PURE__*/React.createElement(Icon, {
11500
- icon: "unfold_less",
11501
- size: "small"
11502
- }), /*#__PURE__*/React.createElement(Text, {
11503
- size: "sm"
11504
- }, "Collapse All"))), /*#__PURE__*/React.createElement("div", {
11592
+ icon: allExpanded ? "unfold_less" : "unfold_more",
11593
+ size: "small",
11594
+ clickable: true,
11595
+ action: handleExpandToggle,
11596
+ tooltip: allExpanded ? "Collapse all" : "Expand all"
11597
+ }))), /*#__PURE__*/React.createElement("div", {
11505
11598
  className: "tree__content"
11506
- }, nodes, children));
11599
+ }, nodes, searchable ? filterNodes(children, searchTerm) : applyExpansionState(children))));
11507
11600
  };
11508
11601
 
11509
11602
  /**
@@ -11539,19 +11632,44 @@ var TreeNode = function TreeNode(props) {
11539
11632
  className = props.className,
11540
11633
  style = props.style,
11541
11634
  restProps = _objectWithoutPropertiesLoose(props, _excluded2$1);
11542
- var _useState4 = useState(open),
11543
- isOpen = _useState4[0],
11544
- setIsOpen = _useState4[1];
11545
- var _useState5 = useState(false),
11546
- isDragging = _useState5[0],
11547
- setIsDragging = _useState5[1];
11635
+ var _useState7 = useState(open),
11636
+ isOpen = _useState7[0],
11637
+ setIsOpen = _useState7[1];
11638
+ var _useState8 = useState(false),
11639
+ isDragging = _useState8[0],
11640
+ setIsDragging = _useState8[1];
11548
11641
  var nodeRef = useRef(null);
11549
11642
 
11643
+ // Get tree context for forced expand/collapse
11644
+ var treeContext = useContext(TreeContext);
11645
+ var forceExpandAll = treeContext.forceExpandAll,
11646
+ forceCollapseAll = treeContext.forceCollapseAll;
11647
+
11550
11648
  // Sync with open prop
11551
11649
  useEffect(function () {
11552
11650
  setIsOpen(open);
11553
11651
  }, [open]);
11554
11652
 
11653
+ // Handle forced expand/collapse from tree context
11654
+ useEffect(function () {
11655
+ if (forceExpandAll && expandable) {
11656
+ setIsOpen(true);
11657
+ // Also update the DOM element
11658
+ if (nodeRef.current) {
11659
+ nodeRef.current.open = true;
11660
+ }
11661
+ }
11662
+ }, [forceExpandAll, expandable]);
11663
+ useEffect(function () {
11664
+ if (forceCollapseAll && expandable) {
11665
+ setIsOpen(false);
11666
+ // Also update the DOM element
11667
+ if (nodeRef.current) {
11668
+ nodeRef.current.open = false;
11669
+ }
11670
+ }
11671
+ }, [forceCollapseAll, expandable]);
11672
+
11555
11673
  // Handle selection (maintaining original behavior)
11556
11674
  var handleSelect = useCallback(function (event) {
11557
11675
  if (disabled) return;
@@ -11559,14 +11677,13 @@ var TreeNode = function TreeNode(props) {
11559
11677
  if (onSelect) onSelect(id);
11560
11678
  }, [disabled, onSelect, id]);
11561
11679
 
11562
- // Handle toggle
11680
+ // Handle toggle - sync with details element
11563
11681
  var handleToggle = useCallback(function (event) {
11564
11682
  if (disabled || !expandable) return;
11565
- event.preventDefault();
11566
- event.stopPropagation();
11567
- setIsOpen(function (prev) {
11568
- return !prev;
11569
- });
11683
+
11684
+ // Sync our state with the details element
11685
+ var detailsElement = event.currentTarget;
11686
+ setIsOpen(detailsElement.open);
11570
11687
  }, [disabled, expandable]);
11571
11688
 
11572
11689
  // Handle keyboard interaction
@@ -11644,24 +11761,29 @@ var TreeNode = function TreeNode(props) {
11644
11761
  onDragStart: handleDragStart,
11645
11762
  onDragEnd: handleDragEnd,
11646
11763
  onDrop: handleDrop,
11647
- onDragOver: handleDragOver
11764
+ onDragOver: handleDragOver,
11765
+ onToggle: handleToggle
11648
11766
  }, restProps), /*#__PURE__*/React.createElement("summary", _extends({
11649
11767
  className: "tree-item",
11650
11768
  onClick: function onClick(event) {
11651
- // Si se hace click en el área general del nodo (no en el label), toggle
11652
- if (event.target === event.currentTarget || event.target.closest('.tree-node__toggle')) {
11653
- handleToggle(event);
11769
+ // Si se hace click en el toggle, permitir el comportamiento natural
11770
+ if (event.target.closest('.tree-node__toggle')) {
11771
+ // No hacer nada, dejar que el details maneje el toggle
11772
+ return;
11654
11773
  }
11774
+
11775
+ // Si hay onSelect y se hace click fuera del toggle, seleccionar
11776
+ if (onSelect) {
11777
+ event.preventDefault(); // Prevenir el toggle del details
11778
+ handleSelect(event);
11779
+ }
11780
+ // Si no hay onSelect, permitir el comportamiento natural del details
11655
11781
  },
11656
11782
  onKeyDown: handleKeyDown
11657
11783
  }, ariaAttributes, {
11658
11784
  title: tooltip
11659
11785
  }), hasChildren && expandable && /*#__PURE__*/React.createElement("div", {
11660
- className: "tree-node__toggle",
11661
- onClick: function onClick(event) {
11662
- event.stopPropagation();
11663
- handleToggle(event);
11664
- }
11786
+ className: "tree-node__toggle"
11665
11787
  }, /*#__PURE__*/React.createElement(Icon, {
11666
11788
  icon: isOpen ? 'expand_less' : 'expand_more',
11667
11789
  size: "small",
@@ -11678,11 +11800,7 @@ var TreeNode = function TreeNode(props) {
11678
11800
  icon: "hourglass_empty",
11679
11801
  size: "small"
11680
11802
  })), /*#__PURE__*/React.createElement("div", {
11681
- className: "label " + clickable,
11682
- onClick: function onClick(event) {
11683
- event.stopPropagation();
11684
- handleSelect(event);
11685
- }
11803
+ className: "label " + clickable
11686
11804
  }, /*#__PURE__*/React.createElement("span", {
11687
11805
  className: "tree-node__label-text"
11688
11806
  }, labelTxt), badge && /*#__PURE__*/React.createElement("span", {
@@ -11724,11 +11842,20 @@ var TreeItem = function TreeItem(props) {
11724
11842
  className = props.className,
11725
11843
  style = props.style,
11726
11844
  restProps = _objectWithoutPropertiesLoose(props, _excluded3);
11727
- var _useState6 = useState(false),
11728
- isDragging = _useState6[0],
11729
- setIsDragging = _useState6[1];
11845
+ var _useState9 = useState(false),
11846
+ isDragging = _useState9[0],
11847
+ setIsDragging = _useState9[1];
11730
11848
  var itemRef = useRef(null);
11731
11849
 
11850
+ // Get tree context
11851
+ var treeContext = useContext(TreeContext);
11852
+ var multiSelect = treeContext.multiSelect,
11853
+ selectedItems = treeContext.selectedItems,
11854
+ handleTreeMultiSelect = treeContext.onMultiSelect;
11855
+
11856
+ // Check if this item is selected in multi-select mode
11857
+ var isMultiSelected = multiSelect && selectedItems.includes(id);
11858
+
11732
11859
  // Handle selection (maintaining original behavior)
11733
11860
  var handleSelect = useCallback(function (event) {
11734
11861
  if (disabled) return;
@@ -11736,12 +11863,20 @@ var TreeItem = function TreeItem(props) {
11736
11863
  if (onSelect) onSelect(id);
11737
11864
  }, [disabled, onSelect, id]);
11738
11865
 
11739
- // Handle checkbox (maintaining original behavior)
11866
+ // Handle checkbox (maintaining original behavior + multi-select)
11740
11867
  var handleCheck = useCallback(function (event) {
11741
11868
  if (disabled) return;
11742
11869
  event.stopPropagation();
11743
- if (onCheck) onCheck(id, event.target.checked);
11744
- }, [disabled, onCheck, id]);
11870
+ var isChecked = event.target.checked;
11871
+
11872
+ // Handle original onCheck callback
11873
+ if (onCheck) onCheck(id, isChecked);
11874
+
11875
+ // Handle multi-select if enabled
11876
+ if (multiSelect && handleTreeMultiSelect) {
11877
+ handleTreeMultiSelect(id, isChecked);
11878
+ }
11879
+ }, [disabled, onCheck, id, multiSelect, handleTreeMultiSelect]);
11745
11880
 
11746
11881
  // Handle keyboard interaction
11747
11882
  var handleKeyDown = useCallback(function (event) {
@@ -11808,11 +11943,11 @@ var TreeItem = function TreeItem(props) {
11808
11943
  onDrop: handleDrop,
11809
11944
  onDragOver: handleDragOver,
11810
11945
  title: tooltip
11811
- }, ariaAttributes, restProps), onCheck && /*#__PURE__*/React.createElement("div", {
11946
+ }, ariaAttributes, restProps), (onCheck || multiSelect) && /*#__PURE__*/React.createElement("div", {
11812
11947
  className: "tree-item__checkbox"
11813
11948
  }, /*#__PURE__*/React.createElement("input", {
11814
11949
  type: "checkbox",
11815
- checked: checked,
11950
+ checked: multiSelect ? isMultiSelected : checked,
11816
11951
  onChange: handleCheck,
11817
11952
  disabled: disabled,
11818
11953
  "aria-label": "Select " + (typeof label === 'string' ? label : 'item')
@@ -11855,10 +11990,8 @@ Tree.propTypes = {
11855
11990
  multiSelect: PropTypes.bool,
11856
11991
  /** Multi-selection callback */
11857
11992
  onMultiSelect: PropTypes.func,
11858
- /** Show expand all button */
11859
- expandAll: PropTypes.bool,
11860
- /** Show collapse all button */
11861
- collapseAll: PropTypes.bool,
11993
+ /** Show expand/collapse icon */
11994
+ showExpandIcon: PropTypes.bool,
11862
11995
  /** Expand all callback */
11863
11996
  onExpandAll: PropTypes.func,
11864
11997
  /** Collapse all callback */