react-hook-core 0.1.3 → 0.1.6
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/README.md +1 -1
- package/lib/components.js +28 -69
- package/lib/core.js +20 -12
- package/lib/diff.js +2 -2
- package/lib/formutil.js +2 -2
- package/lib/index.js +28 -9
- package/lib/reflect.js +268 -0
- package/lib/search.js +579 -0
- package/lib/state.js +4 -4
- package/lib/update.js +7 -20
- package/lib/useEdit.js +55 -40
- package/lib/useSearch.js +48 -49
- package/lib/useView.js +24 -26
- package/package.json +5 -7
- package/src/components.ts +19 -61
- package/src/core.ts +65 -59
- package/src/diff.ts +1 -1
- package/src/formutil.ts +2 -2
- package/src/index.ts +33 -9
- package/src/reflect.ts +244 -0
- package/src/search.ts +600 -0
- package/src/state.ts +1 -1
- package/src/update.ts +7 -19
- package/src/useEdit.ts +65 -49
- package/src/useSearch.ts +54 -43
- package/src/useView.ts +31 -34
- package/tsconfig.json +3 -1
package/src/components.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {addParametersIntoUrl, append, buildMessage, changePage, changePageSize, formatResults, getFieldsFromForm, getModel, handleAppend, handleSortEvent, initFilter, mergeFilter as mergeFilter2, more, reset, Searchable, showPaging, validate} from 'search-core';
|
|
5
|
-
import {BaseDiffState, createDiffStatus, createEditStatus, DiffApprService, DiffParameter, DiffState, DiffStatusConfig, hideLoading, showLoading} from './core';
|
|
6
|
-
import {Attributes, buildId, EditStatusConfig, error, ErrorMessage, Filter, getCurrencyCode, getModelName as getModelName2, initForm, LoadingService, Locale, message, messageByHttpStatus, PageChange, pageSizes, removePhoneFormat, ResourceService, SearchParameter, SearchResult, SearchService, SearchState, StringMap, UIService, ViewParameter, ViewService} from './core';
|
|
2
|
+
import {BaseDiffState, createDiffStatus, createEditStatus, DiffApprService, DiffParameter, DiffState, DiffStatusConfig, handleToggle, hideLoading, showLoading} from './core';
|
|
3
|
+
import {Attributes, EditStatusConfig, error, ErrorMessage, Filter, getCurrencyCode, getModelName as getModelName2, initForm, LoadingService, Locale, message, messageByHttpStatus, PageChange, pageSizes, removePhoneFormat, ResourceService, SearchParameter, SearchResult, SearchService, SearchState, StringMap, UIService, ViewParameter, ViewService} from './core';
|
|
7
4
|
import {formatDiffModel, getDataFields} from './diff';
|
|
8
5
|
import {build, createModel as createModel2, EditParameter, GenericService, handleStatus, handleVersion, initPropertyNullInModel, ResultInfo} from './edit';
|
|
9
6
|
import {focusFirstError, readOnly} from './formutil';
|
|
10
7
|
import {getAutoSearch, getConfirmFunc, getDiffStatusFunc, getEditStatusFunc, getErrorFunc, getLoadingFunc, getLocaleFunc, getMsgFunc, getResource, getUIService} from './input';
|
|
8
|
+
import {clone, diff, makeDiff} from './reflect';
|
|
11
9
|
import {buildFromUrl} from './route';
|
|
10
|
+
import {addParametersIntoUrl, append, buildMessage, changePage, changePageSize, formatResults, getFieldsFromForm, getModel, handleAppend, handleSortEvent, initFilter, mergeFilter as mergeFilter2, more, Pagination, reset, showPaging, Sortable, validate} from './search';
|
|
12
11
|
import {buildFlatState, buildState, enLocale, handleEvent, handleProps, localeOf} from './state';
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
interface Searchable extends Pagination, Sortable {
|
|
14
|
+
}
|
|
15
|
+
export class ViewComponent<T, ID, P, S> extends React.Component<P, S> {
|
|
15
16
|
constructor(props: P, sv: ((id: ID, ctx?: any) => Promise<T>)|ViewService<T, ID>,
|
|
16
17
|
param: ResourceService|ViewParameter,
|
|
17
18
|
showError?: (msg: string, title?: string, detail?: string, callback?: () => void) => void,
|
|
@@ -40,7 +41,6 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
this.back = this.back.bind(this);
|
|
44
44
|
this.getModelName = this.getModelName.bind(this);
|
|
45
45
|
this.load = this.load.bind(this);
|
|
46
46
|
this.getModel = this.getModel.bind(this);
|
|
@@ -54,19 +54,13 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
|
|
|
54
54
|
loading?: LoadingService;
|
|
55
55
|
showError: (msg: string, title?: string, detail?: string, callback?: () => void) => void;
|
|
56
56
|
getLocale?: (profile?: string) => Locale;
|
|
57
|
-
loadData?: (id: ID
|
|
57
|
+
loadData?: (id: ID) => Promise<T|null>;
|
|
58
58
|
// protected service: ViewService<T, ID>;
|
|
59
59
|
form?: HTMLFormElement;
|
|
60
60
|
ref: any;
|
|
61
61
|
keys?: string[];
|
|
62
62
|
metadata?: Attributes;
|
|
63
63
|
|
|
64
|
-
back(event: any) {
|
|
65
|
-
if (event) {
|
|
66
|
-
event.preventDefault();
|
|
67
|
-
}
|
|
68
|
-
this.props.history.goBack();
|
|
69
|
-
}
|
|
70
64
|
getModelName(): string {
|
|
71
65
|
if (this.name && this.name.length > 0) {
|
|
72
66
|
return this.name;
|
|
@@ -78,13 +72,6 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
|
|
|
78
72
|
return n;
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
|
-
componentDidMount() {
|
|
82
|
-
this.form = this.ref.current;
|
|
83
|
-
const id = buildId<ID>(this.props, this.keys);
|
|
84
|
-
if (id) {
|
|
85
|
-
this.load(id);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
75
|
load(_id: ID, callback?: (m: T, showF: (model: T) => void) => void) {
|
|
89
76
|
const id: any = _id;
|
|
90
77
|
if (id != null && id !== '' && this.loadData) {
|
|
@@ -301,6 +288,7 @@ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T
|
|
|
301
288
|
protected listFormId?: string) {
|
|
302
289
|
super(props, getLocale, (ui ? ui.removeError : undefined));
|
|
303
290
|
this.resource = resourceService.resource();
|
|
291
|
+
this.hideFilter = true;
|
|
304
292
|
this.getModelName = this.getModelName.bind(this);
|
|
305
293
|
this.showMessage = this.showMessage.bind(this);
|
|
306
294
|
|
|
@@ -388,8 +376,10 @@ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T
|
|
|
388
376
|
return 'filter';
|
|
389
377
|
}
|
|
390
378
|
|
|
391
|
-
toggleFilter(event:
|
|
392
|
-
|
|
379
|
+
toggleFilter(event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void {
|
|
380
|
+
const x = !this.hideFilter;
|
|
381
|
+
handleToggle(event.target as HTMLInputElement, !x);
|
|
382
|
+
this.hideFilter = x;
|
|
393
383
|
}
|
|
394
384
|
load(s: F, autoSearch: boolean): void {
|
|
395
385
|
const obj2 = initFilter(s, this);
|
|
@@ -616,7 +606,7 @@ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T
|
|
|
616
606
|
this.doSearch();
|
|
617
607
|
}
|
|
618
608
|
}
|
|
619
|
-
export class SearchComponent<T, S extends Filter, P
|
|
609
|
+
export class SearchComponent<T, S extends Filter, P, I extends SearchState<T, S>> extends BaseSearchComponent<T, S, P, I> {
|
|
620
610
|
constructor(props: P, sv: ((s: S, ctx?: any) => Promise<SearchResult<T>>) | SearchService<T, S>,
|
|
621
611
|
param: ResourceService|SearchParameter,
|
|
622
612
|
showMessage?: (msg: string, option?: string) => void,
|
|
@@ -638,7 +628,6 @@ export class SearchComponent<T, S extends Filter, P extends RouteComponentProps,
|
|
|
638
628
|
}
|
|
639
629
|
}
|
|
640
630
|
}
|
|
641
|
-
this.add = this.add.bind(this);
|
|
642
631
|
this.call = this.call.bind(this);
|
|
643
632
|
this.showError = getErrorFunc(param, showError);
|
|
644
633
|
this.componentDidMount = this.componentDidMount.bind(this);
|
|
@@ -664,11 +653,6 @@ export class SearchComponent<T, S extends Filter, P extends RouteComponentProps,
|
|
|
664
653
|
const s: any = {};
|
|
665
654
|
return s;
|
|
666
655
|
}
|
|
667
|
-
add = (event: any) => {
|
|
668
|
-
event.preventDefault();
|
|
669
|
-
const url = this.url + '/add';
|
|
670
|
-
this.props.history.push(url);
|
|
671
|
-
}
|
|
672
656
|
call(se: S) {
|
|
673
657
|
this.running = true;
|
|
674
658
|
const s = clone(se);
|
|
@@ -708,7 +692,7 @@ export class SearchComponent<T, S extends Filter, P extends RouteComponentProps,
|
|
|
708
692
|
}
|
|
709
693
|
}
|
|
710
694
|
|
|
711
|
-
export abstract class BaseEditComponent<T, P
|
|
695
|
+
export abstract class BaseEditComponent<T, P, S> extends BaseComponent<P, S> {
|
|
712
696
|
constructor(props: P,
|
|
713
697
|
protected resourceService: ResourceService,
|
|
714
698
|
protected showMessage: (msg: string) => void,
|
|
@@ -776,7 +760,6 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
776
760
|
if (event) {
|
|
777
761
|
event.preventDefault();
|
|
778
762
|
}
|
|
779
|
-
this.props.history.goBack();
|
|
780
763
|
}
|
|
781
764
|
resetState(newMod: boolean, model: T, originalModel?: T) {
|
|
782
765
|
this.newMode = newMod;
|
|
@@ -983,7 +966,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
983
966
|
this.showError(msg.message, msg.title);
|
|
984
967
|
}
|
|
985
968
|
}
|
|
986
|
-
export class EditComponent<T, ID, P
|
|
969
|
+
export class EditComponent<T, ID, P, S> extends BaseEditComponent<T, P, S> {
|
|
987
970
|
constructor(props: P, protected service: GenericService<T, ID, number|ResultInfo<T>>,
|
|
988
971
|
param: ResourceService|EditParameter,
|
|
989
972
|
showMessage?: (msg: string, option?: string) => void,
|
|
@@ -1015,19 +998,10 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
|
|
|
1015
998
|
}
|
|
1016
999
|
this.load = this.load.bind(this);
|
|
1017
1000
|
this.doSave = this.doSave.bind(this);
|
|
1018
|
-
this.componentDidMount = this.componentDidMount.bind(this);
|
|
1019
1001
|
this.ref = React.createRef();
|
|
1020
1002
|
}
|
|
1021
1003
|
ref: any;
|
|
1022
|
-
|
|
1023
|
-
const k = (this.ui ? this.ui.registerEvents : undefined);
|
|
1024
|
-
this.form = initForm(this.ref.current, k);
|
|
1025
|
-
const id = buildId<ID>(this.props, this.keys);
|
|
1026
|
-
if (id) {
|
|
1027
|
-
this.load(id);
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
load(_id: ID, callback?: (m: T, showM: (m2: T) => void) => void) {
|
|
1004
|
+
load(_id: ID|null, callback?: (m: T, showM: (m2: T) => void) => void) {
|
|
1031
1005
|
const id: any = _id;
|
|
1032
1006
|
if (id != null && id !== '') {
|
|
1033
1007
|
const com = this;
|
|
@@ -1104,7 +1078,7 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
|
|
|
1104
1078
|
}
|
|
1105
1079
|
}
|
|
1106
1080
|
|
|
1107
|
-
export class BaseDiffApprComponent<T, ID, P
|
|
1081
|
+
export class BaseDiffApprComponent<T, ID, P, S extends BaseDiffState> extends React.Component<P, S & any> {
|
|
1108
1082
|
constructor(props: P, protected keys: string[], protected resourceService: ResourceService,
|
|
1109
1083
|
protected showMessage: (msg: string, option?: string) => void,
|
|
1110
1084
|
protected showError: (m: string, title?: string, detail?: string, callback?: () => void) => void,
|
|
@@ -1117,7 +1091,6 @@ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S exten
|
|
|
1117
1091
|
this.resource = resourceService.resource();
|
|
1118
1092
|
this.showMessage = this.showMessage.bind(this);
|
|
1119
1093
|
this.showError = this.showError.bind(this);
|
|
1120
|
-
this.back = this.back.bind(this);
|
|
1121
1094
|
this.initModel = this.initModel.bind(this);
|
|
1122
1095
|
this.postApprove = this.postApprove.bind(this);
|
|
1123
1096
|
this.postReject = this.postReject.bind(this);
|
|
@@ -1134,13 +1107,6 @@ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S exten
|
|
|
1134
1107
|
running?: boolean;
|
|
1135
1108
|
resource: StringMap;
|
|
1136
1109
|
|
|
1137
|
-
back(event: any) {
|
|
1138
|
-
if (event) {
|
|
1139
|
-
event.preventDefault();
|
|
1140
|
-
}
|
|
1141
|
-
this.props.history.goBack();
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
1110
|
initModel(): T {
|
|
1145
1111
|
const x: any = {};
|
|
1146
1112
|
return x;
|
|
@@ -1223,7 +1189,7 @@ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S exten
|
|
|
1223
1189
|
this.showError(msg.message, msg.title);
|
|
1224
1190
|
}
|
|
1225
1191
|
}
|
|
1226
|
-
export class DiffApprComponent<T, ID, P
|
|
1192
|
+
export class DiffApprComponent<T, ID, P, S extends DiffState<T>> extends BaseDiffApprComponent<T, ID, P, S> {
|
|
1227
1193
|
constructor(props: P, protected service: DiffApprService<T, ID>,
|
|
1228
1194
|
param: ResourceService|DiffParameter,
|
|
1229
1195
|
showMessage?: (msg: string, option?: string) => void,
|
|
@@ -1243,14 +1209,6 @@ export class DiffApprComponent<T, ID, P extends RouteComponentProps, S extends D
|
|
|
1243
1209
|
}
|
|
1244
1210
|
ref: any;
|
|
1245
1211
|
|
|
1246
|
-
componentDidMount() {
|
|
1247
|
-
this.form = this.ref.current;
|
|
1248
|
-
const id = buildId<ID>(this.props, this.keys);
|
|
1249
|
-
if (id) {
|
|
1250
|
-
this.load(id);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
1212
|
formatFields(value: T): T {
|
|
1255
1213
|
return value;
|
|
1256
1214
|
}
|
package/src/core.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {focusFirstElement} from './formutil';
|
|
1
|
+
import { Params } from 'react-router';
|
|
2
|
+
import { focusFirstElement } from './formutil';
|
|
3
3
|
|
|
4
4
|
export const pageSizes = [12, 24, 60, 100, 120, 180, 300, 600];
|
|
5
5
|
export interface ModelMap {
|
|
@@ -35,12 +35,12 @@ export interface SearchParameter {
|
|
|
35
35
|
auto?: boolean;
|
|
36
36
|
}
|
|
37
37
|
export interface EditStatusConfig {
|
|
38
|
-
duplicate_key: number|string;
|
|
39
|
-
not_found: number|string;
|
|
40
|
-
success: number|string;
|
|
41
|
-
version_error: number|string;
|
|
42
|
-
error?: number|string;
|
|
43
|
-
data_corrupt?: number|string;
|
|
38
|
+
duplicate_key: number | string;
|
|
39
|
+
not_found: number | string;
|
|
40
|
+
success: number | string;
|
|
41
|
+
version_error: number | string;
|
|
42
|
+
error?: number | string;
|
|
43
|
+
data_corrupt?: number | string;
|
|
44
44
|
}
|
|
45
45
|
export function createEditStatus(status?: EditStatusConfig): EditStatusConfig {
|
|
46
46
|
if (status) {
|
|
@@ -57,10 +57,10 @@ export function createEditStatus(status?: EditStatusConfig): EditStatusConfig {
|
|
|
57
57
|
return s;
|
|
58
58
|
}
|
|
59
59
|
export interface DiffStatusConfig {
|
|
60
|
-
not_found: number|string;
|
|
61
|
-
success: number|string;
|
|
62
|
-
version_error: number|string;
|
|
63
|
-
error?: number|string;
|
|
60
|
+
not_found: number | string;
|
|
61
|
+
success: number | string;
|
|
62
|
+
version_error: number | string;
|
|
63
|
+
error?: number | string;
|
|
64
64
|
}
|
|
65
65
|
export function createDiffStatus(status?: DiffStatusConfig): DiffStatusConfig {
|
|
66
66
|
if (status) {
|
|
@@ -96,7 +96,7 @@ export interface SearchState<T, S extends Filter> {
|
|
|
96
96
|
}
|
|
97
97
|
export interface SearchService<T, S extends Filter> {
|
|
98
98
|
keys?(): string[];
|
|
99
|
-
search(s: S, limit?: number, offset?: number|string, fields?: string[]): Promise<SearchResult<T>>;
|
|
99
|
+
search(s: S, limit?: number, offset?: number | string, fields?: string[]): Promise<SearchResult<T>>;
|
|
100
100
|
}
|
|
101
101
|
export interface ViewParameter {
|
|
102
102
|
resource: ResourceService;
|
|
@@ -105,9 +105,9 @@ export interface ViewParameter {
|
|
|
105
105
|
loading?: LoadingService;
|
|
106
106
|
}
|
|
107
107
|
export interface ViewService<T, ID> {
|
|
108
|
-
metadata?(): Attributes;
|
|
108
|
+
metadata?(): Attributes | undefined;
|
|
109
109
|
keys?(): string[];
|
|
110
|
-
load(id: ID, ctx?: any): Promise<T>;
|
|
110
|
+
load(id: ID, ctx?: any): Promise<T | null>;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export interface DiffParameter {
|
|
@@ -131,8 +131,8 @@ export interface DiffModel<T, ID> {
|
|
|
131
131
|
value: T;
|
|
132
132
|
}
|
|
133
133
|
export interface ApprService<ID> {
|
|
134
|
-
approve(id: ID, ctx?: any): Promise<number|string>;
|
|
135
|
-
reject(id: ID, ctx?: any): Promise<number|string>;
|
|
134
|
+
approve(id: ID, ctx?: any): Promise<number | string>;
|
|
135
|
+
reject(id: ID, ctx?: any): Promise<number | string>;
|
|
136
136
|
}
|
|
137
137
|
export interface DiffService<T, ID> {
|
|
138
138
|
keys(): string[];
|
|
@@ -148,11 +148,11 @@ export interface DiffState<T> {
|
|
|
148
148
|
|
|
149
149
|
// tslint:disable-next-line:class-name
|
|
150
150
|
export class resource {
|
|
151
|
-
static phone = /
|
|
151
|
+
static phone = / |-|\.|\(|\)/g;
|
|
152
152
|
static _cache: any = {};
|
|
153
153
|
static cache = true;
|
|
154
154
|
}
|
|
155
|
-
export function getCurrencyCode(form?: HTMLFormElement|null): string|undefined {
|
|
155
|
+
export function getCurrencyCode(form?: HTMLFormElement | null): string | undefined {
|
|
156
156
|
if (form) {
|
|
157
157
|
const x = form.getAttribute('currency-code');
|
|
158
158
|
if (x) {
|
|
@@ -182,34 +182,34 @@ export interface Message {
|
|
|
182
182
|
yes?: string;
|
|
183
183
|
no?: string;
|
|
184
184
|
}
|
|
185
|
-
export function getString(key: string, gv: StringMap|((key: string) => string)): string {
|
|
185
|
+
export function getString(key: string, gv: StringMap | ((key: string) => string)): string {
|
|
186
186
|
if (typeof gv === 'function') {
|
|
187
187
|
return gv(key);
|
|
188
188
|
} else {
|
|
189
189
|
return gv[key];
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
export function message(gv: StringMap|((key: string) => string), msg: string, title?: string, yes?: string, no?: string): Message {
|
|
192
|
+
export function message(gv: StringMap | ((key: string) => string), msg: string, title?: string, yes?: string, no?: string): Message {
|
|
193
193
|
const m2 = (msg && msg.length > 0 ? getString(msg, gv) : '');
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
194
|
+
const m: Message = { message: m2, title: '' };
|
|
195
|
+
if (title && title.length > 0) {
|
|
196
|
+
m.title = getString(title, gv);
|
|
197
|
+
}
|
|
198
|
+
if (yes && yes.length > 0) {
|
|
199
|
+
m.yes = getString(yes, gv);
|
|
200
|
+
}
|
|
201
|
+
if (no && no.length > 0) {
|
|
202
|
+
m.no = getString(no, gv);
|
|
203
|
+
}
|
|
204
|
+
return m;
|
|
205
205
|
}
|
|
206
|
-
export function messageByHttpStatus(status: number, gv: StringMap|((key: string) => string)): string {
|
|
206
|
+
export function messageByHttpStatus(status: number, gv: StringMap | ((key: string) => string)): string {
|
|
207
207
|
const k = 'status_' + status;
|
|
208
208
|
let msg = getString(k, gv);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
if (!msg || msg.length === 0) {
|
|
210
|
+
msg = getString('error_internal', gv);
|
|
211
|
+
}
|
|
212
|
+
return msg;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
export interface Locale {
|
|
@@ -232,12 +232,12 @@ export interface LoadingService {
|
|
|
232
232
|
export interface ErrorMessage {
|
|
233
233
|
field: string;
|
|
234
234
|
code: string;
|
|
235
|
-
param?: string|number|Date;
|
|
235
|
+
param?: string | number | Date;
|
|
236
236
|
message?: string;
|
|
237
237
|
}
|
|
238
238
|
export interface UIService {
|
|
239
|
-
getValue(el: HTMLInputElement, locale?: Locale, currencyCode?: string): string|number|boolean;
|
|
240
|
-
decodeFromForm(form: HTMLFormElement, locale?: Locale, currencyCode?: string|null): any;
|
|
239
|
+
getValue(el: HTMLInputElement, locale?: Locale, currencyCode?: string): string | number | boolean | null | undefined;
|
|
240
|
+
decodeFromForm(form: HTMLFormElement, locale?: Locale, currencyCode?: string | null): any;
|
|
241
241
|
|
|
242
242
|
validateForm(form?: HTMLFormElement, locale?: Locale, focusFirst?: boolean, scroll?: boolean): boolean;
|
|
243
243
|
removeFormError(form: HTMLFormElement): void;
|
|
@@ -284,26 +284,23 @@ export function buildKeys(attributes: Attributes): string[] {
|
|
|
284
284
|
}
|
|
285
285
|
return ps;
|
|
286
286
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
const sp: any = ((props as any).match ? props : (props as any)['props']);
|
|
287
|
+
type Readonly<T> = {
|
|
288
|
+
readonly [P in keyof T]: T[P];
|
|
289
|
+
};
|
|
290
|
+
export function buildId<ID>(p: Readonly<Params<string>>, keys?: string[]): ID | null {
|
|
293
291
|
if (!keys || keys.length === 0 || keys.length === 1) {
|
|
294
292
|
if (keys && keys.length === 1) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return x;
|
|
293
|
+
if (p[keys[0]]) {
|
|
294
|
+
return p[keys[0]] as any;
|
|
298
295
|
}
|
|
299
296
|
}
|
|
300
|
-
return
|
|
297
|
+
return p['id'] as any;
|
|
301
298
|
}
|
|
302
299
|
const id: any = {};
|
|
303
300
|
for (const key of keys) {
|
|
304
|
-
let v =
|
|
301
|
+
let v = p[key];
|
|
305
302
|
if (!v) {
|
|
306
|
-
v =
|
|
303
|
+
v = p[key];
|
|
307
304
|
if (!v) {
|
|
308
305
|
return null;
|
|
309
306
|
}
|
|
@@ -312,8 +309,6 @@ export function buildId<ID>(props: RouteComponentProps, keys?: string[]): ID|nul
|
|
|
312
309
|
}
|
|
313
310
|
return id;
|
|
314
311
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
312
|
export function dateToDefaultString(date: Date): string {
|
|
318
313
|
return '' + date.getFullYear() + '-' + addZero(date.getMonth() + 1, 2) + '-' + addZero(date.getDate(), 2); // DateUtil.formatDate(date, 'YYYY-MM-DD');
|
|
319
314
|
}
|
|
@@ -380,7 +375,7 @@ export function formatCurrency(currency: string|number, locale?: Locale, currenc
|
|
|
380
375
|
}
|
|
381
376
|
*/
|
|
382
377
|
|
|
383
|
-
export function initForm(form
|
|
378
|
+
export function initForm(form?: HTMLFormElement, initMat?: (f: HTMLFormElement) => void): HTMLFormElement | undefined {
|
|
384
379
|
if (form) {
|
|
385
380
|
setTimeout(() => {
|
|
386
381
|
if (initMat) {
|
|
@@ -412,7 +407,7 @@ export function error(err: any, gv: (key: string) => string, ae: (msg: string, h
|
|
|
412
407
|
export function getName(d: string, n?: string): string {
|
|
413
408
|
return (n && n.length > 0 ? n : d);
|
|
414
409
|
}
|
|
415
|
-
export function getModelName(form?: HTMLFormElement|null, name?: string): string {
|
|
410
|
+
export function getModelName(form?: HTMLFormElement | null, name?: string): string {
|
|
416
411
|
if (form) {
|
|
417
412
|
const a = form.getAttribute('model-name');
|
|
418
413
|
if (a && a.length > 0) {
|
|
@@ -473,7 +468,7 @@ export function hideLoading(s?: LoadingService): void {
|
|
|
473
468
|
export interface UIParameter {
|
|
474
469
|
ui?: UIService;
|
|
475
470
|
}
|
|
476
|
-
export function getRemoveError(u?: UIParameter, rmErr?: (el: HTMLInputElement) => void): ((el: HTMLInputElement) => void)|undefined {
|
|
471
|
+
export function getRemoveError(u?: UIParameter, rmErr?: (el: HTMLInputElement) => void): ((el: HTMLInputElement) => void) | undefined {
|
|
477
472
|
if (rmErr) {
|
|
478
473
|
return rmErr;
|
|
479
474
|
}
|
|
@@ -484,15 +479,26 @@ export function removeFormError(u?: UIParameter, f?: HTMLFormElement): void {
|
|
|
484
479
|
u.ui.removeFormError(f);
|
|
485
480
|
}
|
|
486
481
|
}
|
|
487
|
-
export function getValidateForm(u?: UIParameter, vf?: (form: HTMLFormElement, locale?: Locale, focusFirst?: boolean, scroll?: boolean) => boolean): ((form: HTMLFormElement, locale?: Locale, focusFirst?: boolean, scroll?: boolean) => boolean)|undefined {
|
|
482
|
+
export function getValidateForm(u?: UIParameter, vf?: (form: HTMLFormElement, locale?: Locale, focusFirst?: boolean, scroll?: boolean) => boolean): ((form: HTMLFormElement, locale?: Locale, focusFirst?: boolean, scroll?: boolean) => boolean) | undefined {
|
|
488
483
|
if (vf) {
|
|
489
484
|
return vf;
|
|
490
485
|
}
|
|
491
486
|
return (u && u.ui ? u.ui.validateForm : undefined);
|
|
492
487
|
}
|
|
493
|
-
export function getDecodeFromForm(u?: UIParameter, d?: (form: HTMLFormElement, locale?: Locale, currencyCode?: string) => any): ((form: HTMLFormElement, locale?: Locale, currencyCode?: string) => any)|undefined {
|
|
488
|
+
export function getDecodeFromForm(u?: UIParameter, d?: (form: HTMLFormElement, locale?: Locale, currencyCode?: string) => any): ((form: HTMLFormElement, locale?: Locale, currencyCode?: string) => any) | undefined {
|
|
494
489
|
if (d) {
|
|
495
490
|
return d;
|
|
496
491
|
}
|
|
497
492
|
return (u && u.ui ? u.ui.decodeFromForm : undefined);
|
|
498
493
|
}
|
|
494
|
+
export function handleToggle(target?: HTMLInputElement, on?: boolean): void {
|
|
495
|
+
if (target) {
|
|
496
|
+
if (on) {
|
|
497
|
+
if (!target.classList.contains('on')) {
|
|
498
|
+
target.classList.add('on');
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
target.classList.remove('on');
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
package/src/diff.ts
CHANGED
package/src/formutil.ts
CHANGED
|
@@ -74,7 +74,7 @@ export function focusFirstError(form?: HTMLFormElement|null, className?: string)
|
|
|
74
74
|
const ctrl = form[i] as HTMLInputElement;
|
|
75
75
|
const parent = ctrl.parentElement;
|
|
76
76
|
if (ctrl.classList.contains(className)
|
|
77
|
-
|| parent && parent.classList.contains(className)) {
|
|
77
|
+
|| (parent && parent.classList.contains(className))) {
|
|
78
78
|
ctrl.focus();
|
|
79
79
|
ctrl.scrollIntoView();
|
|
80
80
|
return;
|
|
@@ -86,7 +86,7 @@ export function focusFirstError(form?: HTMLFormElement|null, className?: string)
|
|
|
86
86
|
const parent = ctrl.parentElement;
|
|
87
87
|
if (ctrl.classList.contains('invalid')
|
|
88
88
|
|| ctrl.classList.contains('.ng-invalid')
|
|
89
|
-
|| parent && parent.classList.contains('invalid')) {
|
|
89
|
+
|| (parent && parent.classList.contains('invalid'))) {
|
|
90
90
|
ctrl.focus();
|
|
91
91
|
ctrl.scrollIntoView();
|
|
92
92
|
return;
|
package/src/index.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { RouteComponentProps } from 'react-router';
|
|
3
2
|
export * from './formutil';
|
|
4
3
|
export * from './util';
|
|
5
4
|
export * from './core';
|
|
6
5
|
export * from './state';
|
|
7
6
|
export * from './edit';
|
|
8
7
|
export * from './route';
|
|
9
|
-
export * from './components';
|
|
10
8
|
export * from './diff';
|
|
11
|
-
export * from './router';
|
|
12
9
|
export * from './merge';
|
|
13
10
|
export * from './update';
|
|
14
|
-
export * from './useView';
|
|
15
|
-
export * from './useEdit';
|
|
16
11
|
export * from './useSearch';
|
|
17
12
|
export * from './useMessage';
|
|
13
|
+
export * from './useEdit';
|
|
14
|
+
export * from './components';
|
|
15
|
+
export * from './search';
|
|
16
|
+
export * from './reflect';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
import {pageSizes} from './core';
|
|
19
|
+
|
|
20
|
+
export function checked(s: string[]|string|undefined, v: string): boolean|undefined {
|
|
21
|
+
if (s) {
|
|
22
|
+
if (Array.isArray(s)) {
|
|
23
|
+
return s.includes(v);
|
|
24
|
+
} else {
|
|
25
|
+
return s === v;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
export function value<T>(obj?: T): T {
|
|
31
|
+
return (obj ? obj : {} as any);
|
|
32
|
+
}
|
|
23
33
|
export interface LoadingProps {
|
|
24
34
|
error?: any;
|
|
25
35
|
}
|
|
@@ -45,3 +55,17 @@ export const Loading = (props: LoadingProps) => {
|
|
|
45
55
|
);*/
|
|
46
56
|
}
|
|
47
57
|
};
|
|
58
|
+
export interface Props {
|
|
59
|
+
id?: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
size?: number;
|
|
62
|
+
sizes?: number[];
|
|
63
|
+
onChange?: React.ChangeEventHandler<HTMLSelectElement>;
|
|
64
|
+
}
|
|
65
|
+
export function PageSizeSelect(p: Props) {
|
|
66
|
+
const g = p.sizes;
|
|
67
|
+
const s = (!g || g.length === 0 ? pageSizes : g);
|
|
68
|
+
const opts = s.map(pgSize => React.createElement('option', { key: pgSize, value: pgSize }, pgSize));
|
|
69
|
+
return React.createElement('select', { id: p.id, name: p.name, defaultValue: p.size, onChange: p.onChange }, opts);
|
|
70
|
+
}
|
|
71
|
+
export type OnClick = React.MouseEvent<HTMLElement, MouseEvent>;
|