funda-ui 3.8.821 → 3.9.14
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/Checkbox/index.js +1 -1
- package/Table/index.css +3 -1
- package/Table/index.js +100 -459
- package/Tree/index.css +4 -1
- package/Tree/index.d.ts +5 -0
- package/Tree/index.js +226 -544
- package/lib/cjs/Checkbox/index.js +1 -1
- package/lib/cjs/Table/index.js +100 -459
- package/lib/cjs/Tree/index.d.ts +5 -0
- package/lib/cjs/Tree/index.js +226 -544
- package/lib/css/Table/index.css +3 -1
- package/lib/css/Tree/index.css +4 -1
- package/lib/esm/Checkbox/index.tsx +1 -1
- package/lib/esm/Table/TableFieldRow.tsx +52 -19
- package/lib/esm/Table/TableHeaders.tsx +24 -14
- package/lib/esm/Table/TableRow.tsx +3 -0
- package/lib/esm/Table/index.scss +4 -1
- package/lib/esm/Table/index.tsx +30 -1
- package/lib/esm/Table/table-utils.ts +8 -0
- package/lib/esm/Tree/TreeList.tsx +122 -108
- package/lib/esm/Tree/index.scss +5 -1
- package/lib/esm/Tree/index.tsx +90 -9
- package/lib/esm/Tree/tree-utils.ts +56 -0
- package/package.json +1 -1
package/lib/esm/Tree/index.scss
CHANGED
|
@@ -104,14 +104,18 @@
|
|
|
104
104
|
|
|
105
105
|
> div {
|
|
106
106
|
display: inline-block;
|
|
107
|
+
position: relative;
|
|
107
108
|
|
|
108
109
|
.form-check {
|
|
109
110
|
min-height: auto;
|
|
110
111
|
margin-bottom: 0;
|
|
111
112
|
|
|
112
|
-
[type=checkbox]:indeterminate
|
|
113
|
+
[type=checkbox]:indeterminate,
|
|
114
|
+
[type=checkbox].indeterminate {
|
|
113
115
|
background-color: var(--tree-checkbox-indeterminate-color);
|
|
114
116
|
border-color: var(--tree-checkbox-indeterminate-color);
|
|
117
|
+
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10h8'/%3e%3c/svg%3e");
|
|
118
|
+
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
}
|
package/lib/esm/Tree/index.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import React, { useState, useEffect, useRef, useId } from 'react';
|
|
|
3
3
|
import TreeList from './TreeList';
|
|
4
4
|
import { initUlHeight, initAsyncItems } from './init-height';
|
|
5
5
|
|
|
6
|
+
import {deepClone, flatOriginalData} from './tree-utils';
|
|
6
7
|
|
|
7
8
|
declare module 'react' {
|
|
8
9
|
interface ReactI18NextChildren<T> {
|
|
@@ -10,6 +11,11 @@ declare module 'react' {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
interface ListSearchDataConfig {
|
|
15
|
+
title: string | number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
13
19
|
|
|
14
20
|
interface DataNode {
|
|
15
21
|
key: React.Key;
|
|
@@ -62,6 +68,8 @@ type TreeProps = {
|
|
|
62
68
|
childClassName?: string;
|
|
63
69
|
/** Specify data of Cascading DropDown List as a JSON string format. */
|
|
64
70
|
data?: any[any];
|
|
71
|
+
/** Retrieve data */
|
|
72
|
+
retrieveData?: ListSearchDataConfig[];
|
|
65
73
|
/** -- */
|
|
66
74
|
id?: string;
|
|
67
75
|
onSelect?: (e: any, val: any, func: Function) => void;
|
|
@@ -83,6 +91,7 @@ const Tree = (props: TreeProps) => {
|
|
|
83
91
|
treeClassName,
|
|
84
92
|
childClassName,
|
|
85
93
|
data,
|
|
94
|
+
retrieveData,
|
|
86
95
|
onSelect,
|
|
87
96
|
onCollapse,
|
|
88
97
|
onCheck
|
|
@@ -92,7 +101,8 @@ const Tree = (props: TreeProps) => {
|
|
|
92
101
|
const uniqueID = useId().replace(/\:/g, "-");
|
|
93
102
|
const idRes = id || uniqueID;
|
|
94
103
|
const rootRef = useRef<any>(null);
|
|
95
|
-
const [
|
|
104
|
+
const [list, setList] = useState<DataNode[] | null>(null);
|
|
105
|
+
const [flatList, setFlatList] = useState<DataNode[]>([]);
|
|
96
106
|
const [checkedPrint, setCheckedPrint] = useState<any[]>([]);
|
|
97
107
|
const [checkedData, setCheckedData] = useState<any[]>([]);
|
|
98
108
|
const expandClassName = `${showLine ? 'show-line' : ''} ${disableArrow ? 'hide-arrow' : ''} ${disableCollapse ? 'collapse-disabled' : ''} ${lineStyle ? `line--${lineStyle}` : ''} ${checkable ? 'has-checkbox' : ''}`;
|
|
@@ -153,6 +163,32 @@ const Tree = (props: TreeProps) => {
|
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
|
|
166
|
+
function updateShowProp(obj: DataNode[], retrieveData: ListSearchDataConfig[], val: boolean | undefined = undefined) {
|
|
167
|
+
obj.forEach((item: any, index: number) => {
|
|
168
|
+
|
|
169
|
+
if (retrieveData.length === 0) {
|
|
170
|
+
item.show = true;
|
|
171
|
+
} else {
|
|
172
|
+
if (typeof val !== 'undefined') {
|
|
173
|
+
item.show = val;
|
|
174
|
+
} else {
|
|
175
|
+
if (retrieveData.map((v: any) => v.title?.toLowerCase()).includes(item.title?.toLowerCase())) {
|
|
176
|
+
item.show = true;
|
|
177
|
+
} else {
|
|
178
|
+
item.show = false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
//
|
|
185
|
+
if (item.children) {
|
|
186
|
+
updateShowProp(item.children, retrieveData, val);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
156
192
|
|
|
157
193
|
function addKey(obj: DataNode[], depth: string, init: number) {
|
|
158
194
|
obj.forEach((item: any, index: number) => {
|
|
@@ -184,6 +220,7 @@ const Tree = (props: TreeProps) => {
|
|
|
184
220
|
setCheckedData((prevState) => [{
|
|
185
221
|
key: item.key,
|
|
186
222
|
checked: item.checked === true,
|
|
223
|
+
show: true,
|
|
187
224
|
indeterminate: false
|
|
188
225
|
}, ...prevState]);
|
|
189
226
|
|
|
@@ -194,11 +231,20 @@ const Tree = (props: TreeProps) => {
|
|
|
194
231
|
}
|
|
195
232
|
|
|
196
233
|
|
|
197
|
-
function initDefaultValue(key: React.Key | null, fetch: fetchConfig | null = null, firstRender: boolean = false) {
|
|
234
|
+
function initDefaultValue(key: React.Key | null, fetch: fetchConfig | null = null, firstRender: boolean = false, retrieveData: ListSearchDataConfig[] = []) {
|
|
198
235
|
|
|
199
236
|
if ( firstRender ) {
|
|
200
237
|
addKey(data, '', 0);
|
|
201
|
-
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
// filter showing items
|
|
241
|
+
if (Array.isArray(retrieveData)) {
|
|
242
|
+
updateShowProp(data, retrieveData);
|
|
243
|
+
} else {
|
|
244
|
+
updateShowProp(data, retrieveData, true);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
202
248
|
|
|
203
249
|
// Initialize default value of checkboxes
|
|
204
250
|
if ( checkable ) {
|
|
@@ -206,6 +252,14 @@ const Tree = (props: TreeProps) => {
|
|
|
206
252
|
initCheckboxesData(data);
|
|
207
253
|
}
|
|
208
254
|
|
|
255
|
+
|
|
256
|
+
// update list
|
|
257
|
+
setList(data);
|
|
258
|
+
|
|
259
|
+
// update retrive list
|
|
260
|
+
const _clone: any = deepClone(data);
|
|
261
|
+
setFlatList(flatOriginalData(_clone));
|
|
262
|
+
|
|
209
263
|
return;
|
|
210
264
|
}
|
|
211
265
|
|
|
@@ -218,11 +272,19 @@ const Tree = (props: TreeProps) => {
|
|
|
218
272
|
|
|
219
273
|
if ( _childrenData.length > 0 ) {
|
|
220
274
|
// add children to node
|
|
221
|
-
const _newData: DataNode[] = updateTreeData(
|
|
275
|
+
const _newData: DataNode[] = updateTreeData(list, key ? key : '', _childrenData);
|
|
222
276
|
|
|
223
277
|
// update data
|
|
224
278
|
addKey(_newData, '', 0);
|
|
225
|
-
|
|
279
|
+
|
|
280
|
+
// filter showing items
|
|
281
|
+
if (Array.isArray(retrieveData)) {
|
|
282
|
+
updateShowProp(_newData, retrieveData);
|
|
283
|
+
} else {
|
|
284
|
+
updateShowProp(_newData, retrieveData, true);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
226
288
|
|
|
227
289
|
// Initialize default value of checkboxes
|
|
228
290
|
if ( checkable ) {
|
|
@@ -230,10 +292,19 @@ const Tree = (props: TreeProps) => {
|
|
|
230
292
|
setCheckedData((prevState) => [{
|
|
231
293
|
key: newitem.key,
|
|
232
294
|
checked: newitem.checked === true,
|
|
295
|
+
show: true,
|
|
233
296
|
indeterminate: false
|
|
234
297
|
}, ...prevState]);
|
|
235
298
|
});
|
|
236
299
|
}
|
|
300
|
+
|
|
301
|
+
// update list
|
|
302
|
+
setList(_newData);
|
|
303
|
+
|
|
304
|
+
// update retrive list
|
|
305
|
+
const _clone: any = deepClone(_newData);
|
|
306
|
+
setFlatList(flatOriginalData(_clone));
|
|
307
|
+
|
|
237
308
|
|
|
238
309
|
}
|
|
239
310
|
|
|
@@ -247,7 +318,7 @@ const Tree = (props: TreeProps) => {
|
|
|
247
318
|
}
|
|
248
319
|
});
|
|
249
320
|
|
|
250
|
-
|
|
321
|
+
|
|
251
322
|
// init <ul> height
|
|
252
323
|
// Initialize async items
|
|
253
324
|
const ul: any = [].slice.call(rootRef.current.querySelectorAll('ul'));
|
|
@@ -265,9 +336,19 @@ const Tree = (props: TreeProps) => {
|
|
|
265
336
|
}
|
|
266
337
|
|
|
267
338
|
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
function filterRetriveData(flatData: DataNode[], retrieveData: ListSearchDataConfig[]) {
|
|
343
|
+
return flatData.filter((item: any) => {
|
|
344
|
+
return retrieveData.map((v: any) => v.title?.toLowerCase()).includes(item.title?.toLowerCase())
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
268
348
|
useEffect(() => {
|
|
269
|
-
initDefaultValue(null, null, true);
|
|
270
|
-
}, [data]);
|
|
349
|
+
initDefaultValue(null, null, true, retrieveData);
|
|
350
|
+
}, [data, retrieveData]);
|
|
351
|
+
|
|
271
352
|
|
|
272
353
|
|
|
273
354
|
return (
|
|
@@ -285,7 +366,7 @@ const Tree = (props: TreeProps) => {
|
|
|
285
366
|
disableCollapse={disableCollapse}
|
|
286
367
|
arrow={arrow}
|
|
287
368
|
arrowIcons={arrowIcons}
|
|
288
|
-
data={
|
|
369
|
+
data={Array.isArray(retrieveData) && retrieveData.length > 0 ? filterRetriveData(flatList, retrieveData) : list}
|
|
289
370
|
childClassName={childClassName || 'tree-diagram-default-nav'}
|
|
290
371
|
onSelect={onSelect}
|
|
291
372
|
onCollapse={onCollapse}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const removeItemOnce = (arr: any[], key: string) => {
|
|
2
|
+
return arr.filter((item: any) => {
|
|
3
|
+
return item.key !== key;
|
|
4
|
+
});
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const activeClass = (el: any, mode: string, classname: string = 'active') => {
|
|
10
|
+
if ( mode === 'add' ) {
|
|
11
|
+
el.classList.add(classname);
|
|
12
|
+
} else {
|
|
13
|
+
el.classList.remove(classname);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export const deepClone = (obj: any) => {
|
|
20
|
+
if (Array.isArray(obj)) {
|
|
21
|
+
return (obj as any).map((item: any) => deepClone(item));
|
|
22
|
+
} else if (typeof obj === 'object' && obj !== null) {
|
|
23
|
+
const clone: any = {};
|
|
24
|
+
for (let key in obj) {
|
|
25
|
+
if (obj.hasOwnProperty(key)) {
|
|
26
|
+
clone[key] = deepClone(obj[key]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return clone;
|
|
30
|
+
} else {
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export const flatOriginalData = (data: any[]) => {
|
|
37
|
+
const result: any[] = [];
|
|
38
|
+
const iterate = (obj: any) => {
|
|
39
|
+
if (!obj) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
obj.forEach((item: any) => {
|
|
43
|
+
result.push(item);
|
|
44
|
+
if (item.children) {
|
|
45
|
+
iterate(item.children);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// delete current item children
|
|
49
|
+
delete item.children;
|
|
50
|
+
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
iterate(data);
|
|
55
|
+
return result;
|
|
56
|
+
};
|
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": "3.
|
|
5
|
+
"version": "3.9.14",
|
|
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",
|