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.
@@ -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 && defaultRowHeight > 0) {
75
- el.style.height = defaultRowHeight + "px";
76
-
77
- // Get current dimensions after reset
78
- const style = (el as any).currentStyle || window.getComputedStyle(el);
79
- const _controlWidth = el.scrollWidth + parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth);
80
- cb?.([_controlWidth, defaultRowHeight]);
81
- }
82
- }, [el, defaultRowHeight, cb]);
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
- const style = (el as any).currentStyle || window.getComputedStyle(el);
87
- const _controlWidth = el.scrollWidth + parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth);
88
-
89
- // initialize default row height
90
- if (el.scrollHeight > 0 && !defaultRowHeightInit) {
91
-
92
- let _defaultRowHeight = el.scrollHeight + parseInt(style.borderTopWidth) + parseInt(style.borderBottomWidth);
93
- if (maxHeight != 0 && _defaultRowHeight >= maxHeight) {
94
- _defaultRowHeight = maxHeight;
95
- }
96
-
97
- setDefaultRowHeight(_defaultRowHeight);
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
- // reset the height momentarily to get the correct scrollHeight for the textarea
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
- // then set the height directly, outside of the render loop
111
- // Trying to set this with state or a ref will product an incorrect value.
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
- let _scrollHeight = scrollHeight;
117
- if (maxHeight != 0 && _scrollHeight >= maxHeight) {
118
- _scrollHeight = maxHeight;
119
- }
120
-
121
- el.style.height = _scrollHeight + "px";
122
-
123
- }
123
+ // Callback
124
+ cb?.([_controlWidth, finalHeight]);
124
125
 
125
- cb?.([_controlWidth, scrollHeight]);
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
+ '&': '&amp;',
11
+ '<': '&lt;',
12
+ '>': '&gt;',
13
+ "'": '&#39;',
14
+ '"': '&quot;'
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.899",
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",