@nyris/nyris-webapp 0.3.2 → 0.3.5
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/build/asset-manifest.json +8 -8
- package/build/index.html +1 -1
- package/build/js/test.js +14 -20
- package/build/{precache-manifest.8f85a4fff2063a7498a608ec69549bb1.js → precache-manifest.bbb31f2ce7710d7eb3175b1b48241d24.js} +9 -9
- package/build/service-worker.js +1 -1
- package/build/static/js/2.4a55bc61.chunk.js +3 -0
- package/build/static/js/{2.efc0ab83.chunk.js.LICENSE.txt → 2.4a55bc61.chunk.js.LICENSE.txt} +0 -9
- package/build/static/js/2.4a55bc61.chunk.js.map +1 -0
- package/build/static/js/main.2660f94a.chunk.js +2 -0
- package/build/static/js/main.2660f94a.chunk.js.map +1 -0
- package/package.json +3 -3
- package/public/js/test.js +14 -20
- package/src/App.tsx +3 -7
- package/src/Store/Nyris.ts +7 -7
- package/src/Store/Search.ts +48 -74
- package/src/Store/Store.ts +12 -5
- package/src/components/CustomHits/index.tsx +57 -0
- package/src/components/DragDropFile.tsx +27 -23
- package/src/components/ExampleImages.tsx +2 -2
- package/src/components/Feedback.tsx +2 -2
- package/src/components/Footer.tsx +1 -1
- package/src/components/HeaderMd.tsx +4 -5
- package/src/index.tsx +2 -1
- package/src/modules/LandingPage/{indexApp.tsx → App.tsx} +52 -208
- package/src/modules/LandingPage/{indexAppMD.tsx → AppMD.tsx} +52 -147
- package/src/modules/LandingPage/index.tsx +169 -0
- package/src/modules/LandingPage/indexNewVersion.tsx +14 -21
- package/src/modules/LandingPage/propsType.ts +43 -0
- package/src/page/result/index.tsx +51 -106
- package/src/services/Feedback.ts +46 -47
- package/src/services/image.ts +28 -98
- package/src/services/session.ts +13 -16
- package/src/services/types.ts +2 -48
- package/src/types.ts +12 -8
- package/build/static/js/2.efc0ab83.chunk.js +0 -3
- package/build/static/js/2.efc0ab83.chunk.js.map +0 -1
- package/build/static/js/main.3bfed050.chunk.js +0 -2
- package/build/static/js/main.3bfed050.chunk.js.map +0 -1
- package/src/App.test.tsx +0 -49
- package/src/Store/common.d.ts +0 -10
- package/src/Store/epics/feedback.ts +0 -59
- package/src/Store/epics/types.ts +0 -12
- package/src/components/preview/preview.tsx +0 -433
- package/src/services/findByImage.ts +0 -24
- package/src/services/findRegionsCustom.ts +0 -212
- package/src/services/nyris.ts +0 -123
package/src/services/image.ts
CHANGED
|
@@ -1,110 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
NyrisAPISettings,
|
|
3
|
+
RectCoords,
|
|
4
|
+
selectFirstCenteredRegion,
|
|
5
|
+
urlOrBlobToCanvas
|
|
6
|
+
} from "@nyris/nyris-api";
|
|
3
7
|
import NyrisAPI from "@nyris/nyris-api";
|
|
4
|
-
import {
|
|
8
|
+
import {isEqual} from "lodash";
|
|
5
9
|
|
|
6
|
-
export const
|
|
7
|
-
try {
|
|
8
|
-
const { settings } = stateStore;
|
|
9
|
-
let options = settings;
|
|
10
|
-
const nyrisApi = new NyrisAPICT(settings);
|
|
11
|
-
const randomId = Math.random().toString();
|
|
10
|
+
export const defaultRect = {x1: 0, x2: 1, y1: 0, y2: 1};
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export const createImage = async (fileOrUrl: File|string|HTMLCanvasElement) => {
|
|
13
|
+
const image = fileOrUrl instanceof HTMLCanvasElement ? fileOrUrl : await urlOrBlobToCanvas(fileOrUrl);
|
|
14
|
+
return image;
|
|
15
|
+
}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
17
|
+
export const findRegions = async (image: HTMLCanvasElement, settings: NyrisAPISettings) => {
|
|
18
|
+
const nyrisApi = new NyrisAPI(settings);
|
|
19
|
+
let regions = await nyrisApi.findRegions(image);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const { results, requestId, duration, categoryPredictions, codes } =
|
|
26
|
-
await nyrisApi.findByImage(image, options);
|
|
27
|
-
const payload = {
|
|
28
|
-
results,
|
|
29
|
-
requestId,
|
|
30
|
-
categoryPredictions,
|
|
31
|
-
codes,
|
|
32
|
-
duration,
|
|
33
|
-
regions,
|
|
34
|
-
requestImage: imageFileCanvas,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return payload;
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.log("error serviceImage", error);
|
|
40
|
-
return;
|
|
21
|
+
const selectedRegion = selectFirstCenteredRegion(regions, 0.3, defaultRect);
|
|
22
|
+
return {
|
|
23
|
+
selectedRegion: isEqual(selectedRegion, defaultRect) ? undefined : selectedRegion,
|
|
24
|
+
regions
|
|
41
25
|
}
|
|
42
26
|
};
|
|
43
27
|
|
|
44
|
-
export const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const { settings } = stateStore;
|
|
50
|
-
const api = new NyrisAPI(settings);
|
|
51
|
-
const image = await urlOrBlobToCanvas(file);
|
|
52
|
-
const randomId = Math.random().toString();
|
|
53
|
-
const imageFileCanvas = { canvas: image, id: randomId };
|
|
54
|
-
let options: ImageSearchOptions = {
|
|
55
|
-
cropRect: rectCoords,
|
|
56
|
-
};
|
|
57
|
-
try {
|
|
58
|
-
const { results, duration, requestId, categoryPredictions, codes } =
|
|
59
|
-
await api.findByImage(image, options);
|
|
60
|
-
return {
|
|
61
|
-
results,
|
|
62
|
-
requestId,
|
|
63
|
-
duration,
|
|
64
|
-
categoryPredictions,
|
|
65
|
-
codes,
|
|
66
|
-
requestImage: imageFileCanvas,
|
|
67
|
-
};
|
|
68
|
-
} catch (e) {
|
|
69
|
-
console.warn("search failed serviceImageNonRegion", e);
|
|
28
|
+
export const findByImage = (image: HTMLCanvasElement, settings: NyrisAPISettings, region?: RectCoords) => {
|
|
29
|
+
const nyrisApi = new NyrisAPI(settings);
|
|
30
|
+
let options = {};
|
|
31
|
+
if (region) {
|
|
32
|
+
options = { cropRect: region };
|
|
70
33
|
}
|
|
34
|
+
return nyrisApi.findByImage(image, options);
|
|
71
35
|
};
|
|
72
36
|
|
|
73
|
-
export const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
region?: any
|
|
77
|
-
) => {
|
|
78
|
-
try {
|
|
79
|
-
const { settings } = stateStore;
|
|
80
|
-
|
|
81
|
-
let options = settings;
|
|
82
|
-
const nyrisApi = new NyrisAPICT(settings);
|
|
83
|
-
if (region) {
|
|
84
|
-
let { x1, x2, y1, y2 } = region;
|
|
85
|
-
let crop = rectToCrop({
|
|
86
|
-
x1: x1 * image.width,
|
|
87
|
-
x2: x2 * image.width,
|
|
88
|
-
y1: y1 * image.height,
|
|
89
|
-
y2: y2 * image.height,
|
|
90
|
-
});
|
|
91
|
-
options = {
|
|
92
|
-
...options,
|
|
93
|
-
crop,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const { results, duration, requestId, categoryPredictions, codes } =
|
|
97
|
-
await nyrisApi.findByImage(image, options);
|
|
98
|
-
const payload = {
|
|
99
|
-
results,
|
|
100
|
-
requestId,
|
|
101
|
-
categoryPredictions,
|
|
102
|
-
codes,
|
|
103
|
-
duration,
|
|
104
|
-
regions: region,
|
|
105
|
-
};
|
|
106
|
-
return payload;
|
|
107
|
-
} catch (error: any) {
|
|
108
|
-
console.log("error searchImageByPosition", error);
|
|
109
|
-
}
|
|
37
|
+
export const findByCadFile = (file: File, settings: NyrisAPISettings) => {
|
|
38
|
+
const nyrisApi = new NyrisAPI(settings);
|
|
39
|
+
return nyrisApi.findByCad(file, {});
|
|
110
40
|
};
|
package/src/services/session.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {NyrisAPISettings} from "@nyris/nyris-api";
|
|
3
3
|
|
|
4
4
|
const httpClient = axios.create();
|
|
5
5
|
|
|
6
|
-
export const createSessionByApi = async (
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} catch (error: any) {
|
|
18
|
-
console.log("error createAction:", error);
|
|
19
|
-
}
|
|
6
|
+
export const createSessionByApi = async (settings: NyrisAPISettings) => {
|
|
7
|
+
const { apiKey, baseUrl} = settings;
|
|
8
|
+
let headers = {
|
|
9
|
+
"X-Api-Key": apiKey,
|
|
10
|
+
};
|
|
11
|
+
let response = await httpClient.request({
|
|
12
|
+
method: "POST",
|
|
13
|
+
url: `${baseUrl}/find/v1/session`,
|
|
14
|
+
headers,
|
|
15
|
+
});
|
|
16
|
+
return response.data.session;
|
|
20
17
|
};
|
package/src/services/types.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
// import {SearchAction, SearchState} from "./actions/searchActions";
|
|
2
2
|
// import {NyrisAction, NyrisAppState} from "./actions/nyrisAppActions";
|
|
3
3
|
|
|
4
|
-
export interface MDSettings {
|
|
5
|
-
customFontFamily?: string,
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
appBarTitle: string,
|
|
9
|
-
appBarCustomBackgroundColor?: string,
|
|
10
|
-
appBarCustomTextColor?: string,
|
|
11
|
-
|
|
12
|
-
primaryColor: string,
|
|
13
|
-
secondaryColor: string,
|
|
14
|
-
resultFirstRowProperty: string,
|
|
15
|
-
resultSecondRowProperty: string,
|
|
16
|
-
|
|
17
|
-
resultLinkText?: string,
|
|
18
|
-
resultLinkIcon?: string,
|
|
19
|
-
}
|
|
5
|
+
import {MDSettings} from "../types";
|
|
20
6
|
|
|
21
7
|
export interface SearchServiceSettings {
|
|
22
8
|
xOptions: boolean | string,
|
|
@@ -41,27 +27,6 @@ export interface SearchServiceSettings {
|
|
|
41
27
|
useRecommendations: boolean
|
|
42
28
|
}
|
|
43
29
|
|
|
44
|
-
export interface ImageSearchOptions {
|
|
45
|
-
geoLocation?: { lat: number, lon: number, dist: number };
|
|
46
|
-
crop?: { x: number, y: number, w: number, h: number };
|
|
47
|
-
maxWidth: number;
|
|
48
|
-
maxHeight: number;
|
|
49
|
-
useRecommendations: boolean;
|
|
50
|
-
jpegQuality: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface RectCoords {
|
|
54
|
-
x1: number,
|
|
55
|
-
y1: number,
|
|
56
|
-
x2: number,
|
|
57
|
-
y2: number
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type Region = {
|
|
61
|
-
className?: string,
|
|
62
|
-
confidence?: number
|
|
63
|
-
} & RectCoords
|
|
64
|
-
|
|
65
30
|
export interface Crop {
|
|
66
31
|
x: number,
|
|
67
32
|
y: number,
|
|
@@ -74,23 +39,12 @@ export interface WH {
|
|
|
74
39
|
h: number
|
|
75
40
|
}
|
|
76
41
|
|
|
77
|
-
// export type AppState = {
|
|
78
|
-
// search: SearchState,
|
|
79
|
-
// settings: SearchServiceSettings,
|
|
80
|
-
// nyrisDesign: NyrisAppState
|
|
81
|
-
// };
|
|
82
|
-
|
|
83
|
-
// export type AppAction =
|
|
84
|
-
// | SearchAction
|
|
85
|
-
// | NyrisAction
|
|
86
|
-
|
|
87
|
-
|
|
88
42
|
export interface Result {
|
|
89
43
|
position: number,
|
|
90
44
|
sku?: string,
|
|
91
45
|
title?: string,
|
|
92
46
|
l?: string,
|
|
93
47
|
img?: { url?: string },
|
|
94
|
-
// There can be also any other
|
|
48
|
+
// There can be also any other data
|
|
95
49
|
[x: string]: any
|
|
96
50
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {NyrisAPISettings} from "@nyris/nyris-api";
|
|
2
|
-
import { NyrisAction } from "Store/common";
|
|
3
2
|
import { NyrisAppState } from "Store/Nyris";
|
|
4
|
-
import {
|
|
3
|
+
import { SearchState } from "Store/Search";
|
|
5
4
|
|
|
6
5
|
export interface MDSettings {
|
|
7
6
|
customFontFamily?: string,
|
|
@@ -21,6 +20,12 @@ export interface MDSettings {
|
|
|
21
20
|
active?: boolean
|
|
22
21
|
}
|
|
23
22
|
|
|
23
|
+
export interface AlgoliaSettings {
|
|
24
|
+
apiKey: string,
|
|
25
|
+
appId: string,
|
|
26
|
+
indexName: string
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
export interface AppSettings extends NyrisAPISettings {
|
|
25
30
|
exampleImages: string[],
|
|
26
31
|
preview: boolean,
|
|
@@ -28,9 +33,9 @@ export interface AppSettings extends NyrisAPISettings {
|
|
|
28
33
|
noImageUrl?: string,
|
|
29
34
|
resultTemplate?: string,
|
|
30
35
|
regions: boolean,
|
|
31
|
-
materialDesign?: MDSettings,
|
|
32
36
|
instantRedirectPatterns: string[],
|
|
33
|
-
themePage: ThemeChoice
|
|
37
|
+
themePage: ThemeChoice,
|
|
38
|
+
algolia?: AlgoliaSettings
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export interface DefaultThemeSettings {
|
|
@@ -53,10 +58,6 @@ export type AppState = {
|
|
|
53
58
|
nyrisDesign: NyrisAppState
|
|
54
59
|
};
|
|
55
60
|
|
|
56
|
-
export type AppAction =
|
|
57
|
-
| SearchAction
|
|
58
|
-
| NyrisAction
|
|
59
|
-
|
|
60
61
|
export interface CanvasWithId {
|
|
61
62
|
canvas: HTMLCanvasElement
|
|
62
63
|
id: string
|
|
@@ -85,3 +86,6 @@ export interface SearchServiceSettings {
|
|
|
85
86
|
useRecommendations: boolean
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
export interface AlgoliaResult {
|
|
90
|
+
sku: string
|
|
91
|
+
}
|