funda-ui 4.5.899 → 4.6.111
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/Chatbox/index.css +77 -77
- package/Chatbox/index.d.ts +1 -0
- package/Chatbox/index.js +215 -113
- package/Textarea/index.js +46 -46
- package/Utils/sanitize.d.ts +14 -0
- package/Utils/sanitize.js +87 -0
- package/Utils/useAutosizeTextArea.js +46 -46
- package/lib/cjs/Chatbox/index.d.ts +1 -0
- package/lib/cjs/Chatbox/index.js +215 -113
- package/lib/cjs/Textarea/index.js +46 -46
- package/lib/cjs/Utils/sanitize.d.ts +14 -0
- package/lib/cjs/Utils/sanitize.js +87 -0
- package/lib/cjs/Utils/useAutosizeTextArea.js +46 -46
- package/lib/css/Chatbox/index.css +77 -77
- package/lib/esm/Chatbox/index.scss +5 -5
- package/lib/esm/Chatbox/index.tsx +16 -7
- package/lib/esm/Chatbox/utils/func.ts +0 -54
- package/lib/esm/Textarea/index.tsx +1 -0
- package/lib/esm/Utils/hooks/useAutosizeTextArea.tsx +47 -49
- package/lib/esm/Utils/libs/sanitize.ts +55 -0
- package/package.json +1 -1
|
@@ -51,7 +51,6 @@ const App = () => {
|
|
|
51
51
|
|
|
52
52
|
*/
|
|
53
53
|
import { useEffect, useState, useCallback } from "react";
|
|
54
|
-
|
|
55
54
|
export interface AutosizeTextAreaProps {
|
|
56
55
|
el: any;
|
|
57
56
|
value: string;
|
|
@@ -66,68 +65,67 @@ const useAutosizeTextArea = ({
|
|
|
66
65
|
cb
|
|
67
66
|
}: AutosizeTextAreaProps): { reset: () => void } => {
|
|
68
67
|
|
|
69
|
-
const [defaultRowHeight, setDefaultRowHeight] = useState(0);
|
|
70
68
|
const [defaultRowHeightInit, setDefaultRowHeightInit] = useState(false);
|
|
71
69
|
|
|
72
70
|
// Reset function to restore default height
|
|
73
71
|
const reset = useCallback(() => {
|
|
74
|
-
if (el
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
if (!el) return;
|
|
73
|
+
|
|
74
|
+
const scrollHeight = el.scrollHeight;
|
|
75
|
+
el.style.height = scrollHeight + "px";
|
|
76
|
+
|
|
77
|
+
// Get current dimensions after reset
|
|
78
|
+
const style = window.getComputedStyle(el);
|
|
79
|
+
const _controlWidth = el.scrollWidth + parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth);
|
|
80
|
+
cb?.([_controlWidth, scrollHeight]);
|
|
81
|
+
}, [el, cb]);
|
|
83
82
|
|
|
84
83
|
useEffect(() => {
|
|
85
|
-
if (el)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
setDefaultRowHeightInit(true);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// restore default row height
|
|
102
|
-
if (defaultRowHeight > 0) {
|
|
103
|
-
el.style.height = defaultRowHeight + "px";
|
|
84
|
+
if (!el) return;
|
|
85
|
+
|
|
86
|
+
// Initialize default height
|
|
87
|
+
if (!defaultRowHeightInit) {
|
|
88
|
+
el.style.height = 'auto';
|
|
89
|
+
const initialHeight = el.scrollHeight;
|
|
90
|
+
setDefaultRowHeightInit(true);
|
|
91
|
+
|
|
92
|
+
// If the height is 0, set it to "auto"
|
|
93
|
+
if (initialHeight === 0) {
|
|
94
|
+
el.style.height = "auto";
|
|
95
|
+
} else {
|
|
96
|
+
el.style.height = initialHeight + "px";
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
|
|
107
|
-
const scrollHeight = el.scrollHeight;
|
|
99
|
+
}
|
|
108
100
|
|
|
101
|
+
// Get dimensions
|
|
102
|
+
const style = window.getComputedStyle(el);
|
|
103
|
+
const _controlWidth = el.scrollWidth + parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth);
|
|
104
|
+
|
|
105
|
+
// Calculate height
|
|
106
|
+
el.style.height = 'auto';
|
|
107
|
+
let finalHeight = el.scrollHeight;
|
|
108
|
+
|
|
109
|
+
// Apply max height limit if needed
|
|
110
|
+
if (maxHeight > 0 && finalHeight > maxHeight) {
|
|
111
|
+
finalHeight = maxHeight;
|
|
112
|
+
}
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
// Set final height
|
|
115
|
+
// If the height is 0, set it to "auto"
|
|
116
|
+
if (finalHeight === 0) {
|
|
117
|
+
el.style.height = "auto";
|
|
118
|
+
} else {
|
|
119
|
+
el.style.height = finalHeight + "px";
|
|
120
|
+
}
|
|
112
121
|
|
|
113
|
-
// !!! Compare initial height and changed height
|
|
114
|
-
if (scrollHeight > defaultRowHeight && defaultRowHeight > 0) {
|
|
115
122
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
_scrollHeight = maxHeight;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
el.style.height = _scrollHeight + "px";
|
|
122
|
-
|
|
123
|
-
}
|
|
123
|
+
// Callback
|
|
124
|
+
cb?.([_controlWidth, finalHeight]);
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}, [el, value]);
|
|
126
|
+
}, [el, value, maxHeight, defaultRowHeightInit]);
|
|
128
127
|
|
|
129
128
|
return { reset };
|
|
130
129
|
};
|
|
131
130
|
|
|
132
|
-
export default useAutosizeTextArea;
|
|
133
|
-
|
|
131
|
+
export default useAutosizeTextArea;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* HTML entities encode
|
|
4
|
+
*
|
|
5
|
+
* @param {String} str Input text
|
|
6
|
+
* @return {String} Filtered text
|
|
7
|
+
*/function htmlEncode(str: string): string {
|
|
8
|
+
|
|
9
|
+
return str.replace(/[&<>'"]/g, tag => ({
|
|
10
|
+
'&': '&',
|
|
11
|
+
'<': '<',
|
|
12
|
+
'>': '>',
|
|
13
|
+
"'": ''',
|
|
14
|
+
'"': '"'
|
|
15
|
+
}[tag]!));
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* HTML entities decode
|
|
22
|
+
*
|
|
23
|
+
* @param {String} str Input text
|
|
24
|
+
* @return {String} Filtered text
|
|
25
|
+
*/
|
|
26
|
+
function htmlDecode(str: string = ''): string {
|
|
27
|
+
const entities: [string, string][] = [
|
|
28
|
+
['amp', '&'],
|
|
29
|
+
['apos', '\''],
|
|
30
|
+
['#x27', '\''],
|
|
31
|
+
['#x2F', '/'],
|
|
32
|
+
['#39', '\''],
|
|
33
|
+
['#47', '/'],
|
|
34
|
+
['lt', '<'],
|
|
35
|
+
['gt', '>'],
|
|
36
|
+
['nbsp', ' '],
|
|
37
|
+
['quot', '"'],
|
|
38
|
+
['#60', '<'],
|
|
39
|
+
['#62', '>']
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
for (let i = 0, max = entities.length; i < max; i++) {
|
|
43
|
+
str = str.replace(new RegExp('&' + entities[i][0] + ';', 'g'), entities[i][1]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return str;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
htmlEncode,
|
|
54
|
+
htmlDecode
|
|
55
|
+
}
|
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.
|
|
5
|
+
"version": "4.6.111",
|
|
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",
|