@etsoo/react 1.7.12 → 1.7.13
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/lib/app/ReactUtils.d.ts +0 -14
- package/lib/app/ReactUtils.js +4 -64
- package/package.json +2 -2
- package/src/app/ReactUtils.ts +6 -64
package/lib/app/ReactUtils.d.ts
CHANGED
|
@@ -10,26 +10,12 @@ export declare namespace ReactUtils {
|
|
|
10
10
|
* @returns Formatted value
|
|
11
11
|
*/
|
|
12
12
|
function formatInputValue(value: unknown): string | number | any[] | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* Get nested value
|
|
15
|
-
* @param data Data
|
|
16
|
-
* @param name Field name, support property chain like 'jsonData.logSize'
|
|
17
|
-
* @returns Result
|
|
18
|
-
*/
|
|
19
|
-
function getNestedValue(data: object, name: string): any;
|
|
20
13
|
/**
|
|
21
14
|
* Is safe click
|
|
22
15
|
* @param event Mouse event
|
|
23
16
|
* @returns Result
|
|
24
17
|
*/
|
|
25
18
|
function isSafeClick(event: React.MouseEvent<HTMLElement>): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Set nested value
|
|
28
|
-
* @param data Data
|
|
29
|
-
* @param name Field name, support property chain like 'jsonData.logSize'
|
|
30
|
-
* @param value Value
|
|
31
|
-
*/
|
|
32
|
-
function setNestedValue(data: object, name: string, value: unknown): void;
|
|
33
19
|
/**
|
|
34
20
|
* Trigger input change event
|
|
35
21
|
* @param input Form input
|
package/lib/app/ReactUtils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DomUtils } from '@etsoo/shared';
|
|
1
|
+
import { DomUtils, Utils } from '@etsoo/shared';
|
|
2
2
|
/**
|
|
3
3
|
* React utils
|
|
4
4
|
*/
|
|
@@ -21,36 +21,6 @@ export var ReactUtils;
|
|
|
21
21
|
return String(value);
|
|
22
22
|
}
|
|
23
23
|
ReactUtils.formatInputValue = formatInputValue;
|
|
24
|
-
/**
|
|
25
|
-
* Get nested value
|
|
26
|
-
* @param data Data
|
|
27
|
-
* @param name Field name, support property chain like 'jsonData.logSize'
|
|
28
|
-
* @returns Result
|
|
29
|
-
*/
|
|
30
|
-
function getNestedValue(data, name) {
|
|
31
|
-
const properties = name.split('.');
|
|
32
|
-
const len = properties.length;
|
|
33
|
-
if (len === 1) {
|
|
34
|
-
return Reflect.get(data, name);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
let curr = data;
|
|
38
|
-
for (let i = 0; i < len; i++) {
|
|
39
|
-
const property = properties[i];
|
|
40
|
-
if (i + 1 === len) {
|
|
41
|
-
return Reflect.get(curr, property);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
let p = Reflect.get(curr, property);
|
|
45
|
-
if (p == null) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
curr = p;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
ReactUtils.getNestedValue = getNestedValue;
|
|
54
24
|
/**
|
|
55
25
|
* Is safe click
|
|
56
26
|
* @param event Mouse event
|
|
@@ -77,36 +47,6 @@ export var ReactUtils;
|
|
|
77
47
|
return true;
|
|
78
48
|
}
|
|
79
49
|
ReactUtils.isSafeClick = isSafeClick;
|
|
80
|
-
/**
|
|
81
|
-
* Set nested value
|
|
82
|
-
* @param data Data
|
|
83
|
-
* @param name Field name, support property chain like 'jsonData.logSize'
|
|
84
|
-
* @param value Value
|
|
85
|
-
*/
|
|
86
|
-
function setNestedValue(data, name, value) {
|
|
87
|
-
const properties = name.split('.');
|
|
88
|
-
const len = properties.length;
|
|
89
|
-
if (len === 1)
|
|
90
|
-
Reflect.set(data, name, value);
|
|
91
|
-
else {
|
|
92
|
-
let curr = data;
|
|
93
|
-
for (let i = 0; i < len; i++) {
|
|
94
|
-
const property = properties[i];
|
|
95
|
-
if (i + 1 === len) {
|
|
96
|
-
Reflect.set(curr, property, value);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
let p = Reflect.get(curr, property);
|
|
100
|
-
if (p == null) {
|
|
101
|
-
p = {};
|
|
102
|
-
Reflect.set(curr, property, p);
|
|
103
|
-
}
|
|
104
|
-
curr = p;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
ReactUtils.setNestedValue = setNestedValue;
|
|
110
50
|
/**
|
|
111
51
|
* Trigger input change event
|
|
112
52
|
* @param input Form input
|
|
@@ -172,7 +112,7 @@ export var ReactUtils;
|
|
|
172
112
|
else if (item instanceof HTMLInputElement ||
|
|
173
113
|
item instanceof HTMLTextAreaElement ||
|
|
174
114
|
item instanceof HTMLSelectElement) {
|
|
175
|
-
item.value = `${(_a = getNestedValue(data, item.name || k)) !== null && _a !== void 0 ? _a : ''}`;
|
|
115
|
+
item.value = `${(_a = Utils.getNestedValue(data, item.name || k)) !== null && _a !== void 0 ? _a : ''}`;
|
|
176
116
|
}
|
|
177
117
|
else {
|
|
178
118
|
item.value = data[k];
|
|
@@ -202,11 +142,11 @@ export var ReactUtils;
|
|
|
202
142
|
data[k] = local(item);
|
|
203
143
|
}
|
|
204
144
|
else if (item instanceof HTMLInputElement) {
|
|
205
|
-
setNestedValue(data, item.name || k, DomUtils.getInputValue(item));
|
|
145
|
+
Utils.setNestedValue(data, item.name || k, DomUtils.getInputValue(item));
|
|
206
146
|
}
|
|
207
147
|
else if (item instanceof HTMLTextAreaElement ||
|
|
208
148
|
item instanceof HTMLSelectElement) {
|
|
209
|
-
setNestedValue(data, item.name || k, item.value);
|
|
149
|
+
Utils.setNestedValue(data, item.name || k, item.value);
|
|
210
150
|
}
|
|
211
151
|
else {
|
|
212
152
|
data[k] = item.value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.13",
|
|
4
4
|
"description": "TypeScript ReactJs UI Independent Framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@emotion/styled": "^11.11.0",
|
|
53
53
|
"@etsoo/appscript": "^1.4.55",
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.28",
|
|
55
|
-
"@etsoo/shared": "^1.2.
|
|
55
|
+
"@etsoo/shared": "^1.2.14",
|
|
56
56
|
"@types/react": "^18.2.22",
|
|
57
57
|
"@types/react-dom": "^18.2.7",
|
|
58
58
|
"@types/react-window": "^1.8.5",
|
package/src/app/ReactUtils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, DomUtils, Utils } from '@etsoo/shared';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -22,36 +22,6 @@ export namespace ReactUtils {
|
|
|
22
22
|
return String(value);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Get nested value
|
|
27
|
-
* @param data Data
|
|
28
|
-
* @param name Field name, support property chain like 'jsonData.logSize'
|
|
29
|
-
* @returns Result
|
|
30
|
-
*/
|
|
31
|
-
export function getNestedValue(data: object, name: string) {
|
|
32
|
-
const properties = name.split('.');
|
|
33
|
-
const len = properties.length;
|
|
34
|
-
if (len === 1) {
|
|
35
|
-
return Reflect.get(data, name);
|
|
36
|
-
} else {
|
|
37
|
-
let curr = data;
|
|
38
|
-
for (let i = 0; i < len; i++) {
|
|
39
|
-
const property = properties[i];
|
|
40
|
-
|
|
41
|
-
if (i + 1 === len) {
|
|
42
|
-
return Reflect.get(curr, property);
|
|
43
|
-
} else {
|
|
44
|
-
let p = Reflect.get(curr, property);
|
|
45
|
-
if (p == null) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
curr = p;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
25
|
/**
|
|
56
26
|
* Is safe click
|
|
57
27
|
* @param event Mouse event
|
|
@@ -82,36 +52,6 @@ export namespace ReactUtils {
|
|
|
82
52
|
return true;
|
|
83
53
|
}
|
|
84
54
|
|
|
85
|
-
/**
|
|
86
|
-
* Set nested value
|
|
87
|
-
* @param data Data
|
|
88
|
-
* @param name Field name, support property chain like 'jsonData.logSize'
|
|
89
|
-
* @param value Value
|
|
90
|
-
*/
|
|
91
|
-
export function setNestedValue(data: object, name: string, value: unknown) {
|
|
92
|
-
const properties = name.split('.');
|
|
93
|
-
const len = properties.length;
|
|
94
|
-
if (len === 1) Reflect.set(data, name, value);
|
|
95
|
-
else {
|
|
96
|
-
let curr = data;
|
|
97
|
-
for (let i = 0; i < len; i++) {
|
|
98
|
-
const property = properties[i];
|
|
99
|
-
|
|
100
|
-
if (i + 1 === len) {
|
|
101
|
-
Reflect.set(curr, property, value);
|
|
102
|
-
} else {
|
|
103
|
-
let p = Reflect.get(curr, property);
|
|
104
|
-
if (p == null) {
|
|
105
|
-
p = {};
|
|
106
|
-
Reflect.set(curr, property, p);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
curr = p;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
55
|
/**
|
|
116
56
|
* Trigger input change event
|
|
117
57
|
* @param input Form input
|
|
@@ -200,7 +140,9 @@ export namespace ReactUtils {
|
|
|
200
140
|
item instanceof HTMLTextAreaElement ||
|
|
201
141
|
item instanceof HTMLSelectElement
|
|
202
142
|
) {
|
|
203
|
-
item.value = `${
|
|
143
|
+
item.value = `${
|
|
144
|
+
Utils.getNestedValue(data, item.name || k) ?? ''
|
|
145
|
+
}`;
|
|
204
146
|
} else {
|
|
205
147
|
(item as any).value = data[k];
|
|
206
148
|
}
|
|
@@ -239,7 +181,7 @@ export namespace ReactUtils {
|
|
|
239
181
|
if (local) {
|
|
240
182
|
data[k] = local(item);
|
|
241
183
|
} else if (item instanceof HTMLInputElement) {
|
|
242
|
-
setNestedValue(
|
|
184
|
+
Utils.setNestedValue(
|
|
243
185
|
data,
|
|
244
186
|
item.name || k,
|
|
245
187
|
DomUtils.getInputValue(item)
|
|
@@ -248,7 +190,7 @@ export namespace ReactUtils {
|
|
|
248
190
|
item instanceof HTMLTextAreaElement ||
|
|
249
191
|
item instanceof HTMLSelectElement
|
|
250
192
|
) {
|
|
251
|
-
setNestedValue(data, item.name || k, item.value);
|
|
193
|
+
Utils.setNestedValue(data, item.name || k, item.value);
|
|
252
194
|
} else {
|
|
253
195
|
data[k] = (item as any).value;
|
|
254
196
|
}
|