react-hook-core 0.1.7 → 0.1.10
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 +13 -9
- package/lib/reflect.js +3 -1
- package/lib/state.js +8 -0
- package/lib/useEdit.js +6 -3
- package/package.json +1 -1
- package/src/com.ts +1 -1
- package/src/components.ts +23 -18
- package/src/edit.ts +1 -1
- package/src/reflect.ts +3 -1
- package/src/state.ts +7 -0
- package/src/useEdit.ts +6 -6
package/lib/components.js
CHANGED
|
@@ -398,16 +398,20 @@ var BaseSearchComponent = (function (_super) {
|
|
|
398
398
|
this.initFields = true;
|
|
399
399
|
return fs;
|
|
400
400
|
};
|
|
401
|
-
BaseSearchComponent.prototype.clearQ = function () {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
m.q = '';
|
|
405
|
-
this.setState({ model: m });
|
|
401
|
+
BaseSearchComponent.prototype.clearQ = function (e) {
|
|
402
|
+
if (e) {
|
|
403
|
+
e.preventDefault();
|
|
406
404
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
405
|
+
var n = this.getModelName();
|
|
406
|
+
if (n && n.length > 0) {
|
|
407
|
+
var m = this.state[n];
|
|
408
|
+
if (m) {
|
|
409
|
+
m.q = '';
|
|
410
|
+
var setObj = {};
|
|
411
|
+
setObj[n] = m;
|
|
412
|
+
this.setState(setObj);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
411
415
|
}
|
|
412
416
|
};
|
|
413
417
|
BaseSearchComponent.prototype.search = function (event) {
|
package/lib/reflect.js
CHANGED
|
@@ -116,7 +116,9 @@ function diff(obj1, obj2) {
|
|
|
116
116
|
return fields;
|
|
117
117
|
}
|
|
118
118
|
exports.diff = diff;
|
|
119
|
-
function makeDiff(
|
|
119
|
+
function makeDiff(o1, o2, keys, version) {
|
|
120
|
+
var obj1 = o1;
|
|
121
|
+
var obj2 = o2;
|
|
120
122
|
var obj3 = {};
|
|
121
123
|
var s = diff(obj1, obj2);
|
|
122
124
|
if (s.length === 0) {
|
package/lib/state.js
CHANGED
|
@@ -120,6 +120,14 @@ function buildState(e, state, ctrl, modelName, tloc) {
|
|
|
120
120
|
return objSet;
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
|
+
if (ctrl.tagName === 'SELECT') {
|
|
124
|
+
if (ctrl.value === '' || !ctrl.value) {
|
|
125
|
+
ctrl.removeAttribute('data-value');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
ctrl.setAttribute('data-value', 'data-value');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
123
131
|
var data = util_1.valueOf(ctrl, tloc, e.type);
|
|
124
132
|
if (data.mustChange) {
|
|
125
133
|
if (field.indexOf('.') < 0 && field.indexOf('[') < 0) {
|
package/lib/useEdit.js
CHANGED
|
@@ -30,7 +30,7 @@ exports.useEdit = function (refForm, initialState, service, p2, p) {
|
|
|
30
30
|
}
|
|
31
31
|
var n = baseProps.getModelName(refForm.current);
|
|
32
32
|
var obj = {};
|
|
33
|
-
obj[n] = baseProps.
|
|
33
|
+
obj[n] = baseProps.createModel();
|
|
34
34
|
baseProps.setState(obj);
|
|
35
35
|
var keys;
|
|
36
36
|
if (p && !p.keys && service && service.metadata) {
|
|
@@ -63,7 +63,7 @@ exports.useEditProps = function (props, refForm, initialState, service, p2, p) {
|
|
|
63
63
|
}
|
|
64
64
|
var n = baseProps.getModelName(refForm.current);
|
|
65
65
|
var obj = {};
|
|
66
|
-
obj[n] = baseProps.
|
|
66
|
+
obj[n] = baseProps.createModel();
|
|
67
67
|
baseProps.setState(obj);
|
|
68
68
|
var keys;
|
|
69
69
|
if (p && !p.keys && service && service.metadata) {
|
|
@@ -415,7 +415,10 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
415
415
|
getModelName: getModelName,
|
|
416
416
|
resetState: resetState,
|
|
417
417
|
handleNotFound: handleNotFound,
|
|
418
|
-
getModel: getModel,
|
|
418
|
+
getModel: getModel,
|
|
419
|
+
createModel: createModel,
|
|
420
|
+
create: create,
|
|
421
|
+
save: save,
|
|
419
422
|
onSave: onSave,
|
|
420
423
|
confirm: confirm,
|
|
421
424
|
validate: validate, showMessage: p1.showMessage, succeed: succeed,
|
package/package.json
CHANGED
package/src/com.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface Props {
|
|
|
26
26
|
pageSizeChanged?: (event: any) => void;
|
|
27
27
|
search?: React.MouseEventHandler<HTMLElement>;
|
|
28
28
|
toggle?: React.MouseEventHandler<HTMLElement>;
|
|
29
|
-
clear?: React.MouseEventHandler<
|
|
29
|
+
clear?: React.MouseEventHandler<HTMLButtonElement>;
|
|
30
30
|
onChange?: (e: any, callback?: (() => void) | undefined, lc?: Locale | undefined) => void;
|
|
31
31
|
}
|
|
32
32
|
export function Search(p: Props) {
|
package/src/components.ts
CHANGED
|
@@ -443,18 +443,23 @@ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T
|
|
|
443
443
|
this.setState(prevState => ({ isPageSizeOpenDropDown: !(prevState as any).isPageSizeOpenDropDown } as any));
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
-
clearQ(): void {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
this.
|
|
453
|
-
|
|
454
|
-
|
|
446
|
+
clearQ(e?: React.MouseEvent<HTMLButtonElement, MouseEvent>): void {
|
|
447
|
+
if (e) {
|
|
448
|
+
e.preventDefault();
|
|
449
|
+
}
|
|
450
|
+
const n = this.getModelName();
|
|
451
|
+
if (n && n.length > 0) {
|
|
452
|
+
const m = (this.state as any)[n];
|
|
453
|
+
if (m) {
|
|
454
|
+
m.q = '';
|
|
455
|
+
const setObj: any = {};
|
|
456
|
+
setObj[n] = m;
|
|
457
|
+
this.setState(setObj);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
455
460
|
}
|
|
456
461
|
}
|
|
457
|
-
search(event:
|
|
462
|
+
search(event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void {
|
|
458
463
|
if (event) {
|
|
459
464
|
event.preventDefault();
|
|
460
465
|
if (!this.getSearchForm()) {
|
|
@@ -806,7 +811,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
806
811
|
}
|
|
807
812
|
}
|
|
808
813
|
|
|
809
|
-
create = (event:
|
|
814
|
+
create = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
810
815
|
if (event) {
|
|
811
816
|
event.preventDefault();
|
|
812
817
|
}
|
|
@@ -823,9 +828,9 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
823
828
|
}, 100);
|
|
824
829
|
}
|
|
825
830
|
}
|
|
826
|
-
save = (event:
|
|
831
|
+
save = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
827
832
|
event.preventDefault();
|
|
828
|
-
|
|
833
|
+
event.persist();
|
|
829
834
|
if (!this.form && event && event.target) {
|
|
830
835
|
this.form = (event.target as HTMLInputElement).form;
|
|
831
836
|
}
|
|
@@ -856,7 +861,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
856
861
|
});
|
|
857
862
|
} else {
|
|
858
863
|
const diffObj = makeDiff(initPropertyNullInModel(this.orginalModel, this.metadata), obj, this.keys, this.version);
|
|
859
|
-
const keys = Object.keys(diffObj);
|
|
864
|
+
const keys = Object.keys(diffObj as any);
|
|
860
865
|
if (keys.length === 0) {
|
|
861
866
|
this.showMessage(r.value('msg_no_change'));
|
|
862
867
|
} else {
|
|
@@ -881,7 +886,7 @@ export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
|
881
886
|
}
|
|
882
887
|
}
|
|
883
888
|
|
|
884
|
-
doSave(obj: T, dif?: T
|
|
889
|
+
doSave(obj: T, dif?: Partial<T>, isBack?: boolean) {
|
|
885
890
|
}
|
|
886
891
|
|
|
887
892
|
succeed(msg: string, isBack?: boolean, result?: ResultInfo<T>) {
|
|
@@ -1053,12 +1058,12 @@ export class EditComponent<T, ID, P, S> extends BaseEditComponent<T, P, S> {
|
|
|
1053
1058
|
}
|
|
1054
1059
|
}
|
|
1055
1060
|
}
|
|
1056
|
-
doSave(obj: T, body?: T
|
|
1061
|
+
doSave(obj: T, body?: Partial<T>, isBack?: boolean) {
|
|
1057
1062
|
this.running = true;
|
|
1058
1063
|
showLoading(this.loading);
|
|
1059
1064
|
const isBackO = (isBack == null || isBack === undefined ? this.backOnSuccess : isBack);
|
|
1060
1065
|
const com = this;
|
|
1061
|
-
let m = obj;
|
|
1066
|
+
let m: T|Partial<T> = obj;
|
|
1062
1067
|
let fn = this.newMode ? this.service.insert : this.service.update;
|
|
1063
1068
|
if (!this.newMode) {
|
|
1064
1069
|
if (this.patchable === true && this.service.patch && body && Object.keys(body).length > 0) {
|
|
@@ -1066,7 +1071,7 @@ export class EditComponent<T, ID, P, S> extends BaseEditComponent<T, P, S> {
|
|
|
1066
1071
|
fn = this.service.patch;
|
|
1067
1072
|
}
|
|
1068
1073
|
}
|
|
1069
|
-
fn(m).then(result => {
|
|
1074
|
+
fn(m as any).then(result => {
|
|
1070
1075
|
com.postSave(result, isBackO);
|
|
1071
1076
|
com.running = false;
|
|
1072
1077
|
hideLoading(com.loading);
|
package/src/edit.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface EditParameter {
|
|
|
17
17
|
status?: EditStatusConfig;
|
|
18
18
|
}
|
|
19
19
|
export interface GenericService<T, ID, R> extends ViewService<T, ID> {
|
|
20
|
-
patch?(obj: T
|
|
20
|
+
patch?(obj: Partial<T>, ctx?: any): Promise<R>;
|
|
21
21
|
insert(obj: T, ctx?: any): Promise<R>;
|
|
22
22
|
update(obj: T, ctx?: any): Promise<R>;
|
|
23
23
|
delete?(id: ID, ctx?: any): Promise<number>;
|
package/src/reflect.ts
CHANGED
|
@@ -105,7 +105,9 @@ export function diff(obj1: any, obj2: any): string[] {
|
|
|
105
105
|
return fields;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export function makeDiff(
|
|
108
|
+
export function makeDiff<T>(o1: T, o2: T, keys?: string[], version?: string): Partial<T> {
|
|
109
|
+
const obj1: any = o1;
|
|
110
|
+
const obj2: any = o2;
|
|
109
111
|
const obj3: any = {};
|
|
110
112
|
const s = diff(obj1, obj2);
|
|
111
113
|
if (s.length === 0) {
|
package/src/state.ts
CHANGED
|
@@ -100,6 +100,13 @@ export function buildState<S, K extends keyof S>(e: any, state: Readonly<S>, ctr
|
|
|
100
100
|
objSet[modelName] = model;
|
|
101
101
|
return objSet;
|
|
102
102
|
} else {
|
|
103
|
+
if (ctrl.tagName === 'SELECT') {
|
|
104
|
+
if (ctrl.value === '' || !ctrl.value) {
|
|
105
|
+
ctrl.removeAttribute('data-value');
|
|
106
|
+
} else {
|
|
107
|
+
ctrl.setAttribute('data-value', 'data-value');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
103
110
|
const data = valueOf(ctrl, tloc, e.type);
|
|
104
111
|
if (data.mustChange) {
|
|
105
112
|
if (field.indexOf('.') < 0 && field.indexOf('[') < 0) {
|
package/src/useEdit.ts
CHANGED
|
@@ -80,7 +80,7 @@ export const useEdit = <T, ID, S>(
|
|
|
80
80
|
}
|
|
81
81
|
const n = baseProps.getModelName(refForm.current);
|
|
82
82
|
const obj: any = {};
|
|
83
|
-
obj[n] = baseProps.
|
|
83
|
+
obj[n] = baseProps.createModel();
|
|
84
84
|
baseProps.setState(obj);
|
|
85
85
|
let keys: string[]|undefined;
|
|
86
86
|
if (p && !p.keys && service && service.metadata) {
|
|
@@ -120,7 +120,7 @@ export const useEditProps = <T, ID, S, P>(
|
|
|
120
120
|
}
|
|
121
121
|
const n = baseProps.getModelName(refForm.current);
|
|
122
122
|
const obj: any = {};
|
|
123
|
-
obj[n] = baseProps.
|
|
123
|
+
obj[n] = baseProps.createModel();
|
|
124
124
|
baseProps.setState(obj);
|
|
125
125
|
let keys: string[]|undefined;
|
|
126
126
|
if (p && !p.keys && service && service.metadata) {
|
|
@@ -288,7 +288,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
288
288
|
validate(obj, () => {
|
|
289
289
|
const msg = message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
|
|
290
290
|
p1.confirm(msg.message, msg.title, () => {
|
|
291
|
-
doSave(obj, diffObj, version, isBack);
|
|
291
|
+
doSave(obj, diffObj as any, version, isBack);
|
|
292
292
|
}, msg.no, msg.yes);
|
|
293
293
|
});
|
|
294
294
|
}
|
|
@@ -403,7 +403,7 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
403
403
|
};
|
|
404
404
|
const handleDuplicateKey = (p && p.handleDuplicateKey ? p.handleDuplicateKey : _handleDuplicateKey);
|
|
405
405
|
|
|
406
|
-
const _doSave = (obj: T, body?: T
|
|
406
|
+
const _doSave = (obj: T, body?: Partial<T>, version?: string, isBack?: boolean) => {
|
|
407
407
|
setRunning(true);
|
|
408
408
|
showLoading(p1.loading);
|
|
409
409
|
const isBackO = (isBack == null || isBack === undefined ? true : isBack);
|
|
@@ -483,8 +483,8 @@ export const useCoreEdit = <T, ID, S, P>(
|
|
|
483
483
|
resetState,
|
|
484
484
|
handleNotFound,
|
|
485
485
|
getModel,
|
|
486
|
-
|
|
487
|
-
|
|
486
|
+
createModel,
|
|
487
|
+
create,
|
|
488
488
|
save,
|
|
489
489
|
onSave,
|
|
490
490
|
// eslint-disable-next-line no-restricted-globals
|