funda-ui 4.5.666 → 4.5.671
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/ColorPicker/index.js +3 -1
- package/Date/index.js +14 -1
- package/DragDropList/index.css +188 -0
- package/DragDropList/index.d.ts +44 -0
- package/DragDropList/index.js +1587 -0
- package/Input/index.d.ts +2 -0
- package/Input/index.js +14 -1
- package/LICENSE +21 -0
- package/MultipleSelect/index.css +237 -144
- package/MultipleSelect/index.d.ts +24 -10
- package/MultipleSelect/index.js +2240 -1225
- package/README.md +3 -1
- package/RangeSlider/index.js +14 -1
- package/Textarea/index.d.ts +2 -0
- package/Textarea/index.js +14 -1
- package/Tree/index.d.ts +1 -0
- package/Tree/index.js +29 -0
- package/Utils/useBoundedDrag.d.ts +125 -0
- package/Utils/useBoundedDrag.js +380 -0
- package/Utils/useDragDropPosition.d.ts +169 -0
- package/Utils/useDragDropPosition.js +456 -0
- package/Utils/useIsMobile.d.ts +2 -0
- package/Utils/useIsMobile.js +168 -0
- package/all.d.ts +1 -0
- package/all.js +1 -1
- package/lib/cjs/ColorPicker/index.js +3 -1
- package/lib/cjs/Date/index.js +14 -1
- package/lib/cjs/DragDropList/index.d.ts +44 -0
- package/lib/cjs/DragDropList/index.js +1587 -0
- package/lib/cjs/Input/index.d.ts +2 -0
- package/lib/cjs/Input/index.js +14 -1
- package/lib/cjs/MultipleSelect/index.d.ts +24 -10
- package/lib/cjs/MultipleSelect/index.js +2240 -1225
- package/lib/cjs/RangeSlider/index.js +14 -1
- package/lib/cjs/Textarea/index.d.ts +2 -0
- package/lib/cjs/Textarea/index.js +14 -1
- package/lib/cjs/Tree/index.d.ts +1 -0
- package/lib/cjs/Tree/index.js +29 -0
- package/lib/cjs/Utils/useBoundedDrag.d.ts +125 -0
- package/lib/cjs/Utils/useBoundedDrag.js +380 -0
- package/lib/cjs/Utils/useDragDropPosition.d.ts +169 -0
- package/lib/cjs/Utils/useDragDropPosition.js +456 -0
- package/lib/cjs/Utils/useIsMobile.d.ts +2 -0
- package/lib/cjs/Utils/useIsMobile.js +168 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -1
- package/lib/css/DragDropList/index.css +188 -0
- package/lib/css/MultipleSelect/index.css +237 -144
- package/lib/esm/ColorPicker/index.tsx +53 -49
- package/lib/esm/DragDropList/index.scss +245 -0
- package/lib/esm/DragDropList/index.tsx +494 -0
- package/lib/esm/Input/index.tsx +17 -3
- package/lib/esm/MultipleSelect/index.scss +288 -183
- package/lib/esm/MultipleSelect/index.tsx +305 -166
- package/lib/esm/MultipleSelect/utils/func.ts +21 -1
- package/lib/esm/Tabs/Tabs.tsx +1 -1
- package/lib/esm/Textarea/index.tsx +18 -1
- package/lib/esm/Tree/TreeList.tsx +32 -0
- package/lib/esm/Tree/index.tsx +3 -0
- package/lib/esm/Utils/hooks/useBoundedDrag.tsx +301 -0
- package/lib/esm/Utils/hooks/useDragDropPosition.tsx +420 -0
- package/lib/esm/Utils/hooks/useIsMobile.tsx +56 -0
- package/lib/esm/index.js +1 -0
- package/package.json +1 -1
- package/lib/esm/MultipleSelect/ItemList.tsx +0 -323
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef, useEffect, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
getNextSiblings
|
|
6
|
-
} from 'funda-utils/dist/cjs/dom';
|
|
7
|
-
import { clsWrite, combinedCls } from 'funda-utils/dist/cjs/cls';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { formatIndentVal, multiSelControlOptionExist } from './utils/func';
|
|
12
|
-
|
|
13
|
-
/* Recursively nested components to traverse nodes
|
|
14
|
-
-------------------------------------------------*/
|
|
15
|
-
export type ItemListProps = {
|
|
16
|
-
appendControl?: React.ReactNode;
|
|
17
|
-
root: any;
|
|
18
|
-
listContainerClassName: string;
|
|
19
|
-
valSelected: any[];
|
|
20
|
-
indentStr: string;
|
|
21
|
-
iconAdd?: React.ReactNode | string;
|
|
22
|
-
iconRemove?: React.ReactNode | string;
|
|
23
|
-
selected?: boolean;
|
|
24
|
-
onSelect: (v: any, cb?: () => void) => void;
|
|
25
|
-
alternateCollapse?: boolean;
|
|
26
|
-
first?: boolean;
|
|
27
|
-
arrow?: React.ReactNode;
|
|
28
|
-
childClassName: string;
|
|
29
|
-
data: any[any];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const ItemList = forwardRef((props: ItemListProps, externalRef: any) => {
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
appendControl,
|
|
36
|
-
root,
|
|
37
|
-
listContainerClassName,
|
|
38
|
-
valSelected,
|
|
39
|
-
indentStr,
|
|
40
|
-
iconAdd,
|
|
41
|
-
iconRemove,
|
|
42
|
-
selected,
|
|
43
|
-
onSelect,
|
|
44
|
-
alternateCollapse,
|
|
45
|
-
first,
|
|
46
|
-
arrow,
|
|
47
|
-
childClassName,
|
|
48
|
-
data,
|
|
49
|
-
} = props;
|
|
50
|
-
|
|
51
|
-
const listContainerRef = useRef<any>(null);
|
|
52
|
-
|
|
53
|
-
const activeClass = (el: any, mode: string, classname: string = 'active') => {
|
|
54
|
-
if ( mode === 'add' ) {
|
|
55
|
-
el.classList.add(classname);
|
|
56
|
-
} else {
|
|
57
|
-
el.classList.remove(classname);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const closeChild = (hyperlink: HTMLElement, ul: HTMLAllCollection) => {
|
|
62
|
-
if ( ul.length === 0 ) return;
|
|
63
|
-
|
|
64
|
-
activeClass(hyperlink, 'remove');
|
|
65
|
-
hyperlink.setAttribute('aria-expanded', 'false');
|
|
66
|
-
activeClass(hyperlink.parentNode, 'remove');
|
|
67
|
-
|
|
68
|
-
//to close
|
|
69
|
-
[].slice.call(ul).forEach(function(element: any){
|
|
70
|
-
element.style.maxHeight = 0;
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const openChild = (hyperlink: HTMLElement, ul: HTMLAllCollection) => {
|
|
75
|
-
if ( ul.length === 0 ) return;
|
|
76
|
-
|
|
77
|
-
activeClass(hyperlink, 'add');
|
|
78
|
-
hyperlink.setAttribute('aria-expanded', 'true');
|
|
79
|
-
activeClass(hyperlink.parentNode, 'add');
|
|
80
|
-
|
|
81
|
-
// init <ul> height
|
|
82
|
-
[].slice.call(ul).forEach(function (_curUl: any) {
|
|
83
|
-
|
|
84
|
-
const allHeight = [].slice.call(_curUl.querySelectorAll('li')).map((_curLi: any) => _curLi.scrollHeight);
|
|
85
|
-
|
|
86
|
-
// Prevent missing height, causing the last element to be clipped
|
|
87
|
-
const maxHeight = Math.max(...allHeight);
|
|
88
|
-
allHeight.push(maxHeight*3);
|
|
89
|
-
|
|
90
|
-
//
|
|
91
|
-
const totalHeight = allHeight.reduce(
|
|
92
|
-
(accumulator: number, currentValue: number) => accumulator + currentValue,
|
|
93
|
-
0,
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
// Prevent the use of iframe or other situations where the height is 0
|
|
97
|
-
_curUl.style.maxHeight = `${totalHeight == 0 ? 999 : totalHeight}px`;
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
function handleClick(e: any) {
|
|
106
|
-
e.preventDefault();
|
|
107
|
-
e.stopPropagation();
|
|
108
|
-
const hyperlink = e.currentTarget.querySelector('div');
|
|
109
|
-
const subElement = getNextSiblings(hyperlink, 'ul');
|
|
110
|
-
|
|
111
|
-
// hide child if expandedLink doesn't exist, on the contrary
|
|
112
|
-
//=====================
|
|
113
|
-
if ( hyperlink.getAttribute('aria-expanded') === 'false' || hyperlink.getAttribute('aria-expanded') === null ) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
//Hide all other siblings of the selected <ul>
|
|
117
|
-
if ( alternateCollapse ) {
|
|
118
|
-
[].slice.call(listContainerRef.current.children).forEach(function(li: any){
|
|
119
|
-
|
|
120
|
-
activeClass(li, 'remove');
|
|
121
|
-
|
|
122
|
-
const _li = li.firstChild;
|
|
123
|
-
activeClass(_li, 'remove');
|
|
124
|
-
_li.setAttribute('aria-expanded', false);
|
|
125
|
-
|
|
126
|
-
[].slice.call(getNextSiblings(_li, 'ul')).forEach(function(element: any){
|
|
127
|
-
element.style.maxHeight = 0;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
//open current
|
|
134
|
-
openChild(hyperlink, subElement as never);
|
|
135
|
-
|
|
136
|
-
} else {
|
|
137
|
-
|
|
138
|
-
//close current
|
|
139
|
-
closeChild(hyperlink, subElement as never);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
function arrowGenerator() {
|
|
148
|
-
return arrow ? arrow : <svg viewBox="0 0 22 22" width="8px"><path d="m345.44 248.29l-194.29 194.28c-12.359 12.365-32.397 12.365-44.75 0-12.354-12.354-12.354-32.391 0-44.744l171.91-171.91-171.91-171.9c-12.354-12.359-12.354-32.394 0-44.748 12.354-12.359 32.391-12.359 44.75 0l194.29 194.28c6.177 6.18 9.262 14.271 9.262 22.366 0 8.099-3.091 16.196-9.267 22.373" transform="matrix(.03541-.00013.00013.03541 2.98 3.02)" fill="#a5a5a5" /></svg>;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
|
|
153
|
-
if (root !== null && data.length > 0) {
|
|
154
|
-
// Activate current item
|
|
155
|
-
//=====================
|
|
156
|
-
const allItems = listContainerRef.current ? [].slice.call(root.querySelectorAll(`.${childClassName} div`)).map( (item: any) => {
|
|
157
|
-
return {
|
|
158
|
-
el: item,
|
|
159
|
-
actived: item.parentNode.classList?.contains('active') ? true : false,
|
|
160
|
-
expandedLink: document.body.contains(item.parentNode.parentNode.previousSibling) ? item.parentNode.parentNode.previousSibling : false
|
|
161
|
-
}
|
|
162
|
-
} ) : [];
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
allItems.forEach( (hyperlink: any) => {
|
|
166
|
-
|
|
167
|
-
// Expand the currently active item by default
|
|
168
|
-
if ( hyperlink.actived ) {
|
|
169
|
-
|
|
170
|
-
hyperlink.el.setAttribute('aria-expanded', 'true');
|
|
171
|
-
|
|
172
|
-
if ( hyperlink.expandedLink ) {
|
|
173
|
-
const expandedLink: any = hyperlink.expandedLink; // <a>
|
|
174
|
-
activeClass(expandedLink.parentNode, 'add');
|
|
175
|
-
expandedLink.setAttribute('aria-expanded', true);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// init <ul> height
|
|
180
|
-
const ul = getNextSiblings(hyperlink.el, 'ul');
|
|
181
|
-
|
|
182
|
-
[].slice.call(ul).forEach(function (_curUl: any) {
|
|
183
|
-
|
|
184
|
-
const allHeight = [].slice.call(_curUl.querySelectorAll('li')).map((_curLi: any) => _curLi.scrollHeight);
|
|
185
|
-
|
|
186
|
-
// Prevent missing height, causing the last element to be clipped
|
|
187
|
-
const maxHeight = Math.max(...allHeight);
|
|
188
|
-
allHeight.push(maxHeight * 3);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
const totalHeight = allHeight.reduce(
|
|
193
|
-
(accumulator: number, currentValue: number) => accumulator + currentValue,
|
|
194
|
-
0,
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
// Prevent the use of iframe or other situations where the height is 0
|
|
198
|
-
_curUl.style.maxHeight = `${totalHeight == 0 ? 999 : totalHeight}px`;
|
|
199
|
-
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}, [data]);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (data) {
|
|
214
|
-
|
|
215
|
-
return (
|
|
216
|
-
<>
|
|
217
|
-
<ul
|
|
218
|
-
className={`${listContainerClassName || ''} ${childClassName}`}
|
|
219
|
-
style={!first ? { maxHeight: '0px' } : {}}
|
|
220
|
-
ref={(node) => {
|
|
221
|
-
listContainerRef.current = node;
|
|
222
|
-
if (typeof externalRef === 'function') {
|
|
223
|
-
externalRef(node);
|
|
224
|
-
} else if (externalRef) {
|
|
225
|
-
externalRef.current = node;
|
|
226
|
-
}
|
|
227
|
-
}}
|
|
228
|
-
>
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
{data ? data.map((item: any, i: number) => {
|
|
232
|
-
|
|
233
|
-
// callback from each option
|
|
234
|
-
if (typeof item.appendControlCallback === 'function') {
|
|
235
|
-
setTimeout(() => {
|
|
236
|
-
item.appendControlCallback?.();
|
|
237
|
-
}, 0);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return <li
|
|
242
|
-
key={selected ? 'item-selected' + i : 'item' + i}
|
|
243
|
-
className={selected ? 'selected' : combinedCls(
|
|
244
|
-
{
|
|
245
|
-
'disabled': item.disabled,
|
|
246
|
-
'hide': multiSelControlOptionExist(valSelected, item.value)
|
|
247
|
-
}
|
|
248
|
-
)}
|
|
249
|
-
data-index={i}
|
|
250
|
-
data-value={`${item.value}`}
|
|
251
|
-
data-label={`${item.label}`}
|
|
252
|
-
data-list-item-label={`${typeof item.listItemLabel === 'undefined' ? '' : item.listItemLabel}`}
|
|
253
|
-
data-disabled={item.disabled || 'false'}
|
|
254
|
-
data-querystring={`${typeof item.queryString === 'undefined' ? '' : item.queryString}`}
|
|
255
|
-
data-itemdata={JSON.stringify(item)}
|
|
256
|
-
onClick={selected ? () => void(0) : handleClick}
|
|
257
|
-
>
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<div>
|
|
261
|
-
<strong>
|
|
262
|
-
<span dangerouslySetInnerHTML={{
|
|
263
|
-
__html: selected ? (typeof item.listItemLabel === 'undefined' ? formatIndentVal(item.label, indentStr) : formatIndentVal(item.listItemLabel, indentStr)) : (typeof item.listItemLabel === 'undefined' ? item.label : item.listItemLabel)
|
|
264
|
-
}}></span>
|
|
265
|
-
{item.children && item.children.length > 0 && !selected ? <span className="arrow">{arrowGenerator()}</span> : ''}
|
|
266
|
-
</strong>
|
|
267
|
-
|
|
268
|
-
{selected && appendControl ? <>
|
|
269
|
-
<span className="m-select__ext" id={`m-select__ext-${item.value}${selected ? '-selected' : ''}`}>
|
|
270
|
-
{appendControl}
|
|
271
|
-
</span>
|
|
272
|
-
</> : null}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
<i
|
|
276
|
-
onClick={(e: React.MouseEvent) => {
|
|
277
|
-
e.stopPropagation();
|
|
278
|
-
onSelect((e.target as any).closest('li'), undefined);
|
|
279
|
-
}}>
|
|
280
|
-
|
|
281
|
-
{selected ? <>
|
|
282
|
-
{iconRemove ? <>{iconRemove}</> : <><svg width="15px" height="15px" viewBox="0 0 24 24" fill="none"><path fillRule="evenodd" clipRule="evenodd" d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10ZM8 11a1 1 0 1 0 0 2h8a1 1 0 1 0 0-2H8Z" fill="#000" /></svg></>}
|
|
283
|
-
</> : <>
|
|
284
|
-
{iconAdd ? <>{iconAdd}</> : <><svg width="15px" height="15px" viewBox="0 0 24 24" fill="none"><path d="M12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2ZM16 12.75H12.75V16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16V12.75H8C7.59 12.75 7.25 12.41 7.25 12C7.25 11.59 7.59 11.25 8 11.25H11.25V8C11.25 7.59 11.59 7.25 12 7.25C12.41 7.25 12.75 7.59 12.75 8V11.25H16C16.41 11.25 16.75 11.59 16.75 12C16.75 12.41 16.41 12.75 16 12.75Z" fill="#000" /></svg></>}
|
|
285
|
-
</>}
|
|
286
|
-
</i>
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
</div>
|
|
290
|
-
|
|
291
|
-
{item.children && <ItemList
|
|
292
|
-
root={root}
|
|
293
|
-
listContainerClassName={listContainerClassName}
|
|
294
|
-
ref={externalRef}
|
|
295
|
-
indentStr={indentStr}
|
|
296
|
-
valSelected={valSelected}
|
|
297
|
-
iconAdd={iconAdd}
|
|
298
|
-
iconRemove={iconRemove}
|
|
299
|
-
onSelect={onSelect}
|
|
300
|
-
first={false}
|
|
301
|
-
arrow={arrow}
|
|
302
|
-
data={item.children}
|
|
303
|
-
childClassName={childClassName}
|
|
304
|
-
/>}
|
|
305
|
-
|
|
306
|
-
</li>;
|
|
307
|
-
}) : null}
|
|
308
|
-
|
|
309
|
-
</ul>
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
</>
|
|
313
|
-
)
|
|
314
|
-
} else {
|
|
315
|
-
return (
|
|
316
|
-
<></>
|
|
317
|
-
)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
export default ItemList;
|