react-hook-core 0.4.1 → 0.4.3
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/search.js +30 -18
- package/lib/useSearch.js +1 -1
- package/package.json +1 -1
- package/src/search.ts +42 -32
- package/src/useSearch.ts +1 -1
package/lib/search.js
CHANGED
|
@@ -410,10 +410,10 @@ function getPrefix(url) {
|
|
|
410
410
|
function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
411
411
|
if (!isFirstLoad) {
|
|
412
412
|
if (!fields || fields.length === 0) {
|
|
413
|
-
fields =
|
|
413
|
+
fields = "fields";
|
|
414
414
|
}
|
|
415
415
|
if (!limit || limit.length === 0) {
|
|
416
|
-
limit =
|
|
416
|
+
limit = "limit";
|
|
417
417
|
}
|
|
418
418
|
if (page && page > 1) {
|
|
419
419
|
if (!ft.page || ft.page <= 1) {
|
|
@@ -432,17 +432,22 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
432
432
|
var objValue = ft[key];
|
|
433
433
|
if (objValue) {
|
|
434
434
|
if (key !== fields) {
|
|
435
|
-
if (typeof objValue ===
|
|
435
|
+
if (typeof objValue === "string" || typeof objValue === "number") {
|
|
436
436
|
if (key === limit) {
|
|
437
437
|
if (objValue !== core_1.resources.limit) {
|
|
438
438
|
url += getPrefix(url) + (key + "=" + objValue);
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
else {
|
|
442
|
-
|
|
442
|
+
if (typeof objValue === "string") {
|
|
443
|
+
url += getPrefix(url) + (key + "=" + encodeURI(objValue));
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
url += getPrefix(url) + (key + "=" + objValue);
|
|
447
|
+
}
|
|
443
448
|
}
|
|
444
449
|
}
|
|
445
|
-
else if (typeof objValue ===
|
|
450
|
+
else if (typeof objValue === "object") {
|
|
446
451
|
if (objValue instanceof Date) {
|
|
447
452
|
url += getPrefix(url) + (key + "=" + objValue.toISOString());
|
|
448
453
|
}
|
|
@@ -452,14 +457,14 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
452
457
|
var strs = [];
|
|
453
458
|
for (var _a = 0, objValue_1 = objValue; _a < objValue_1.length; _a++) {
|
|
454
459
|
var subValue = objValue_1[_a];
|
|
455
|
-
if (typeof subValue ===
|
|
456
|
-
strs.push(subValue);
|
|
460
|
+
if (typeof subValue === "string") {
|
|
461
|
+
strs.push(encodeURI(subValue));
|
|
457
462
|
}
|
|
458
|
-
else if (typeof subValue ===
|
|
463
|
+
else if (typeof subValue === "number") {
|
|
459
464
|
strs.push(subValue.toString());
|
|
460
465
|
}
|
|
461
466
|
}
|
|
462
|
-
url += getPrefix(url) + (key + "=" + strs.join(
|
|
467
|
+
url += getPrefix(url) + (key + "=" + strs.join(","));
|
|
463
468
|
}
|
|
464
469
|
}
|
|
465
470
|
else {
|
|
@@ -467,11 +472,18 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
467
472
|
for (var _b = 0, keysLvl2_1 = keysLvl2; _b < keysLvl2_1.length; _b++) {
|
|
468
473
|
var key2 = keysLvl2_1[_b];
|
|
469
474
|
var objValueLvl2 = objValue[key2];
|
|
470
|
-
if (objValueLvl2
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
+
if (objValueLvl2) {
|
|
476
|
+
if (objValueLvl2 instanceof Date) {
|
|
477
|
+
url += getPrefix(url) + (key + "." + key2 + "=" + objValueLvl2.toISOString());
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
if (typeof objValueLvl2 === "string") {
|
|
481
|
+
url += getPrefix(url) + (key + "." + key2 + "=" + encodeURI(objValueLvl2));
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
url += getPrefix(url) + (key + "." + key2 + "=" + objValueLvl2);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
475
487
|
}
|
|
476
488
|
}
|
|
477
489
|
}
|
|
@@ -480,15 +492,15 @@ function addParametersIntoUrl(ft, isFirstLoad, page, fields, limit) {
|
|
|
480
492
|
}
|
|
481
493
|
}
|
|
482
494
|
}
|
|
483
|
-
var p =
|
|
495
|
+
var p = "http://";
|
|
484
496
|
var loc = window.location.href;
|
|
485
497
|
if (loc.length >= 8) {
|
|
486
498
|
var ss = loc.substring(0, 8);
|
|
487
|
-
if (ss ===
|
|
488
|
-
p =
|
|
499
|
+
if (ss === "https://") {
|
|
500
|
+
p = "https://";
|
|
489
501
|
}
|
|
490
502
|
}
|
|
491
|
-
window.history.replaceState({ path: currentUrl },
|
|
503
|
+
window.history.replaceState({ path: currentUrl }, "", p + url);
|
|
492
504
|
}
|
|
493
505
|
}
|
|
494
506
|
exports.addParametersIntoUrl = addParametersIntoUrl;
|
package/lib/useSearch.js
CHANGED
|
@@ -119,7 +119,7 @@ exports.useCoreSearch = function (refForm, initialState, service, p1, p2) {
|
|
|
119
119
|
setRerender(!rerender);
|
|
120
120
|
}, [state]);
|
|
121
121
|
var _getCurrencyCode = function () {
|
|
122
|
-
return refForm && refForm.current ? refForm.current.getAttribute('currency-code') :
|
|
122
|
+
return refForm && refForm.current ? refForm.current.getAttribute('currency-code') : 'USD';
|
|
123
123
|
};
|
|
124
124
|
var getCurrencyCode = p && p.getCurrencyCode ? p.getCurrencyCode : _getCurrencyCode;
|
|
125
125
|
var _c = merge_1.useMergeState(p), component = _c[0], setComponent = _c[1];
|
package/package.json
CHANGED
package/src/search.ts
CHANGED
|
@@ -414,59 +414,69 @@ function getPrefix(url: string): string {
|
|
|
414
414
|
export function addParametersIntoUrl<S extends Filter>(ft: S, isFirstLoad?: boolean, page?: number, fields?: string, limit?: string): void {
|
|
415
415
|
if (!isFirstLoad) {
|
|
416
416
|
if (!fields || fields.length === 0) {
|
|
417
|
-
fields =
|
|
417
|
+
fields = "fields"
|
|
418
418
|
}
|
|
419
419
|
if (!limit || limit.length === 0) {
|
|
420
|
-
limit =
|
|
420
|
+
limit = "limit"
|
|
421
421
|
}
|
|
422
422
|
if (page && page > 1) {
|
|
423
423
|
if (!ft.page || ft.page <= 1) {
|
|
424
|
-
ft.page = page
|
|
424
|
+
ft.page = page
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
const pageIndex = ft.page
|
|
427
|
+
const pageIndex = ft.page
|
|
428
428
|
if (pageIndex && !isNaN(pageIndex) && pageIndex <= 1) {
|
|
429
|
-
delete ft.page
|
|
429
|
+
delete ft.page
|
|
430
430
|
}
|
|
431
|
-
const keys = Object.keys(ft)
|
|
432
|
-
const currentUrl = window.location.host + window.location.pathname
|
|
433
|
-
let url = removeFormatUrl(currentUrl)
|
|
431
|
+
const keys = Object.keys(ft)
|
|
432
|
+
const currentUrl = window.location.host + window.location.pathname
|
|
433
|
+
let url = removeFormatUrl(currentUrl)
|
|
434
434
|
for (const key of keys) {
|
|
435
|
-
const objValue = (ft as any)[key]
|
|
435
|
+
const objValue = (ft as any)[key]
|
|
436
436
|
if (objValue) {
|
|
437
437
|
if (key !== fields) {
|
|
438
|
-
if (typeof objValue ===
|
|
438
|
+
if (typeof objValue === "string" || typeof objValue === "number") {
|
|
439
439
|
if (key === limit) {
|
|
440
440
|
if (objValue !== resources.limit) {
|
|
441
|
-
url += getPrefix(url) + `${key}=${objValue}
|
|
441
|
+
url += getPrefix(url) + `${key}=${objValue}`
|
|
442
442
|
}
|
|
443
443
|
} else {
|
|
444
|
-
|
|
444
|
+
if (typeof objValue === "string") {
|
|
445
|
+
url += getPrefix(url) + `${key}=${encodeURI(objValue)}`
|
|
446
|
+
} else {
|
|
447
|
+
url += getPrefix(url) + `${key}=${objValue}`
|
|
448
|
+
}
|
|
445
449
|
}
|
|
446
|
-
} else if (typeof objValue ===
|
|
450
|
+
} else if (typeof objValue === "object") {
|
|
447
451
|
if (objValue instanceof Date) {
|
|
448
|
-
url += getPrefix(url) + `${key}=${objValue.toISOString()}
|
|
452
|
+
url += getPrefix(url) + `${key}=${objValue.toISOString()}`
|
|
449
453
|
} else {
|
|
450
454
|
if (Array.isArray(objValue)) {
|
|
451
455
|
if (objValue.length > 0) {
|
|
452
|
-
const strs: string[] = []
|
|
456
|
+
const strs: string[] = []
|
|
453
457
|
for (const subValue of objValue) {
|
|
454
|
-
if (typeof subValue ===
|
|
455
|
-
strs.push(subValue)
|
|
456
|
-
} else if (typeof subValue ===
|
|
457
|
-
strs.push(subValue.toString())
|
|
458
|
+
if (typeof subValue === "string") {
|
|
459
|
+
strs.push(encodeURI(subValue))
|
|
460
|
+
} else if (typeof subValue === "number") {
|
|
461
|
+
strs.push(subValue.toString())
|
|
458
462
|
}
|
|
459
463
|
}
|
|
460
|
-
url += getPrefix(url) + `${key}=${strs.join(
|
|
464
|
+
url += getPrefix(url) + `${key}=${strs.join(",")}`
|
|
461
465
|
}
|
|
462
466
|
} else {
|
|
463
|
-
const keysLvl2 = Object.keys(objValue)
|
|
467
|
+
const keysLvl2 = Object.keys(objValue)
|
|
464
468
|
for (const key2 of keysLvl2) {
|
|
465
|
-
const objValueLvl2 = objValue[key2]
|
|
466
|
-
if (objValueLvl2
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
469
|
+
const objValueLvl2 = objValue[key2]
|
|
470
|
+
if (objValueLvl2) {
|
|
471
|
+
if (objValueLvl2 instanceof Date) {
|
|
472
|
+
url += getPrefix(url) + `${key}.${key2}=${objValueLvl2.toISOString()}`
|
|
473
|
+
} else {
|
|
474
|
+
if (typeof objValueLvl2 === "string") {
|
|
475
|
+
url += getPrefix(url) + `${key}.${key2}=${encodeURI(objValueLvl2)}`
|
|
476
|
+
} else {
|
|
477
|
+
url += getPrefix(url) + `${key}.${key2}=${objValueLvl2}`
|
|
478
|
+
}
|
|
479
|
+
}
|
|
470
480
|
}
|
|
471
481
|
}
|
|
472
482
|
}
|
|
@@ -475,15 +485,15 @@ export function addParametersIntoUrl<S extends Filter>(ft: S, isFirstLoad?: bool
|
|
|
475
485
|
}
|
|
476
486
|
}
|
|
477
487
|
}
|
|
478
|
-
let p =
|
|
479
|
-
const loc = window.location.href
|
|
488
|
+
let p = "http://"
|
|
489
|
+
const loc = window.location.href
|
|
480
490
|
if (loc.length >= 8) {
|
|
481
|
-
const ss = loc.substring(0, 8)
|
|
482
|
-
if (ss ===
|
|
483
|
-
p =
|
|
491
|
+
const ss = loc.substring(0, 8)
|
|
492
|
+
if (ss === "https://") {
|
|
493
|
+
p = "https://"
|
|
484
494
|
}
|
|
485
495
|
}
|
|
486
|
-
window.history.replaceState({path: currentUrl},
|
|
496
|
+
window.history.replaceState({ path: currentUrl }, "", p + url)
|
|
487
497
|
}
|
|
488
498
|
}
|
|
489
499
|
|
package/src/useSearch.ts
CHANGED
|
@@ -235,7 +235,7 @@ export const useCoreSearch = <T, S extends Filter, ST>(
|
|
|
235
235
|
}, [state]);
|
|
236
236
|
|
|
237
237
|
const _getCurrencyCode = (): string => {
|
|
238
|
-
return refForm && refForm.current ? refForm.current.getAttribute('currency-code') :
|
|
238
|
+
return refForm && refForm.current ? refForm.current.getAttribute('currency-code') : 'USD';
|
|
239
239
|
};
|
|
240
240
|
const getCurrencyCode = p && p.getCurrencyCode ? p.getCurrencyCode : _getCurrencyCode;
|
|
241
241
|
|