funda-ui 4.2.255 → 4.2.375

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 (60) hide show
  1. package/CascadingSelect/index.js +1 -1
  2. package/EventCalendar/index.css +3 -0
  3. package/EventCalendar/index.d.ts +4 -1
  4. package/EventCalendar/index.js +16 -4
  5. package/EventCalendarTimeline/index.css +17 -0
  6. package/EventCalendarTimeline/index.d.ts +9 -2
  7. package/EventCalendarTimeline/index.js +77 -22
  8. package/LiveSearch/index.css +12 -0
  9. package/LiveSearch/index.js +1 -1
  10. package/ModalDialog/index.js +1 -1
  11. package/NativeSelect/index.js +75 -47
  12. package/Pagination/index.d.ts +2 -0
  13. package/Pagination/index.js +25 -21
  14. package/Radio/index.js +14 -6
  15. package/RangeSlider/index.css +1 -0
  16. package/Select/index.css +5 -0
  17. package/Select/index.d.ts +1 -0
  18. package/Select/index.js +31 -11
  19. package/Tabs/index.js +13 -2
  20. package/Tree/index.js +90 -56
  21. package/lib/cjs/CascadingSelect/index.js +1 -1
  22. package/lib/cjs/EventCalendar/index.d.ts +4 -1
  23. package/lib/cjs/EventCalendar/index.js +16 -4
  24. package/lib/cjs/EventCalendarTimeline/index.d.ts +9 -2
  25. package/lib/cjs/EventCalendarTimeline/index.js +77 -22
  26. package/lib/cjs/LiveSearch/index.js +1 -1
  27. package/lib/cjs/ModalDialog/index.js +1 -1
  28. package/lib/cjs/NativeSelect/index.js +75 -47
  29. package/lib/cjs/Pagination/index.d.ts +2 -0
  30. package/lib/cjs/Pagination/index.js +25 -21
  31. package/lib/cjs/Radio/index.js +14 -6
  32. package/lib/cjs/Select/index.d.ts +1 -0
  33. package/lib/cjs/Select/index.js +31 -11
  34. package/lib/cjs/Tabs/index.js +13 -2
  35. package/lib/cjs/Tree/index.js +90 -56
  36. package/lib/css/EventCalendar/index.css +3 -0
  37. package/lib/css/EventCalendarTimeline/index.css +17 -0
  38. package/lib/css/LiveSearch/index.css +12 -0
  39. package/lib/css/RangeSlider/index.css +1 -0
  40. package/lib/css/Select/index.css +5 -0
  41. package/lib/esm/CascadingSelect/index.tsx +1 -1
  42. package/lib/esm/EventCalendar/index.scss +2 -0
  43. package/lib/esm/EventCalendar/index.tsx +23 -6
  44. package/lib/esm/EventCalendarTimeline/index.scss +24 -1
  45. package/lib/esm/EventCalendarTimeline/index.tsx +195 -118
  46. package/lib/esm/LiveSearch/index.scss +14 -1
  47. package/lib/esm/LiveSearch/index.tsx +1 -1
  48. package/lib/esm/ModalDialog/index.tsx +1 -1
  49. package/lib/esm/NativeSelect/index.tsx +4 -18
  50. package/lib/esm/NativeSelect/native-select-utils/func.ts +40 -0
  51. package/lib/esm/Pagination/index.tsx +31 -22
  52. package/lib/esm/Radio/index.tsx +19 -6
  53. package/lib/esm/RangeSlider/index.scss +2 -0
  54. package/lib/esm/Select/index.scss +6 -1
  55. package/lib/esm/Select/index.tsx +70 -54
  56. package/lib/esm/Table/Table.tsx +2 -0
  57. package/lib/esm/Tabs/Tabs.tsx +19 -4
  58. package/lib/esm/Tree/TreeList.tsx +61 -54
  59. package/lib/esm/Tree/index.tsx +4 -0
  60. package/package.json +1 -1
@@ -1,11 +1,9 @@
1
- import React, { useEffect, useRef, useCallback } from 'react';
1
+ import React, { useEffect, useRef } from 'react';
2
2
 
3
3
  // HAS CHECKBOX
4
4
 
5
5
  import {
6
6
  getNextSiblings,
7
- getPreviousSiblings,
8
- getParents,
9
7
  getChildren
10
8
  } from 'funda-utils';
11
9
 
@@ -33,6 +31,7 @@ type TreeListProps = {
33
31
  arrow?: React.ReactNode;
34
32
  arrowIcons?: React.ReactNode[];
35
33
  childClassName?: string;
34
+ orginalData: any[any];
36
35
  data: any[any];
37
36
  getCheckedPrint?: any[];
38
37
  updateCheckedPrint?: any;
@@ -56,6 +55,7 @@ export default function TreeList(props: TreeListProps) {
56
55
  arrow,
57
56
  arrowIcons,
58
57
  childClassName,
58
+ orginalData,
59
59
  data,
60
60
  getCheckedPrint,
61
61
  updateCheckedPrint,
@@ -90,66 +90,74 @@ export default function TreeList(props: TreeListProps) {
90
90
  });
91
91
  };
92
92
 
93
- const setCheckboxIndeterminateData = (arr: any[], key: string, val: boolean) => {
94
- arr.forEach((item: any, index: number) => {
95
- if (item.key === key) arr[index].indeterminate = val;
96
- });
97
- };
98
-
99
-
100
-
101
- const setCheckboxIndeterminateStatus = (checkedData: any[], printData: any[], el: HTMLFormElement | null) => {
102
- let _parentsLi: any = [];
103
-
104
- if ( el !== null ) {
105
- _parentsLi = [].slice.call(getParents(el,'li'));
106
- _parentsLi.splice(0, 1);
107
- } else {
108
- _parentsLi = [].slice.call(document.querySelectorAll(`#${checkboxNamePrefix} li`));
93
+ // check whether the node is in the Indeterminate state
94
+ const isIndeterminate = (node: any) => {
95
+ if (!node.children || node.children.length === 0) {
96
+ return false;
109
97
  }
110
98
 
99
+ let hasChecked = false;
100
+ let hasUnchecked = false;
111
101
 
112
- //---
113
- _parentsLi.forEach((node: any) => {
114
- const _checkboxes = getChildren(node, '[type="checkbox"]');
115
- const parentKey = typeof _checkboxes[0] === 'undefined' ? '' : _checkboxes[0].dataset.key;
102
+ for (let child of node.children) {
103
+ if (isIndeterminate(child)) {
104
+ return true;
105
+ }
116
106
 
107
+ if (child.checked) {
108
+ hasChecked = true;
109
+ } else {
110
+ hasUnchecked = true;
111
+ }
117
112
 
118
- //
119
- let _checkedLengthCalcArr: any[] = [];
120
- checkedData.forEach((oitem: any, oindex: number) => {
121
- _checkboxes.forEach((el: any) => {
122
- if (el.dataset.key === oitem.key) _checkedLengthCalcArr.push(oitem);
123
- });
124
- });
125
- _checkedLengthCalcArr = _checkedLengthCalcArr.filter((el: any) => {
126
- return el.key !== parentKey;
127
- })
113
+ // If there are some selected and some unchecked, the node is Indeterminate
114
+ if (hasChecked && hasUnchecked) {
115
+ return true;
116
+ }
117
+ }
128
118
 
129
- //
130
- const _checkedLength = _checkedLengthCalcArr.filter((el: any) => {
131
- return el.checked === true;
132
- }).length;
119
+ // If all child nodes are the same, it is not Indeterminate
120
+ return false;
121
+ };
133
122
 
134
- if ( _checkedLength === 0 ) {
135
- setCheckboxIndeterminateData(checkedData, parentKey, false);
136
- } else {
137
123
 
138
- if ( _checkedLength === _checkboxes.length-1 ) {
139
- setCheckboxIndeterminateData(checkedData, parentKey, false);
140
- setCheckboxCheckedData(checkedData, parentKey, true);
141
- printData.push(formatCheckboxControlVal(_checkboxes[0]));
142
- }
143
-
144
- if ( _checkedLength < _checkboxes.length-1 ) {
145
- setCheckboxIndeterminateData(checkedData, parentKey, true);
146
- setCheckboxCheckedData(checkedData, parentKey, false);
147
- printData = removeItemOnce(printData, parentKey);
148
- }
124
+ const updateTreeCheckedItems = (arr: any[], flatArr: any[]) => {
125
+ if (!Array.isArray(arr)) return;
149
126
 
127
+ for (let i = 0; i < arr.length; i++) {
128
+ const orginalDataKey: React.Key = arr[i].key;
129
+ const targetItem = flatArr.find((v: any) => v.key === orginalDataKey);
130
+ if (typeof targetItem !== 'undefined') {
131
+ // update value of checked
132
+ arr[i].checked = targetItem.checked;
133
+ }
134
+
135
+ if (arr[i].children) updateTreeCheckedItems(arr[i].children, flatArr);
136
+ }
137
+ }
138
+
139
+ const updateIndeterminateData = (arr: any[], flatArr: any[]) => {
140
+ if (!Array.isArray(arr)) return;
141
+
142
+ for (let i = 0; i < arr.length; i++) {
143
+ const orginalDataKey: React.Key = arr[i].key;
144
+ const targetItem = flatArr.find((v: any) => v.key === orginalDataKey);
145
+ if (typeof targetItem !== 'undefined') {
146
+ // update indeterminate of item
147
+ targetItem.indeterminate = isIndeterminate(arr[i]);
150
148
  }
149
+
150
+ if (arr[i].children) updateIndeterminateData(arr[i].children, flatArr);
151
+ }
152
+ }
153
+
154
+ const setCheckboxIndeterminateStatus = (checkedData: any[], printData: any[], el: HTMLFormElement | null) => {
151
155
 
152
- });
156
+ // update checked items from orginal data
157
+ updateTreeCheckedItems(orginalData, checkedData);
158
+
159
+ // check whether the node is in the Indeterminate state
160
+ updateIndeterminateData(orginalData, checkedData);
153
161
 
154
162
  return [checkedData, printData];
155
163
 
@@ -301,7 +309,6 @@ export default function TreeList(props: TreeListProps) {
301
309
  //-----------
302
310
  if ( val === true ) {
303
311
  _res.push(formatCheckboxControlVal(el));
304
- setCheckboxIndeterminateData(_checkedData, _curKey, false);
305
312
  setCheckboxCheckedData(_checkedData, _curKey, true);
306
313
 
307
314
  } else {
@@ -317,7 +324,6 @@ export default function TreeList(props: TreeListProps) {
317
324
  [].slice.call(getChildren(el.closest('li'), '[type="checkbox"]')).forEach((node: any) => {
318
325
  if ( val === true ) {
319
326
  if ( node.dataset.key !== _curKey ) {
320
- setCheckboxIndeterminateData(_checkedData, node.dataset.key, false);
321
327
  setCheckboxCheckedData(_checkedData, node.dataset.key, true);
322
328
  _res.push(formatCheckboxControlVal(node));
323
329
  }
@@ -509,6 +515,7 @@ export default function TreeList(props: TreeListProps) {
509
515
  {item.children && item.children.length > 0 && <TreeList
510
516
  rootNode={rootNode}
511
517
  checkboxNamePrefix={checkboxNamePrefix}
518
+ orginalData={orginalData}
512
519
  data={item.children}
513
520
  first={false}
514
521
  arrow={arrow}
@@ -7,6 +7,7 @@ import {
7
7
  } from 'funda-utils';
8
8
 
9
9
 
10
+
10
11
  import TreeList from './TreeList';
11
12
  import { initUlHeight, initAsyncItems } from './init-height';
12
13
 
@@ -102,6 +103,7 @@ const Tree = (props: TreeProps) => {
102
103
  const uniqueID = useComId();
103
104
  const idRes = id || uniqueID;
104
105
  const rootRef = useRef<any>(null);
106
+ const [orginalData, setOrginalData] = useState<DataNode[] | null>(null);
105
107
  const [list, setList] = useState<DataNode[] | null>(null);
106
108
  const [flatList, setFlatList] = useState<DataNode[]>([]);
107
109
  const [checkedPrint, setCheckedPrint] = useState<any[]>([]);
@@ -348,6 +350,7 @@ const Tree = (props: TreeProps) => {
348
350
 
349
351
  useEffect(() => {
350
352
  initDefaultValue(null, null, true, retrieveData);
353
+ setOrginalData(data);
351
354
  }, [data, retrieveData]);
352
355
 
353
356
 
@@ -367,6 +370,7 @@ const Tree = (props: TreeProps) => {
367
370
  disableCollapse={disableCollapse}
368
371
  arrow={arrow}
369
372
  arrowIcons={arrowIcons}
373
+ orginalData={orginalData}
370
374
  data={Array.isArray(retrieveData) && retrieveData.length > 0 ? filterRetriveData(flatList, retrieveData) : list}
371
375
  childClassName={childClassName || 'tree-diagram-default-nav'}
372
376
  onSelect={onSelect}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "UIUX Lab",
3
3
  "email": "uiuxlab@gmail.com",
4
4
  "name": "funda-ui",
5
- "version": "4.2.255",
5
+ "version": "4.2.375",
6
6
  "description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
7
7
  "repository": {
8
8
  "type": "git",