react-hook-core 0.1.22 → 0.1.24
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/components.js +2 -2
- package/lib/index.js +43 -15
- package/lib/useSearch.js +2 -2
- package/package.json +1 -1
- package/src/components.ts +2 -2
- package/src/core.ts +1 -1
- package/src/index.ts +73 -3
- package/src/useEdit.ts +539 -539
- package/src/useSearch.ts +523 -523
package/lib/components.js
CHANGED
|
@@ -476,8 +476,8 @@ var BaseSearchComponent = (function (_super) {
|
|
|
476
476
|
if ((!s.page || s.page <= 1) && s.firstLimit && s.firstLimit > 0) {
|
|
477
477
|
limit = s.firstLimit;
|
|
478
478
|
}
|
|
479
|
-
com.nextPageToken = sr.
|
|
480
|
-
search_1.handleAppend(com, sr.list, limit, sr.
|
|
479
|
+
com.nextPageToken = sr.next;
|
|
480
|
+
search_1.handleAppend(com, sr.list, limit, sr.next);
|
|
481
481
|
if (com.append && (s.page && s.page > 1)) {
|
|
482
482
|
com.appendList(results);
|
|
483
483
|
}
|
package/lib/index.js
CHANGED
|
@@ -21,21 +21,6 @@ __export(require("./components"));
|
|
|
21
21
|
__export(require("./search"));
|
|
22
22
|
__export(require("./reflect"));
|
|
23
23
|
__export(require("./com"));
|
|
24
|
-
exports.useCallbackState = function (initialValue) {
|
|
25
|
-
var _a = react_1.useState(initialValue), state = _a[0], _setState = _a[1];
|
|
26
|
-
var callbackQueue = react_1.useRef([]);
|
|
27
|
-
react_1.useEffect(function () {
|
|
28
|
-
callbackQueue.current.forEach(function (cb) { return cb(state); });
|
|
29
|
-
callbackQueue.current = [];
|
|
30
|
-
}, [state]);
|
|
31
|
-
var setState = function (newValue, callback) {
|
|
32
|
-
_setState(newValue);
|
|
33
|
-
if (callback && typeof callback === "function") {
|
|
34
|
-
callbackQueue.current.push(callback);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
return [state, setState];
|
|
38
|
-
};
|
|
39
24
|
function checked(s, v) {
|
|
40
25
|
if (s) {
|
|
41
26
|
if (Array.isArray(s)) {
|
|
@@ -67,6 +52,49 @@ exports.Loading = function (props) {
|
|
|
67
52
|
return (React.createElement('div', { className: 'loader-wrapper' }, React.createElement('div', { className: 'loader-sign', style: loadingStyle }, React.createElement('div', { className: 'loader' }))));
|
|
68
53
|
}
|
|
69
54
|
};
|
|
55
|
+
exports.CurrencyInput = function (props) {
|
|
56
|
+
var _a;
|
|
57
|
+
var _b = react_1.useState(undefined), state = _b[0], setState = _b[1];
|
|
58
|
+
react_1.useEffect(function () {
|
|
59
|
+
setState(props.value);
|
|
60
|
+
}, [props.value]);
|
|
61
|
+
var onChange = function (e) {
|
|
62
|
+
var v1 = e.target.value;
|
|
63
|
+
setState(v1);
|
|
64
|
+
if (props.onChange) {
|
|
65
|
+
props.onChange(e);
|
|
66
|
+
}
|
|
67
|
+
if (props.onChangeNumber) {
|
|
68
|
+
props.onChangeNumber(parseFloat(v1));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var ip = (_a = {
|
|
72
|
+
value: state,
|
|
73
|
+
className: props === null || props === void 0 ? void 0 : props.className,
|
|
74
|
+
name: props === null || props === void 0 ? void 0 : props.name,
|
|
75
|
+
onChange: onChange,
|
|
76
|
+
disabled: props === null || props === void 0 ? void 0 : props.disabled
|
|
77
|
+
},
|
|
78
|
+
_a['data-field'] = props['data-field'],
|
|
79
|
+
_a.min = props === null || props === void 0 ? void 0 : props.min,
|
|
80
|
+
_a.max = props === null || props === void 0 ? void 0 : props.max,
|
|
81
|
+
_a.type = props === null || props === void 0 ? void 0 : props.type,
|
|
82
|
+
_a.onBlur = function (e) {
|
|
83
|
+
if (props.allowZero && e.target.value === '0') {
|
|
84
|
+
setState('0');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (props.locale && props.currencyOnBlur) {
|
|
88
|
+
props.currencyOnBlur(e, props.locale, props.currencyCode, props.symbol);
|
|
89
|
+
}
|
|
90
|
+
setTimeout(function () {
|
|
91
|
+
var v2 = e.target.value;
|
|
92
|
+
setState(v2);
|
|
93
|
+
}, 50);
|
|
94
|
+
},
|
|
95
|
+
_a);
|
|
96
|
+
return React.createElement("input", { className: ip.className, onBlur: ip.onBlur, type: ip.type, name: ip.name, onChange: ip.onChange, disabled: ip.disabled, "data-field": ip['data-field'], min: ip.min, max: ip.max, value: state });
|
|
97
|
+
};
|
|
70
98
|
function formatDate(date, format) {
|
|
71
99
|
if (!date) {
|
|
72
100
|
return '';
|
package/lib/useSearch.js
CHANGED
|
@@ -328,13 +328,13 @@ exports.useCoreSearch = function (refForm, initialState, service, p1, p2) {
|
|
|
328
328
|
}
|
|
329
329
|
var am = component.appendMode;
|
|
330
330
|
var pi = (s.page && s.page >= 1 ? s.page : 1);
|
|
331
|
-
setComponent({ total: sr.total, pageIndex: pi, nextPageToken: sr.
|
|
331
|
+
setComponent({ total: sr.total, pageIndex: pi, nextPageToken: sr.next });
|
|
332
332
|
if (am) {
|
|
333
333
|
var limit = s.limit;
|
|
334
334
|
if ((!s.page || s.page <= 1) && s.firstLimit && s.firstLimit > 0) {
|
|
335
335
|
limit = s.firstLimit;
|
|
336
336
|
}
|
|
337
|
-
search_1.handleAppend(component, sr.list, limit, sr.
|
|
337
|
+
search_1.handleAppend(component, sr.list, limit, sr.next);
|
|
338
338
|
if (component.append && (s.page && s.page > 1)) {
|
|
339
339
|
appendList(results, component.list, setState);
|
|
340
340
|
}
|
package/package.json
CHANGED
package/src/components.ts
CHANGED
|
@@ -526,8 +526,8 @@ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T
|
|
|
526
526
|
if ((!s.page || s.page <= 1) && s.firstLimit && s.firstLimit > 0) {
|
|
527
527
|
limit = s.firstLimit;
|
|
528
528
|
}
|
|
529
|
-
com.nextPageToken = sr.
|
|
530
|
-
handleAppend(com, sr.list, limit, sr.
|
|
529
|
+
com.nextPageToken = sr.next;
|
|
530
|
+
handleAppend(com, sr.list, limit, sr.next);
|
|
531
531
|
if (com.append && (s.page && s.page > 1)) {
|
|
532
532
|
com.appendList(results);
|
|
533
533
|
} else {
|
package/src/core.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ChangeEvent, ChangeEventHandler, FocusEvent, useEffect, useState } from 'react';
|
|
3
3
|
export * from './formutil';
|
|
4
4
|
export * from './util';
|
|
5
5
|
export * from './core';
|
|
@@ -16,7 +16,7 @@ export * from './components';
|
|
|
16
16
|
export * from './search';
|
|
17
17
|
export * from './reflect';
|
|
18
18
|
export * from './com';
|
|
19
|
-
|
|
19
|
+
/*
|
|
20
20
|
type CallBackType<T> = (updatedValue: T) => void;
|
|
21
21
|
type SetStateType<T> = T | ((prev: T) => T);
|
|
22
22
|
type RetType = <T>(initialValue: T | (() => T)) => [T, (newValue: SetStateType<T>, callback?: CallBackType<T>) => void];
|
|
@@ -38,7 +38,7 @@ export const useCallbackState: RetType = <T>(initialValue: T | (() => T)) => {
|
|
|
38
38
|
};
|
|
39
39
|
return [state, setState];
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
*/
|
|
42
42
|
export function checked(s: string[]|string|undefined, v: string): boolean|undefined {
|
|
43
43
|
if (s) {
|
|
44
44
|
if (Array.isArray(s)) {
|
|
@@ -77,6 +77,76 @@ export const Loading = (props: LoadingProps) => {
|
|
|
77
77
|
);*/
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
+
interface Locale {
|
|
81
|
+
decimalSeparator: string;
|
|
82
|
+
groupSeparator: string;
|
|
83
|
+
currencyCode: string;
|
|
84
|
+
currencySymbol: string;
|
|
85
|
+
currencyPattern: number;
|
|
86
|
+
}
|
|
87
|
+
interface InputProps {
|
|
88
|
+
name?: string;
|
|
89
|
+
className?: string;
|
|
90
|
+
value?: string;
|
|
91
|
+
['data-field']?: string;
|
|
92
|
+
defaultValue?: string;
|
|
93
|
+
onChangeNumber?: (value: number) => void;
|
|
94
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
95
|
+
currencyOnBlur?: (event: Event|any, locale: Locale, currencyCode?: string, includingCurrencySymbol?: boolean) => void;
|
|
96
|
+
currencyCode?: string;
|
|
97
|
+
symbol?: boolean;
|
|
98
|
+
readOnly?: boolean;
|
|
99
|
+
locale?: Locale;
|
|
100
|
+
type?: string;
|
|
101
|
+
disabled?: boolean;
|
|
102
|
+
required?: boolean;
|
|
103
|
+
typeOutput?: string;
|
|
104
|
+
min?: string|number;
|
|
105
|
+
max?: string|number;
|
|
106
|
+
allowZero?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export const CurrencyInput = (props: InputProps) => {
|
|
109
|
+
const [state, setState] = useState<string|undefined>(undefined);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
setState(props.value);
|
|
112
|
+
}, [props.value]);
|
|
113
|
+
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
114
|
+
const v1 = e.target.value;
|
|
115
|
+
setState(v1);
|
|
116
|
+
if (props.onChange) {
|
|
117
|
+
props.onChange(e);
|
|
118
|
+
}
|
|
119
|
+
if (props.onChangeNumber) {
|
|
120
|
+
props.onChangeNumber(parseFloat(v1));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const ip = {
|
|
124
|
+
value: state,
|
|
125
|
+
className: props?.className,
|
|
126
|
+
name: props?.name,
|
|
127
|
+
onChange,
|
|
128
|
+
disabled: props?.disabled,
|
|
129
|
+
['data-field']: props['data-field'],
|
|
130
|
+
min: props?.min,
|
|
131
|
+
max: props?.max,
|
|
132
|
+
type: props?.type,
|
|
133
|
+
onBlur: (e: FocusEvent<HTMLInputElement>) => {
|
|
134
|
+
if (props.allowZero && e.target.value === '0') {
|
|
135
|
+
setState('0');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (props.locale && props.currencyOnBlur) {
|
|
139
|
+
props.currencyOnBlur(e, props.locale, props.currencyCode, props.symbol);
|
|
140
|
+
}
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
const v2 = e.target.value;
|
|
143
|
+
setState(v2);
|
|
144
|
+
}, 50);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
// return <input className={ip.className} type={ip.type} name={ip.name} onChange={ip.onChange} disabled={ip.disabled} data-field={ip['data-field']} min={ip.min} max={ip.max} value={state} />;
|
|
148
|
+
return React.createElement("input", { className: ip.className, onBlur: ip.onBlur, type: ip.type, name: ip.name, onChange: ip.onChange, disabled: ip.disabled, "data-field": ip['data-field'], min: ip.min, max: ip.max, value: state });
|
|
149
|
+
};
|
|
80
150
|
export type OnClick = React.MouseEvent<HTMLElement, MouseEvent>;
|
|
81
151
|
export function formatDate(date: Date | null | undefined, format: string): string {
|
|
82
152
|
if (!date) {
|