@rxdrag/website-lib-core 0.0.68 → 0.0.70
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/package.json +5 -5
- package/src/astro/media.ts +26 -13
- package/src/entify/Entify.ts +49 -16
- package/src/entify/IEntify.ts +12 -11
- package/src/entify/lib/fulltextSearch.ts +3 -2
- package/src/entify/lib/newQueryPostOptions.ts +3 -2
- package/src/entify/lib/newQueryProductOptions.ts +3 -3
- package/src/entify/lib/newQueryProductsMediaOptions.ts +2 -2
- package/src/entify/lib/queryEntityList.ts +2 -4
- package/src/entify/lib/queryFeaturedProducts.ts +3 -2
- package/src/entify/lib/queryLatestPosts.ts +3 -2
- package/src/entify/lib/queryOneEntity.ts +0 -4
- package/src/entify/lib/queryOneMedia.ts +5 -2
- package/src/entify/lib/queryOnePostBySlug.ts +3 -2
- package/src/entify/lib/queryOneProductBySlug.ts +3 -2
- package/src/entify/lib/queryPosts.ts +3 -2
- package/src/entify/lib/queryProducts.ts +3 -2
- package/src/entify/types/utils.ts +2 -6
- package/src/entify/view-model/funcs.ts +13 -35
- package/src/entify/view-model/models.ts +9 -24
- package/src/react/components/Medias/index.tsx +3 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.70",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
27
|
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
28
|
-
"@rxdrag/
|
|
29
|
-
"@rxdrag/
|
|
28
|
+
"@rxdrag/tsconfig": "0.2.0",
|
|
29
|
+
"@rxdrag/slate-preview": "1.2.58"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"clsx": "^2.1.0",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"lodash-es": "^4.17.21",
|
|
36
36
|
"react": "^19.1.0",
|
|
37
37
|
"react-dom": "^19.1.0",
|
|
38
|
-
"@rxdrag/entify-lib": "0.0.
|
|
39
|
-
"@rxdrag/rxcms-models": "0.3.
|
|
38
|
+
"@rxdrag/entify-lib": "0.0.21",
|
|
39
|
+
"@rxdrag/rxcms-models": "0.3.92"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"astro": "^4.0.0 || ^5.0.0"
|
package/src/astro/media.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ImageSizes, Media } from "@rxdrag/rxcms-models";
|
|
2
|
-
import { ImgHTMLAttributes } from "react";
|
|
3
2
|
|
|
4
3
|
export type FileFieldType =
|
|
5
4
|
| "thumbnail"
|
|
@@ -32,16 +31,34 @@ export const DEFAULT_LARGE: ImageResize = {
|
|
|
32
31
|
height: 1200,
|
|
33
32
|
};
|
|
34
33
|
|
|
34
|
+
export const DEFAULT_PRODUCT_IMAGE_SIZE: ImageResize = {
|
|
35
|
+
width: 800,
|
|
36
|
+
height: 800,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_PRODUCT_THUMBNAIL_IMAGE_SIZE: ImageResize = {
|
|
40
|
+
width: 600,
|
|
41
|
+
height: 400,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_POST_IMAGE_SIZE: ImageResize = {
|
|
45
|
+
width: 800,
|
|
46
|
+
height: 600,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const DEFAULT_POST_THUMBNAIL_IMAGE_SIZE: ImageResize = {
|
|
50
|
+
width: 600,
|
|
51
|
+
height: 400,
|
|
52
|
+
};
|
|
53
|
+
|
|
35
54
|
//TODO:以后还要加transform参数
|
|
36
|
-
export type ImageProps =
|
|
55
|
+
export type ImageProps = {
|
|
37
56
|
className?: string;
|
|
38
|
-
|
|
57
|
+
mediaRef?: string;
|
|
39
58
|
//默认original
|
|
40
59
|
fileField?: FileFieldType;
|
|
41
60
|
resize?: ImageResize;
|
|
42
61
|
children?: React.ReactNode;
|
|
43
|
-
//为导出代码方便,如果设置了src,显示的时候可以忽略mediaId等
|
|
44
|
-
src?: string;
|
|
45
62
|
};
|
|
46
63
|
|
|
47
64
|
export const transformMeidaFields = (
|
|
@@ -52,29 +69,25 @@ export const transformMeidaFields = (
|
|
|
52
69
|
const fields = ["original", "thumbnail"];
|
|
53
70
|
if (resize) {
|
|
54
71
|
fields.push(
|
|
55
|
-
`resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${
|
|
56
|
-
resize.height || DEFUALT_HEIGHT
|
|
72
|
+
`resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${resize.height || DEFUALT_HEIGHT
|
|
57
73
|
})`
|
|
58
74
|
);
|
|
59
75
|
}
|
|
60
76
|
if (field === "small") {
|
|
61
77
|
fields.push(
|
|
62
|
-
`small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${
|
|
63
|
-
images?.small?.height || DEFAULT_SAMLL.height
|
|
78
|
+
`small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${images?.small?.height || DEFAULT_SAMLL.height
|
|
64
79
|
})`
|
|
65
80
|
);
|
|
66
81
|
}
|
|
67
82
|
if (field === "medium") {
|
|
68
83
|
fields.push(
|
|
69
|
-
`medium(width: ${
|
|
70
|
-
images?.medium?.width || DEFAULT_MEDIUM.width
|
|
84
|
+
`medium(width: ${images?.medium?.width || DEFAULT_MEDIUM.width
|
|
71
85
|
}, height: ${images?.medium?.height || DEFAULT_MEDIUM.height})`
|
|
72
86
|
);
|
|
73
87
|
}
|
|
74
88
|
if (field === "large") {
|
|
75
89
|
fields.push(
|
|
76
|
-
`large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${
|
|
77
|
-
images?.large?.height || DEFAULT_LARGE.height
|
|
90
|
+
`large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${images?.large?.height || DEFAULT_LARGE.height
|
|
78
91
|
})`
|
|
79
92
|
);
|
|
80
93
|
}
|
package/src/entify/Entify.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvVariables
|
|
1
|
+
import { EnvVariables } from "./types";
|
|
2
2
|
import { queryOneTheme } from "./lib/queryOneTheme";
|
|
3
3
|
import {
|
|
4
4
|
ListConditions,
|
|
@@ -29,6 +29,7 @@ import { queryUserIds } from "./lib/queryUserIds";
|
|
|
29
29
|
import { IEntify, PostPatinateOptions, PostsOptions } from "./IEntify";
|
|
30
30
|
import { queryWebsite } from "./lib/queryWebsite";
|
|
31
31
|
import {
|
|
32
|
+
ImageSize,
|
|
32
33
|
ImageSizes,
|
|
33
34
|
Media,
|
|
34
35
|
Page,
|
|
@@ -40,26 +41,25 @@ import {
|
|
|
40
41
|
import { queryPageBySlug } from "./lib/queryPageBySlug";
|
|
41
42
|
import { queryPageByType } from "./lib/queryPageByType";
|
|
42
43
|
import { queryOneMedia } from "./lib/queryOneMedia";
|
|
44
|
+
import { DEFAULT_LARGE, DEFAULT_MEDIUM, DEFAULT_SAMLL, DEFUALT_HEIGHT, DEFUALT_WIDTH, FileFieldType, ImageResize } from "../astro/media";
|
|
43
45
|
|
|
44
46
|
export class Entify implements IEntify {
|
|
45
47
|
private static instance: Entify | null = null;
|
|
46
48
|
|
|
47
|
-
private constructor(protected envVariables: EnvVariables) { }
|
|
49
|
+
private constructor(protected envVariables: EnvVariables, protected imageSizes: ImageSizes) { }
|
|
48
50
|
|
|
49
|
-
public static getInstance(envVariables: EnvVariables): Entify {
|
|
51
|
+
public static getInstance(envVariables: EnvVariables, imageSizes: ImageSizes): Entify {
|
|
50
52
|
if (!Entify.instance) {
|
|
51
|
-
Entify.instance = new Entify(envVariables);
|
|
53
|
+
Entify.instance = new Entify(envVariables, imageSizes);
|
|
52
54
|
}
|
|
53
55
|
return Entify.instance;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
public setImageSizes(imageSizes: ImageSizes | undefined): void {
|
|
58
|
+
public setImageSizes(imageSizes: ImageSizes): void {
|
|
59
59
|
this.imageSizes = imageSizes;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public getImageSizes(): ImageSizes
|
|
62
|
+
public getImageSizes(): ImageSizes {
|
|
63
63
|
return this.imageSizes;
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -100,15 +100,33 @@ export class Entify implements IEntify {
|
|
|
100
100
|
return (await queryLangs(this.envVariables))?.items;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
public async getMedia(ref: string | undefined | null): Promise<Media | undefined> {
|
|
104
|
-
|
|
103
|
+
public async getMedia(ref: string | undefined | null, fileField?: FileFieldType, resize?: ImageResize): Promise<Media | undefined> {
|
|
104
|
+
const fields: string[] = []
|
|
105
|
+
switch (fileField) {
|
|
106
|
+
case "resize":
|
|
107
|
+
fields.push(`resize(width: ${resize?.width || DEFUALT_WIDTH}, height: ${resize?.height || DEFUALT_HEIGHT})`)
|
|
108
|
+
break;
|
|
109
|
+
case "small":
|
|
110
|
+
fields.push(`small(width: ${this.imageSizes.small?.width || DEFAULT_SAMLL.width}, height: ${this.imageSizes.small?.height || DEFAULT_SAMLL.height})`)
|
|
111
|
+
break;
|
|
112
|
+
case "medium":
|
|
113
|
+
fields.push(`medium(width: ${this.imageSizes.medium?.width || DEFAULT_MEDIUM.width}, height: ${this.imageSizes.medium?.height || DEFAULT_MEDIUM.height})`)
|
|
114
|
+
break;
|
|
115
|
+
case "large":
|
|
116
|
+
fields.push(`large(width: ${this.imageSizes.large?.width || DEFAULT_LARGE.width}, height: ${this.imageSizes.large?.height || DEFAULT_LARGE.height})`)
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
return await queryOneMedia(ref, fields, this.envVariables);
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
public async getFeaturedProducts(
|
|
108
123
|
count?: number,
|
|
109
|
-
imageSize?:
|
|
124
|
+
imageSize?: ImageSize,
|
|
110
125
|
addonFields?: (keyof Product)[]
|
|
111
126
|
) {
|
|
127
|
+
if (!imageSize) {
|
|
128
|
+
imageSize = this.imageSizes.productThumbnial;
|
|
129
|
+
}
|
|
112
130
|
return await queryFeaturedProducts(
|
|
113
131
|
count,
|
|
114
132
|
imageSize,
|
|
@@ -117,7 +135,10 @@ export class Entify implements IEntify {
|
|
|
117
135
|
);
|
|
118
136
|
}
|
|
119
137
|
|
|
120
|
-
public async getLatestPosts(count?: number, coverSize?:
|
|
138
|
+
public async getLatestPosts(count?: number, coverSize?: ImageSize) {
|
|
139
|
+
if (!coverSize) {
|
|
140
|
+
coverSize = this.imageSizes.postThumbnial;
|
|
141
|
+
}
|
|
121
142
|
return await queryLatestPosts(count, coverSize, this.envVariables);
|
|
122
143
|
}
|
|
123
144
|
|
|
@@ -198,7 +219,10 @@ export class Entify implements IEntify {
|
|
|
198
219
|
}));
|
|
199
220
|
}
|
|
200
221
|
|
|
201
|
-
public async getPostBySlug(slug: string, coverSize:
|
|
222
|
+
public async getPostBySlug(slug: string, coverSize: ImageSize | undefined) {
|
|
223
|
+
if (!coverSize) {
|
|
224
|
+
coverSize = this.imageSizes.post;
|
|
225
|
+
}
|
|
202
226
|
return await queryOnePostBySlug(slug, coverSize, this.envVariables);
|
|
203
227
|
}
|
|
204
228
|
|
|
@@ -223,9 +247,12 @@ export class Entify implements IEntify {
|
|
|
223
247
|
|
|
224
248
|
public async getProducts(
|
|
225
249
|
conditions: ListConditions,
|
|
226
|
-
imageSize:
|
|
250
|
+
imageSize: ImageSize | undefined,
|
|
227
251
|
addonFields?: (keyof Product)[]
|
|
228
252
|
) {
|
|
253
|
+
if (!imageSize) {
|
|
254
|
+
imageSize = this.imageSizes.productThumbnial;
|
|
255
|
+
}
|
|
229
256
|
return (
|
|
230
257
|
await queryProducts(conditions, imageSize, this.envVariables, addonFields)
|
|
231
258
|
)?.items;
|
|
@@ -372,7 +399,10 @@ export class Entify implements IEntify {
|
|
|
372
399
|
return paths;
|
|
373
400
|
}
|
|
374
401
|
|
|
375
|
-
public async getProductBySlug(slug: string, imageSize:
|
|
402
|
+
public async getProductBySlug(slug: string, imageSize: ImageSize | undefined) {
|
|
403
|
+
if (!imageSize) {
|
|
404
|
+
imageSize = this.imageSizes.product;
|
|
405
|
+
}
|
|
376
406
|
return await queryOneProductBySlug(slug, imageSize, this.envVariables);
|
|
377
407
|
}
|
|
378
408
|
|
|
@@ -418,7 +448,10 @@ export class Entify implements IEntify {
|
|
|
418
448
|
return (await queryUserPosts({ userId }, this.envVariables))?.items;
|
|
419
449
|
}
|
|
420
450
|
|
|
421
|
-
public async fulltextSearch(keyword: string, imageSize:
|
|
451
|
+
public async fulltextSearch(keyword: string, imageSize: ImageSize | undefined) {
|
|
452
|
+
if (!imageSize) {
|
|
453
|
+
imageSize = this.imageSizes.postThumbnial;
|
|
454
|
+
}
|
|
422
455
|
return await fulltextSearch(keyword, imageSize, this.envVariables);
|
|
423
456
|
}
|
|
424
457
|
|
package/src/entify/IEntify.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IQueryOptions, ListResult } from "@rxdrag/entify-lib";
|
|
2
|
-
import { TSize } from "./types";
|
|
3
2
|
import { ListConditions, UploadOptions, UploadSession } from "./lib";
|
|
4
3
|
import {
|
|
5
4
|
TPost,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
TUser,
|
|
10
9
|
} from "./view-model";
|
|
11
10
|
import {
|
|
11
|
+
ImageSize,
|
|
12
12
|
ImageSizes,
|
|
13
13
|
Lang,
|
|
14
14
|
Media,
|
|
@@ -21,10 +21,11 @@ import {
|
|
|
21
21
|
WebsitePart,
|
|
22
22
|
} from "@rxdrag/rxcms-models";
|
|
23
23
|
import { WebsitePartBoolExp } from "@rxdrag/rxcms-models/";
|
|
24
|
+
import { FileFieldType, ImageResize } from "../astro";
|
|
24
25
|
|
|
25
26
|
export type PostsOptions = {
|
|
26
27
|
category?: string;
|
|
27
|
-
coverSize?:
|
|
28
|
+
coverSize?: ImageSize | undefined;
|
|
28
29
|
page: number;
|
|
29
30
|
pageSize: number;
|
|
30
31
|
};
|
|
@@ -36,8 +37,8 @@ export type PostPatinateOptions = {
|
|
|
36
37
|
|
|
37
38
|
export interface IEntify {
|
|
38
39
|
//从配置文件注入到这里面,供组件使用
|
|
39
|
-
setImageSizes(imageSizes: ImageSizes
|
|
40
|
-
getImageSizes(): ImageSizes
|
|
40
|
+
setImageSizes(imageSizes: ImageSizes): void;
|
|
41
|
+
getImageSizes(): ImageSizes;
|
|
41
42
|
getLang(): string;
|
|
42
43
|
queryEntityList<
|
|
43
44
|
T,
|
|
@@ -58,17 +59,17 @@ export interface IEntify {
|
|
|
58
59
|
|
|
59
60
|
getLangs(): Promise<Lang[] | undefined>;
|
|
60
61
|
|
|
61
|
-
getMedia(ref: string | undefined | null): Promise<Media | undefined>;
|
|
62
|
+
getMedia(ref: string | undefined | null, fileField?: FileFieldType, resize?: ImageResize): Promise<Media | undefined>;
|
|
62
63
|
|
|
63
64
|
getFeaturedProducts(
|
|
64
65
|
count?: number,
|
|
65
|
-
imageSize?:
|
|
66
|
+
imageSize?: ImageSize,
|
|
66
67
|
addonFields?: (keyof Product)[]
|
|
67
68
|
): Promise<TProduct[] | undefined>;
|
|
68
69
|
|
|
69
70
|
getLatestPosts(
|
|
70
71
|
count?: number,
|
|
71
|
-
coverSize?:
|
|
72
|
+
coverSize?: ImageSize
|
|
72
73
|
): Promise<TPost[] | undefined>;
|
|
73
74
|
|
|
74
75
|
getPosts(options: PostsOptions): Promise<TPost[] | undefined>;
|
|
@@ -107,7 +108,7 @@ export interface IEntify {
|
|
|
107
108
|
|
|
108
109
|
getPostBySlug(
|
|
109
110
|
slug: string,
|
|
110
|
-
coverSize:
|
|
111
|
+
coverSize: ImageSize | undefined
|
|
111
112
|
): Promise<TPost | undefined>;
|
|
112
113
|
|
|
113
114
|
getPostSlugs(): Promise<Array<string | undefined>>;
|
|
@@ -118,7 +119,7 @@ export interface IEntify {
|
|
|
118
119
|
|
|
119
120
|
getProducts(
|
|
120
121
|
conditions: ListConditions,
|
|
121
|
-
imageSize:
|
|
122
|
+
imageSize: ImageSize | undefined,
|
|
122
123
|
addonFields?: (keyof Product)[]
|
|
123
124
|
): Promise<TProduct[] | undefined>;
|
|
124
125
|
|
|
@@ -133,7 +134,7 @@ export interface IEntify {
|
|
|
133
134
|
|
|
134
135
|
getProductBySlug(
|
|
135
136
|
slug: string,
|
|
136
|
-
imageSize:
|
|
137
|
+
imageSize: ImageSize | undefined
|
|
137
138
|
): Promise<TProduct | undefined>;
|
|
138
139
|
|
|
139
140
|
getProductPaths(): Promise<unknown>;
|
|
@@ -152,7 +153,7 @@ export interface IEntify {
|
|
|
152
153
|
|
|
153
154
|
fulltextSearch(
|
|
154
155
|
keyword: string,
|
|
155
|
-
imageSize:
|
|
156
|
+
imageSize: ImageSize | undefined
|
|
156
157
|
): Promise<ListResult<SearchIndex> | undefined>;
|
|
157
158
|
|
|
158
159
|
getUserPaths(): Promise<unknown>;
|
|
@@ -7,14 +7,15 @@ import {
|
|
|
7
7
|
SearchIndexQueryOptions,
|
|
8
8
|
SearchIndexFields,
|
|
9
9
|
MediaQueryOptions,
|
|
10
|
+
ImageSize,
|
|
10
11
|
} from "@rxdrag/rxcms-models";
|
|
11
12
|
import { queryEntityList } from "./queryEntityList";
|
|
12
13
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
13
|
-
import { EnvVariables
|
|
14
|
+
import { EnvVariables } from "../types";
|
|
14
15
|
|
|
15
16
|
export async function fulltextSearch(
|
|
16
17
|
keyword: string,
|
|
17
|
-
imageSize:
|
|
18
|
+
imageSize: ImageSize | undefined,
|
|
18
19
|
envVariables: EnvVariables
|
|
19
20
|
) {
|
|
20
21
|
|
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
UserFields,
|
|
6
6
|
MediaQueryOptions,
|
|
7
7
|
PostCategoryFields,
|
|
8
|
+
ImageSize,
|
|
8
9
|
} from "@rxdrag/rxcms-models";
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
import { newPageMetaOptions } from "./newPageMetaOptions";
|
|
11
12
|
|
|
12
13
|
//查询一个产品的参数,不带条件
|
|
13
|
-
export function newQueryOnePostOptions(coverSize?:
|
|
14
|
+
export function newQueryOnePostOptions(coverSize?: ImageSize) {
|
|
14
15
|
const coverFields = ["thumbnail", "url"];
|
|
15
16
|
if (coverSize?.width && coverSize?.height) {
|
|
16
17
|
coverFields.push(
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
AttachmentOnProductFields,
|
|
10
10
|
ProductCategoryFields,
|
|
11
11
|
ProductRelatedPivotQueryOptions,
|
|
12
|
+
ImageSize,
|
|
12
13
|
} from "@rxdrag/rxcms-models";
|
|
13
|
-
import { TSize } from "../types";
|
|
14
14
|
import { newPageMetaOptions } from "./newPageMetaOptions";
|
|
15
15
|
|
|
16
|
-
function creatProductMediaOptions(imagSize?:
|
|
16
|
+
function creatProductMediaOptions(imagSize?: ImageSize) {
|
|
17
17
|
const imageFields = ["thumbnail(width:400, height:320)", "url"];
|
|
18
18
|
if (imagSize?.width && imagSize?.height) {
|
|
19
19
|
imageFields.push(
|
|
@@ -39,7 +39,7 @@ function creatProductMediaOptions(imagSize?: TSize) {
|
|
|
39
39
|
).media(new MediaQueryOptions().description().file(imageFields));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function newQueryProductOptions(imagSize?:
|
|
42
|
+
export function newQueryProductOptions(imagSize?: ImageSize) {
|
|
43
43
|
return new ProductQueryOptions([
|
|
44
44
|
ProductFields.id,
|
|
45
45
|
ProductFields.title,
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
MediaOnProductQueryOptions,
|
|
3
3
|
MediaOnProductFields,
|
|
4
4
|
MediaQueryOptions,
|
|
5
|
+
ImageSize,
|
|
5
6
|
} from "@rxdrag/rxcms-models";
|
|
6
|
-
import { TSize } from "../types";
|
|
7
7
|
|
|
8
|
-
export function newQueryProductsMediaOptions(imageSize?:
|
|
8
|
+
export function newQueryProductsMediaOptions(imageSize?: ImageSize | undefined) {
|
|
9
9
|
return new MediaOnProductQueryOptions(
|
|
10
10
|
[MediaOnProductFields.seqValue, MediaOnProductFields.altText],
|
|
11
11
|
{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IQueryOptions, ListResult } from "@rxdrag/entify-lib";
|
|
2
2
|
import { createEntifyClient } from "./createEntifyClient";
|
|
3
3
|
import { EnvVariables } from "../types";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { Post, PostCategoryEntityName, PostEntityName, Product, ProductCategoryEntityName, ProductEntityName, UserEntityName } from "@rxdrag/rxcms-models";
|
|
5
|
+
import { postCategoriesToViewModel, postListToViewModel, productCategoriesToViewModel, productListToViewModel, userListToViewModel } from "../view-model";
|
|
6
6
|
|
|
7
7
|
export async function queryEntityList<T, WhereExp = unknown, OrderBy = unknown, DistinctExp = unknown>(
|
|
8
8
|
options: IQueryOptions<T, WhereExp, OrderBy, DistinctExp>,
|
|
@@ -37,8 +37,6 @@ export async function queryEntityList<T, WhereExp = unknown, OrderBy = unknown,
|
|
|
37
37
|
return postCategoriesToViewModel(result as ListResult<Post> | undefined);
|
|
38
38
|
case UserEntityName:
|
|
39
39
|
return userListToViewModel(result as ListResult<Post> | undefined);
|
|
40
|
-
case MediaEntityName:
|
|
41
|
-
return mediaListToViewModel(result as ListResult<Post> | undefined);
|
|
42
40
|
}
|
|
43
41
|
return result;
|
|
44
42
|
}
|
|
@@ -5,16 +5,17 @@ import {
|
|
|
5
5
|
ProductDistinctExp,
|
|
6
6
|
ProductFields,
|
|
7
7
|
ProductQueryOptions,
|
|
8
|
+
ImageSize,
|
|
8
9
|
} from "@rxdrag/rxcms-models";
|
|
9
10
|
import { queryEntityList } from "./queryEntityList";
|
|
10
11
|
import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
11
|
-
import { EnvVariables
|
|
12
|
+
import { EnvVariables } from "../types";
|
|
12
13
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
13
14
|
import { TProduct } from "../view-model";
|
|
14
15
|
|
|
15
16
|
export async function queryFeaturedProducts(
|
|
16
17
|
count: number = 8,
|
|
17
|
-
imageSize:
|
|
18
|
+
imageSize: ImageSize | undefined,
|
|
18
19
|
envVariables: EnvVariables,
|
|
19
20
|
addonFields?: (keyof Product)[]
|
|
20
21
|
) {
|
|
@@ -13,12 +13,13 @@ import {
|
|
|
13
13
|
PostCategoryFields,
|
|
14
14
|
} from "@rxdrag/rxcms-models";
|
|
15
15
|
import { queryEntityList } from "./queryEntityList";
|
|
16
|
-
import { EnvVariables
|
|
16
|
+
import { EnvVariables } from "../types";
|
|
17
17
|
import { TPost } from "../view-model";
|
|
18
|
+
import { ImageSize } from "@rxdrag/rxcms-models";
|
|
18
19
|
|
|
19
20
|
export async function queryLatestPosts(
|
|
20
21
|
count: number = 2,
|
|
21
|
-
coverSize:
|
|
22
|
+
coverSize: ImageSize | undefined,
|
|
22
23
|
envVariables: EnvVariables
|
|
23
24
|
) {
|
|
24
25
|
const result = await queryEntityList<
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IQueryOptions } from "@rxdrag/entify-lib";
|
|
2
2
|
import { createEntifyClient } from "./createEntifyClient";
|
|
3
3
|
import {
|
|
4
|
-
MediaEntityName,
|
|
5
4
|
PostCategoryEntityName,
|
|
6
5
|
PostEntityName,
|
|
7
6
|
ProductCategoryEntityName,
|
|
@@ -13,7 +12,6 @@ import {
|
|
|
13
12
|
import { WebsitePartBoolExp } from "@rxdrag/rxcms-models/";
|
|
14
13
|
import { EnvVariables } from "../types";
|
|
15
14
|
import {
|
|
16
|
-
mediaToViewModel,
|
|
17
15
|
postCategoryToViewModel,
|
|
18
16
|
postToViewModel,
|
|
19
17
|
productCategoryToViewModel,
|
|
@@ -57,8 +55,6 @@ export async function queryOneEntity<
|
|
|
57
55
|
return postCategoryToViewModel(result) as T | undefined;
|
|
58
56
|
case UserEntityName:
|
|
59
57
|
return userToViewModel(result) as T | undefined;
|
|
60
|
-
case MediaEntityName:
|
|
61
|
-
return mediaToViewModel(result) as T | undefined;
|
|
62
58
|
case WebsiteSettingsEntityName:
|
|
63
59
|
return websiteSettingsToViewModel(result) as T | undefined;
|
|
64
60
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Media, MediaBoolExp, MediaDistinctExp, MediaFields, MediaOrderBy, MediaQueryOptions } from "@rxdrag/rxcms-models";
|
|
2
2
|
import { EnvVariables } from "../types";
|
|
3
3
|
import { queryOneEntity } from "./queryOneEntity";
|
|
4
|
+
export const queryOneMedia = async (
|
|
5
|
+
ref: string | undefined | null,
|
|
6
|
+
fields: string[] | undefined,
|
|
7
|
+
envVariables: EnvVariables) => {
|
|
4
8
|
|
|
5
|
-
export const queryOneMedia = async (ref: string | undefined | null, envVariables: EnvVariables) => {
|
|
6
9
|
const media = await queryOneEntity<Media, MediaBoolExp, MediaOrderBy, MediaDistinctExp>(
|
|
7
10
|
new MediaQueryOptions([
|
|
8
11
|
MediaFields.id,
|
|
@@ -16,7 +19,7 @@ export const queryOneMedia = async (ref: string | undefined | null, envVariables
|
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
})
|
|
19
|
-
.file(["original", "thumbnail"])
|
|
22
|
+
.file(["original", "thumbnail", ...(fields || [])])
|
|
20
23
|
.setNoQuery(!ref)
|
|
21
24
|
,
|
|
22
25
|
envVariables
|
|
@@ -6,12 +6,13 @@ import {
|
|
|
6
6
|
} from "@rxdrag/rxcms-models";
|
|
7
7
|
import { newQueryOnePostOptions } from "./newQueryPostOptions";
|
|
8
8
|
import { queryOneEntity } from "./queryOneEntity";
|
|
9
|
-
import { EnvVariables
|
|
9
|
+
import { EnvVariables } from "../types";
|
|
10
10
|
import { TPost } from "../view-model";
|
|
11
|
+
import { ImageSize } from "@rxdrag/rxcms-models";
|
|
11
12
|
|
|
12
13
|
export async function queryOnePostBySlug(
|
|
13
14
|
slug: string,
|
|
14
|
-
coverSize:
|
|
15
|
+
coverSize: ImageSize | undefined,
|
|
15
16
|
envVariables: EnvVariables
|
|
16
17
|
) {
|
|
17
18
|
const post = await queryOneEntity<
|
|
@@ -6,12 +6,13 @@ import {
|
|
|
6
6
|
} from "@rxdrag/rxcms-models";
|
|
7
7
|
import { newQueryProductOptions } from "./newQueryProductOptions";
|
|
8
8
|
import { queryOneEntity } from "./queryOneEntity";
|
|
9
|
-
import { EnvVariables
|
|
9
|
+
import { EnvVariables } from "../types";
|
|
10
10
|
import { productToViewModel, TProduct } from "../view-model";
|
|
11
|
+
import { ImageSize } from "@rxdrag/rxcms-models";
|
|
11
12
|
|
|
12
13
|
export async function queryOneProductBySlug(
|
|
13
14
|
slug: string,
|
|
14
|
-
imageSize:
|
|
15
|
+
imageSize: ImageSize | undefined,
|
|
15
16
|
envVariables: EnvVariables
|
|
16
17
|
) {
|
|
17
18
|
const product = await queryOneEntity<
|
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
UserQueryOptions,
|
|
12
12
|
UserFields,
|
|
13
13
|
ProductOrderBy,
|
|
14
|
+
ImageSize,
|
|
14
15
|
} from "@rxdrag/rxcms-models";
|
|
15
16
|
import { queryEntityList } from "./queryEntityList";
|
|
16
17
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
17
|
-
import { EnvVariables
|
|
18
|
+
import { EnvVariables } from "../types";
|
|
18
19
|
import { TPost } from "../view-model";
|
|
19
20
|
|
|
20
21
|
export interface ListConditions {
|
|
@@ -26,7 +27,7 @@ export interface ListConditions {
|
|
|
26
27
|
|
|
27
28
|
export async function queryPosts(
|
|
28
29
|
conditions: ListConditions,
|
|
29
|
-
coverSize:
|
|
30
|
+
coverSize: ImageSize | undefined,
|
|
30
31
|
envVariables: EnvVariables,
|
|
31
32
|
selectFields?: (keyof Post)[]
|
|
32
33
|
) {
|
|
@@ -12,12 +12,13 @@ import { ListConditions } from "./queryPosts";
|
|
|
12
12
|
import { queryEntityList } from "./queryEntityList";
|
|
13
13
|
import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
14
14
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
15
|
-
import { EnvVariables
|
|
15
|
+
import { EnvVariables } from "../types";
|
|
16
16
|
import { TProduct } from "../view-model";
|
|
17
|
+
import { ImageSize } from "@rxdrag/rxcms-models";
|
|
17
18
|
|
|
18
19
|
export async function queryProducts(
|
|
19
20
|
conditions: ListConditions,
|
|
20
|
-
imageSize:
|
|
21
|
+
imageSize: ImageSize | undefined,
|
|
21
22
|
envVariables: EnvVariables,
|
|
22
23
|
addonFields?: (keyof Product)[]
|
|
23
24
|
) {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import { ImageSizes } from "@rxdrag/rxcms-models";
|
|
1
2
|
import { EnvVariables } from "./variables";
|
|
2
|
-
|
|
3
|
-
export type TSize = {
|
|
4
|
-
width: number
|
|
5
|
-
height: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
3
|
//astro传递上下文用
|
|
9
4
|
export type Locals = {
|
|
10
5
|
env: EnvVariables;
|
|
6
|
+
imageSizes: ImageSizes;
|
|
11
7
|
};
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
WebsiteSettings,
|
|
10
10
|
} from "@rxdrag/rxcms-models";
|
|
11
11
|
import {
|
|
12
|
-
TMedia,
|
|
13
12
|
TMedias,
|
|
14
13
|
TPost,
|
|
15
14
|
TPostCategory,
|
|
@@ -20,15 +19,6 @@ import {
|
|
|
20
19
|
} from "./models";
|
|
21
20
|
import { ListResult } from "@rxdrag/entify-lib";
|
|
22
21
|
|
|
23
|
-
export function mediaToViewModel(media?: Media): TMedia | undefined {
|
|
24
|
-
if (!media) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
...media,
|
|
29
|
-
...media?.file,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
22
|
|
|
33
23
|
export function mediasToViewModel(product?: Product): TMedias | undefined {
|
|
34
24
|
if (!product) {
|
|
@@ -40,7 +30,7 @@ export function mediasToViewModel(product?: Product): TMedias | undefined {
|
|
|
40
30
|
return {
|
|
41
31
|
alt: mediaOnProduct.altText,
|
|
42
32
|
seqValue: mediaOnProduct.seqValue,
|
|
43
|
-
...
|
|
33
|
+
...mediaOnProduct.media!,
|
|
44
34
|
};
|
|
45
35
|
}),
|
|
46
36
|
};
|
|
@@ -48,14 +38,14 @@ export function mediasToViewModel(product?: Product): TMedias | undefined {
|
|
|
48
38
|
|
|
49
39
|
export function attachmentsToViewModel(
|
|
50
40
|
attachments?: AttachmentOnProduct[]
|
|
51
|
-
):
|
|
41
|
+
): Media[] | undefined {
|
|
52
42
|
if (!attachments) {
|
|
53
43
|
return undefined;
|
|
54
44
|
}
|
|
55
45
|
return attachments?.map((attachPovit) => {
|
|
56
46
|
return {
|
|
57
47
|
seqValue: attachPovit.seqValue,
|
|
58
|
-
...
|
|
48
|
+
...attachPovit.attachment!,
|
|
59
49
|
};
|
|
60
50
|
});
|
|
61
51
|
}
|
|
@@ -79,19 +69,19 @@ export function productCategoryToViewModel(
|
|
|
79
69
|
}
|
|
80
70
|
return {
|
|
81
71
|
...productCategory,
|
|
82
|
-
media: productCategory?.media
|
|
72
|
+
media: productCategory?.media,
|
|
83
73
|
children: productCategory?.children?.length
|
|
84
74
|
? (productCategory?.children?.map(productCategoryToViewModel) as
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
| TProductCategory[]
|
|
76
|
+
| undefined)
|
|
87
77
|
: undefined,
|
|
88
78
|
parent:
|
|
89
79
|
productCategory?.parent &&
|
|
90
80
|
productCategoryToViewModel(productCategory?.parent),
|
|
91
81
|
products: productCategory?.products?.length
|
|
92
82
|
? (productCategory?.products?.map(productToViewModel) as
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
| TProduct[]
|
|
84
|
+
| undefined)
|
|
95
85
|
: undefined,
|
|
96
86
|
};
|
|
97
87
|
}
|
|
@@ -152,11 +142,11 @@ export function postCategoryToViewModel(
|
|
|
152
142
|
}
|
|
153
143
|
return {
|
|
154
144
|
...postCategory,
|
|
155
|
-
media: postCategory?.media
|
|
145
|
+
media: postCategory?.media,
|
|
156
146
|
children: postCategory?.children?.length
|
|
157
147
|
? (postCategory?.children?.map(postCategoryToViewModel) as
|
|
158
|
-
|
|
159
|
-
|
|
148
|
+
| TPostCategory[]
|
|
149
|
+
| undefined)
|
|
160
150
|
: undefined,
|
|
161
151
|
parent:
|
|
162
152
|
postCategory?.parent && postCategoryToViewModel(postCategory?.parent),
|
|
@@ -190,7 +180,7 @@ export function postToViewModel(post?: Post): TPost | undefined {
|
|
|
190
180
|
content: post?.content,
|
|
191
181
|
meta: post?.meta,
|
|
192
182
|
category: post?.category && postCategoryToViewModel(post?.category),
|
|
193
|
-
cover: post?.cover
|
|
183
|
+
cover: post?.cover,
|
|
194
184
|
};
|
|
195
185
|
}
|
|
196
186
|
|
|
@@ -226,7 +216,7 @@ export function userToViewModel(user?: User): TUser | undefined {
|
|
|
226
216
|
}
|
|
227
217
|
return {
|
|
228
218
|
...user,
|
|
229
|
-
avatar: user?.avatar
|
|
219
|
+
avatar: user?.avatar,
|
|
230
220
|
};
|
|
231
221
|
}
|
|
232
222
|
|
|
@@ -241,15 +231,3 @@ export function userListToViewModel(
|
|
|
241
231
|
items: users?.items?.map(userToViewModel) as TUser[] | undefined,
|
|
242
232
|
};
|
|
243
233
|
}
|
|
244
|
-
|
|
245
|
-
export function mediaListToViewModel(
|
|
246
|
-
medias?: ListResult<Media>
|
|
247
|
-
): ListResult<TMedia> | undefined {
|
|
248
|
-
if (!medias) {
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
...medias,
|
|
253
|
-
items: medias?.items?.map(mediaToViewModel) as TMedia[] | undefined,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Media, PageMeta } from "@rxdrag/rxcms-models";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* 定义数据绑定用的类型,需要从@rxdrag/rxcms-models的类型进行转换
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export type TMedia = {
|
|
8
|
-
id?: string | null;
|
|
9
|
-
name?: string;
|
|
10
|
-
mimeType?: string;
|
|
11
|
-
extName?: string;
|
|
12
|
-
thumbnail?: string;
|
|
13
|
-
resize?: string;
|
|
14
|
-
url?: string;
|
|
3
|
+
export type TMedia = Media & {
|
|
15
4
|
alt?: string;
|
|
16
|
-
|
|
17
|
-
updatedAt?: Date;
|
|
18
|
-
mediaType?: MediaType;
|
|
19
|
-
};
|
|
5
|
+
}
|
|
20
6
|
|
|
21
7
|
export type TMedias = {
|
|
22
8
|
externalVideoUrl?: string;
|
|
@@ -43,7 +29,7 @@ export type TProduct = {
|
|
|
43
29
|
features?: string;
|
|
44
30
|
medias?: TMedias;
|
|
45
31
|
//从头medias中获取第一个不是视频的图片
|
|
46
|
-
cover?:
|
|
32
|
+
cover?: Media;
|
|
47
33
|
content?: string;
|
|
48
34
|
content2?: string;
|
|
49
35
|
content3?: string;
|
|
@@ -53,7 +39,7 @@ export type TProduct = {
|
|
|
53
39
|
updatedAt?: Date;
|
|
54
40
|
category?: TProductCategory;
|
|
55
41
|
related?: TProduct[];
|
|
56
|
-
attachments?:
|
|
42
|
+
attachments?: Media[];
|
|
57
43
|
meta?: PageMeta;
|
|
58
44
|
};
|
|
59
45
|
|
|
@@ -62,7 +48,7 @@ export type TPostCategory = {
|
|
|
62
48
|
slug?: string;
|
|
63
49
|
name?: string;
|
|
64
50
|
children?: TProductCategory[];
|
|
65
|
-
media?:
|
|
51
|
+
media?: Media;
|
|
66
52
|
parent?: TProductCategory;
|
|
67
53
|
posts?: TPost[];
|
|
68
54
|
};
|
|
@@ -70,7 +56,7 @@ export type TPostCategory = {
|
|
|
70
56
|
export type TUser = {
|
|
71
57
|
id?: string | null;
|
|
72
58
|
name?: string;
|
|
73
|
-
avatar?:
|
|
59
|
+
avatar?: Media;
|
|
74
60
|
position?: string;
|
|
75
61
|
profile?: string;
|
|
76
62
|
email?: string;
|
|
@@ -87,7 +73,7 @@ export type TPost = {
|
|
|
87
73
|
slug?: string;
|
|
88
74
|
title?: string;
|
|
89
75
|
description?: string;
|
|
90
|
-
cover?:
|
|
76
|
+
cover?: Media;
|
|
91
77
|
content?: string;
|
|
92
78
|
extends?: object;
|
|
93
79
|
publishedAt?: Date;
|
|
@@ -101,7 +87,7 @@ export type TPost = {
|
|
|
101
87
|
export type TWebsiteSettings = {
|
|
102
88
|
id?: string | null;
|
|
103
89
|
contact?: string;
|
|
104
|
-
contactAvatar?:
|
|
90
|
+
contactAvatar?: Media;
|
|
105
91
|
address?: string;
|
|
106
92
|
email?: string;
|
|
107
93
|
tel?: string;
|
|
@@ -131,6 +117,5 @@ export const entityMaps: Record<string, string> = {
|
|
|
131
117
|
Post: "TPost",
|
|
132
118
|
PostCategory: "TPostCategory",
|
|
133
119
|
User: "TUser",
|
|
134
|
-
Media: "TMedia",
|
|
135
120
|
WebsiteSettings: "TWebsiteSettings",
|
|
136
121
|
};
|
|
@@ -61,9 +61,7 @@ export const Medias = forwardRef<HTMLDivElement, MediasProps>((props, ref) => {
|
|
|
61
61
|
: value.externalVideoUrl.split("v=")[1]?.split("&")[0];
|
|
62
62
|
|
|
63
63
|
if (videoId) {
|
|
64
|
-
setThumbnailUrl(
|
|
65
|
-
`https://img.youtube.com/vi/${videoId}/default.jpg`
|
|
66
|
-
);
|
|
64
|
+
setThumbnailUrl(`https://img.youtube.com/vi/${videoId}/default.jpg`);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
}, [value?.externalVideoUrl]);
|
|
@@ -211,7 +209,7 @@ export const Medias = forwardRef<HTMLDivElement, MediasProps>((props, ref) => {
|
|
|
211
209
|
)}
|
|
212
210
|
>
|
|
213
211
|
<img
|
|
214
|
-
src={media?.resize || media?.url}
|
|
212
|
+
src={media?.file?.resize || media?.file?.url}
|
|
215
213
|
alt={media?.alt}
|
|
216
214
|
className="w-full h-full object-cover object-center"
|
|
217
215
|
/>
|
|
@@ -310,7 +308,7 @@ export const Medias = forwardRef<HTMLDivElement, MediasProps>((props, ref) => {
|
|
|
310
308
|
onClick={() => setSelectedId(media.id)}
|
|
311
309
|
>
|
|
312
310
|
<img
|
|
313
|
-
src={media?.resize || media?.url}
|
|
311
|
+
src={media?.file?.resize || media?.file?.url}
|
|
314
312
|
alt={media?.alt}
|
|
315
313
|
className="w-full h-full object-cover"
|
|
316
314
|
/>
|