react-hook-core 0.3.4 → 0.3.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/lib/core.js +13 -10
- package/lib/edit.js +35 -3
- package/lib/search.js +2 -10
- package/lib/useEdit.js +0 -13
- package/package.json +1 -1
- package/src/core.ts +10 -7
- package/src/edit.ts +39 -4
- package/src/reflect.ts +2 -3
- package/src/search.ts +1 -14
- package/src/useEdit.ts +0 -10
- package/src/useSearch.ts +1 -8
package/lib/core.js
CHANGED
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var formutil_1 = require("./formutil");
|
|
4
4
|
exports.pageSizes = [12, 24, 60, 100, 120, 180, 300, 600];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
var resources = (function () {
|
|
6
|
+
function resources() {
|
|
7
|
+
}
|
|
8
|
+
resources.phone = / |-|\.|\(|\)/g;
|
|
9
|
+
resources._cache = {};
|
|
10
|
+
resources.cache = true;
|
|
11
|
+
resources.limit = 24;
|
|
12
|
+
resources.pages = exports.pageSizes;
|
|
13
|
+
resources.pageMaxSize = 7;
|
|
14
|
+
return resources;
|
|
13
15
|
}());
|
|
14
|
-
exports.
|
|
16
|
+
exports.resources = resources;
|
|
17
|
+
exports.size = exports.pageSizes;
|
|
15
18
|
function getCurrencyCode(form) {
|
|
16
19
|
if (form) {
|
|
17
20
|
var x = form.getAttribute('currency-code');
|
|
@@ -24,7 +27,7 @@ function getCurrencyCode(form) {
|
|
|
24
27
|
exports.getCurrencyCode = getCurrencyCode;
|
|
25
28
|
function removePhoneFormat(phone) {
|
|
26
29
|
if (phone) {
|
|
27
|
-
return phone.replace(
|
|
30
|
+
return phone.replace(resources.phone, '');
|
|
28
31
|
}
|
|
29
32
|
else {
|
|
30
33
|
return phone;
|
package/lib/edit.js
CHANGED
|
@@ -5,11 +5,11 @@ function build(attributes, name) {
|
|
|
5
5
|
if (!attributes) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
|
-
if (core_1.
|
|
9
|
-
var meta = core_1.
|
|
8
|
+
if (core_1.resources.cache && name && name.length > 0) {
|
|
9
|
+
var meta = core_1.resources._cache[name];
|
|
10
10
|
if (!meta) {
|
|
11
11
|
meta = buildMetaModel(attributes);
|
|
12
|
-
core_1.
|
|
12
|
+
core_1.resources._cache[name] = meta;
|
|
13
13
|
}
|
|
14
14
|
return meta;
|
|
15
15
|
}
|
|
@@ -102,3 +102,35 @@ function handleVersion(obj, version) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
exports.handleVersion = handleVersion;
|
|
105
|
+
function isSuccessful(x) {
|
|
106
|
+
if (Array.isArray(x)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
else if (typeof x === 'object') {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
else if (typeof x === 'number' && x > 0) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
exports.isSuccessful = isSuccessful;
|
|
118
|
+
function afterSaved(res, form, resource, showFormError, alertSuccess, alertError, navigate) {
|
|
119
|
+
if (Array.isArray(res)) {
|
|
120
|
+
showFormError(form, res);
|
|
121
|
+
}
|
|
122
|
+
else if (isSuccessful(res)) {
|
|
123
|
+
alertSuccess(resource.msg_save_success, function () {
|
|
124
|
+
if (navigate) {
|
|
125
|
+
navigate(-1);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else if (res === 0) {
|
|
130
|
+
alertError(resource.error_not_found);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
alertError(resource.error_conflict);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.afterSaved = afterSaved;
|
package/lib/search.js
CHANGED
|
@@ -7,16 +7,8 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
7
7
|
return r;
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
var core_1 = require("./core");
|
|
10
11
|
var reflect_1 = require("./reflect");
|
|
11
|
-
var resources = (function () {
|
|
12
|
-
function resources() {
|
|
13
|
-
}
|
|
14
|
-
resources.limit = 24;
|
|
15
|
-
resources.pages = [12, 24, 60, 100, 120, 180, 300, 600];
|
|
16
|
-
resources.pageMaxSize = 7;
|
|
17
|
-
return resources;
|
|
18
|
-
}());
|
|
19
|
-
exports.resources = resources;
|
|
20
12
|
function getOffset(limit, page, firstLimit) {
|
|
21
13
|
var p = page && page > 0 ? page : 1;
|
|
22
14
|
if (firstLimit && firstLimit > 0) {
|
|
@@ -442,7 +434,7 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
442
434
|
if (key !== fields) {
|
|
443
435
|
if (typeof objValue === 'string' || typeof objValue === 'number') {
|
|
444
436
|
if (key === limit) {
|
|
445
|
-
if (objValue !== resources.limit) {
|
|
437
|
+
if (objValue !== core_1.resources.limit) {
|
|
446
438
|
url += getPrefix(url) + (key + "=" + objValue);
|
|
447
439
|
}
|
|
448
440
|
}
|
package/lib/useEdit.js
CHANGED
|
@@ -477,16 +477,3 @@ exports.useCoreEdit = function (refForm, initialState, service, p1, p, props) {
|
|
|
477
477
|
load: load,
|
|
478
478
|
doSave: doSave });
|
|
479
479
|
};
|
|
480
|
-
function isSuccessful(x) {
|
|
481
|
-
if (Array.isArray(x)) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
else if (typeof x === 'object') {
|
|
485
|
-
return true;
|
|
486
|
-
}
|
|
487
|
-
else if (typeof x === 'number' && x > 0) {
|
|
488
|
-
return true;
|
|
489
|
-
}
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
exports.isSuccessful = isSuccessful;
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -2,6 +2,15 @@ import { Params } from 'react-router';
|
|
|
2
2
|
import { focusFirstElement } from './formutil';
|
|
3
3
|
|
|
4
4
|
export const pageSizes = [12, 24, 60, 100, 120, 180, 300, 600];
|
|
5
|
+
// tslint:disable-next-line:class-name
|
|
6
|
+
export class resources {
|
|
7
|
+
static phone = / |-|\.|\(|\)/g;
|
|
8
|
+
static _cache: any = {};
|
|
9
|
+
static cache = true;
|
|
10
|
+
static limit = 24;
|
|
11
|
+
static pages = pageSizes;
|
|
12
|
+
static pageMaxSize = 7;
|
|
13
|
+
}
|
|
5
14
|
export const size = pageSizes;
|
|
6
15
|
export interface ModelMap {
|
|
7
16
|
[key: string]: any;
|
|
@@ -148,12 +157,6 @@ export interface DiffState<T> {
|
|
|
148
157
|
disabled: boolean;
|
|
149
158
|
}
|
|
150
159
|
|
|
151
|
-
// tslint:disable-next-line:class-name
|
|
152
|
-
export class resource {
|
|
153
|
-
static phone = / |-|\.|\(|\)/g;
|
|
154
|
-
static _cache: any = {};
|
|
155
|
-
static cache = true;
|
|
156
|
-
}
|
|
157
160
|
export function getCurrencyCode(form?: HTMLFormElement | null): string | undefined {
|
|
158
161
|
if (form) {
|
|
159
162
|
const x = form.getAttribute('currency-code');
|
|
@@ -165,7 +168,7 @@ export function getCurrencyCode(form?: HTMLFormElement | null): string | undefin
|
|
|
165
168
|
}
|
|
166
169
|
export function removePhoneFormat(phone: string): string {
|
|
167
170
|
if (phone) {
|
|
168
|
-
return phone.replace(
|
|
171
|
+
return phone.replace(resources.phone, '');
|
|
169
172
|
} else {
|
|
170
173
|
return phone;
|
|
171
174
|
}
|
package/src/edit.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NavigateFunction } from 'react-router-dom';
|
|
2
|
+
import {Attribute, Attributes, ErrorMessage, LoadingService, Locale, resources, ResourceService, StringMap, UIService, ViewService} from './core';
|
|
2
3
|
|
|
3
4
|
export interface ResultInfo<T> {
|
|
4
5
|
status: number|string;
|
|
@@ -30,11 +31,11 @@ export function build(attributes: Attributes, name?: string): MetaModel|undefine
|
|
|
30
31
|
if (!attributes) {
|
|
31
32
|
return undefined;
|
|
32
33
|
}
|
|
33
|
-
if (
|
|
34
|
-
let meta: MetaModel =
|
|
34
|
+
if (resources.cache && name && name.length > 0) {
|
|
35
|
+
let meta: MetaModel = resources._cache[name];
|
|
35
36
|
if (!meta) {
|
|
36
37
|
meta = buildMetaModel(attributes);
|
|
37
|
-
|
|
38
|
+
resources._cache[name] = meta;
|
|
38
39
|
}
|
|
39
40
|
return meta;
|
|
40
41
|
} else {
|
|
@@ -151,3 +152,37 @@ export function handleVersion<T>(obj: T, version?: string): void {
|
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
}
|
|
155
|
+
export function isSuccessful<T>(x: number|T|ErrorMessage[]): boolean {
|
|
156
|
+
if (Array.isArray(x)) {
|
|
157
|
+
return false;
|
|
158
|
+
} else if (typeof x === 'object') {
|
|
159
|
+
return true;
|
|
160
|
+
} else if (typeof x === 'number' && x > 0) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
type Result<T> = number | T | ErrorMessage[]
|
|
166
|
+
export function afterSaved<T>(
|
|
167
|
+
res: Result<T>,
|
|
168
|
+
form: HTMLFormElement | undefined,
|
|
169
|
+
resource: StringMap,
|
|
170
|
+
showFormError: (form?: HTMLFormElement, errors?: ErrorMessage[]) => ErrorMessage[],
|
|
171
|
+
alertSuccess: (msg: string, callback?: () => void) => void,
|
|
172
|
+
alertError: (msg: string) => void,
|
|
173
|
+
navigate?: NavigateFunction,
|
|
174
|
+
) {
|
|
175
|
+
if (Array.isArray(res)) {
|
|
176
|
+
showFormError(form, res)
|
|
177
|
+
} else if (isSuccessful(res)) {
|
|
178
|
+
alertSuccess(resource.msg_save_success, () => {
|
|
179
|
+
if (navigate) {
|
|
180
|
+
navigate(-1)
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
} else if (res === 0) {
|
|
184
|
+
alertError(resource.error_not_found)
|
|
185
|
+
} else {
|
|
186
|
+
alertError(resource.error_conflict)
|
|
187
|
+
}
|
|
188
|
+
}
|
package/src/reflect.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StringMap } from "./core";
|
|
1
2
|
import { NavigateFunction } from "react-router-dom"
|
|
2
3
|
|
|
3
4
|
export function clone(obj: any): any {
|
|
@@ -141,9 +142,7 @@ export function hasDiff<T>(o1: T, o2: T, keys?: string[], version?: string): boo
|
|
|
141
142
|
const diff = makeDiff(o1, o2, keys, version)
|
|
142
143
|
return !isEmptyObject(diff)
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
-
[key: string]: string;
|
|
146
|
-
}
|
|
145
|
+
|
|
147
146
|
export function goBack<T>(
|
|
148
147
|
navigate: NavigateFunction,
|
|
149
148
|
confirm: (msg: string, yesCallback?: () => void) => void,
|
package/src/search.ts
CHANGED
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import { StringMap } from "./core";
|
|
1
|
+
import { Filter, resources, StringMap } from "./core";
|
|
2
2
|
import { clone } from "./reflect";
|
|
3
3
|
|
|
4
|
-
// tslint:disable-next-line:class-name
|
|
5
|
-
export class resources {
|
|
6
|
-
static limit = 24;
|
|
7
|
-
static pages = [12, 24, 60, 100, 120, 180, 300, 600];
|
|
8
|
-
static pageMaxSize = 7;
|
|
9
|
-
}
|
|
10
|
-
interface Filter {
|
|
11
|
-
page?: number;
|
|
12
|
-
limit: number;
|
|
13
|
-
firstLimit?: number;
|
|
14
|
-
fields?: string[];
|
|
15
|
-
sort?: string;
|
|
16
|
-
}
|
|
17
4
|
interface Locale {
|
|
18
5
|
id?: string;
|
|
19
6
|
countryCode: string;
|
package/src/useEdit.ts
CHANGED
|
@@ -550,13 +550,3 @@ if (running === true) {
|
|
|
550
550
|
doSave
|
|
551
551
|
};
|
|
552
552
|
};
|
|
553
|
-
export function isSuccessful<T>(x: number|T|ErrorMessage[]): boolean {
|
|
554
|
-
if (Array.isArray(x)) {
|
|
555
|
-
return false;
|
|
556
|
-
} else if (typeof x === 'object') {
|
|
557
|
-
return true;
|
|
558
|
-
} else if (typeof x === 'number' && x > 0) {
|
|
559
|
-
return true;
|
|
560
|
-
}
|
|
561
|
-
return false;
|
|
562
|
-
}
|
package/src/useSearch.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {useEffect, useState} from 'react';
|
|
2
|
-
import {error, getName, getRemoveError, getValidateForm, hideLoading, initForm, Locale, PageChange, pageSizes, removeFormError, ResourceService, SearchParameter, SearchResult, SearchService, showLoading} from './core';
|
|
2
|
+
import {error, Filter, getName, getRemoveError, getValidateForm, hideLoading, initForm, Locale, PageChange, pageSizes, removeFormError, ResourceService, SearchParameter, SearchResult, SearchService, showLoading} from './core';
|
|
3
3
|
import {DispatchWithCallback, useMergeState} from './merge';
|
|
4
4
|
import {clone} from './reflect';
|
|
5
5
|
import {buildFromUrl} from './route';
|
|
@@ -11,13 +11,6 @@ export interface Searchable extends Pagination, Sortable {
|
|
|
11
11
|
nextPageToken?: string;
|
|
12
12
|
excluding?: string[]|number[];
|
|
13
13
|
}
|
|
14
|
-
interface Filter {
|
|
15
|
-
page?: number;
|
|
16
|
-
limit: number;
|
|
17
|
-
firstLimit?: number;
|
|
18
|
-
fields?: string[];
|
|
19
|
-
sort?: string;
|
|
20
|
-
}
|
|
21
14
|
|
|
22
15
|
export const callSearch = <T, S extends Filter>(se: S, search3: (s: S, limit?: number, offset?: number|string, fields?: string[]) => Promise<SearchResult<T>>, showResults3: (s: S, sr: SearchResult<T>, lc: Locale) => void, searchError3: (err: any) => void, lc: Locale, nextPageToken?: string) => {
|
|
23
16
|
const s = clone(se);
|