@etsoo/react 1.7.9 → 1.7.11

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.
@@ -27,9 +27,9 @@ export declare namespace ReactUtils {
27
27
  * Update refs
28
28
  * @param refs Refs
29
29
  * @param data Data
30
- * @param callback Callback to update refs' value
30
+ * @param callback Callback to update refs' value, return false continue to process
31
31
  */
32
- function updateRefs<D, T = HTMLInputElement>(refs: Partial<DataTypes.DI<ReadonlyArray<keyof D & string>, React.MutableRefObject<T | undefined>>>, data: D, callback?: ((item: T, value: D[keyof D & string]) => void) | keyof T): void;
32
+ function updateRefs<D, T = HTMLInputElement>(refs: Partial<DataTypes.DI<ReadonlyArray<keyof D & string>, React.MutableRefObject<T | undefined>>>, data: D, callback?: ((item: T, value: D[keyof D & string]) => void | boolean) | keyof T): void;
33
33
  /**
34
34
  * Update data with refs
35
35
  * @param refs Refs
@@ -1,3 +1,4 @@
1
+ import { DomUtils } from '@etsoo/shared';
1
2
  /**
2
3
  * React utils
3
4
  */
@@ -88,7 +89,7 @@ export var ReactUtils;
88
89
  * Update refs
89
90
  * @param refs Refs
90
91
  * @param data Data
91
- * @param callback Callback to update refs' value
92
+ * @param callback Callback to update refs' value, return false continue to process
92
93
  */
93
94
  function updateRefs(refs, data, callback) {
94
95
  const local = callback == null
@@ -105,12 +106,15 @@ export var ReactUtils;
105
106
  if (item == null)
106
107
  continue;
107
108
  const value = data[k];
108
- if (local) {
109
- local(item, value);
109
+ if (local && local(item, value) !== false) {
110
+ continue;
111
+ }
112
+ else if (item instanceof HTMLInputElement ||
113
+ item instanceof HTMLTextAreaElement) {
114
+ item.value = `${value !== null && value !== void 0 ? value : ''}`;
110
115
  }
111
116
  else {
112
- // Straightforward set string value to property "value"
113
- item.value = value !== null && value !== void 0 ? value : '';
117
+ item.value = value;
114
118
  }
115
119
  }
116
120
  }
@@ -136,6 +140,12 @@ export var ReactUtils;
136
140
  if (local) {
137
141
  data[k] = local(item);
138
142
  }
143
+ else if (item instanceof HTMLInputElement) {
144
+ data[k] = DomUtils.getInputValue(item);
145
+ }
146
+ else if (item instanceof HTMLTextAreaElement) {
147
+ data[k] = item.value;
148
+ }
139
149
  else {
140
150
  data[k] = item.value;
141
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.7.9",
3
+ "version": "1.7.11",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { DataTypes, DomUtils } from '@etsoo/shared';
2
2
  import React from 'react';
3
3
 
4
4
  /**
@@ -104,7 +104,7 @@ export namespace ReactUtils {
104
104
  * Update refs
105
105
  * @param refs Refs
106
106
  * @param data Data
107
- * @param callback Callback to update refs' value
107
+ * @param callback Callback to update refs' value, return false continue to process
108
108
  */
109
109
  export function updateRefs<D, T = HTMLInputElement>(
110
110
  refs: Partial<
@@ -114,7 +114,9 @@ export namespace ReactUtils {
114
114
  >
115
115
  >,
116
116
  data: D,
117
- callback?: ((item: T, value: D[keyof D & string]) => void) | keyof T
117
+ callback?:
118
+ | ((item: T, value: D[keyof D & string]) => void | boolean)
119
+ | keyof T
118
120
  ) {
119
121
  const local: typeof callback =
120
122
  callback == null
@@ -132,11 +134,15 @@ export namespace ReactUtils {
132
134
  if (item == null) continue;
133
135
  const value = data[k];
134
136
 
135
- if (local) {
136
- local(item, value);
137
+ if (local && local(item, value) !== false) {
138
+ continue;
139
+ } else if (
140
+ item instanceof HTMLInputElement ||
141
+ item instanceof HTMLTextAreaElement
142
+ ) {
143
+ item.value = `${value ?? ''}`;
137
144
  } else {
138
- // Straightforward set string value to property "value"
139
- (item as any).value = value ?? '';
145
+ (item as any).value = value;
140
146
  }
141
147
  }
142
148
  }
@@ -172,6 +178,10 @@ export namespace ReactUtils {
172
178
 
173
179
  if (local) {
174
180
  data[k] = local(item);
181
+ } else if (item instanceof HTMLInputElement) {
182
+ data[k] = DomUtils.getInputValue(item) as any;
183
+ } else if (item instanceof HTMLTextAreaElement) {
184
+ data[k] = item.value as any;
175
185
  } else {
176
186
  data[k] = (item as any).value;
177
187
  }