@rxdrag/website-lib-core 0.0.11 → 0.0.13
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 +4 -4
- package/src/component-logic/modal.ts +11 -2
- package/src/controller/OpenableController.ts +5 -0
- package/src/controller/PageLoader.ts +1 -1
- package/src/entify/Entify.ts +56 -0
- package/src/entify/IEntify.ts +43 -3
- package/src/entify/lib/langFields.ts +2 -0
- package/src/entify/lib/newPageMetaOptions.ts +4 -6
- package/src/entify/lib/newQueryPageOptions.ts +14 -0
- package/src/entify/lib/queryAllProducts.ts +5 -0
- package/src/entify/lib/queryFeaturedProducts.ts +5 -0
- package/src/entify/lib/queryLangs.ts +8 -21
- package/src/entify/lib/queryLatestPosts.ts +6 -1
- package/src/entify/lib/queryOnePostBySlug.ts +27 -10
- package/src/entify/lib/queryOnePostCategoryBySlug.ts +5 -0
- package/src/entify/lib/queryOneProductBySlug.ts +13 -3
- package/src/entify/lib/queryOneProductCategoryBySlug.ts +24 -5
- package/src/entify/lib/queryOneTheme.ts +2 -1
- package/src/entify/lib/queryPageBySlug.ts +43 -0
- package/src/entify/lib/queryPageByType.ts +44 -0
- package/src/entify/lib/queryPostCategories.ts +7 -0
- package/src/entify/lib/queryPostSlugs.ts +5 -0
- package/src/entify/lib/queryPosts.ts +56 -39
- package/src/entify/lib/queryProductCategories.ts +7 -0
- package/src/entify/lib/queryProducts.ts +5 -0
- package/src/entify/lib/queryProductsInMenu.ts +14 -12
- package/src/entify/lib/queryUserPosts.ts +5 -0
- package/src/entify/lib/queryWebSiteSettings.ts +2 -3
- package/src/entify/lib/queryWebsite.ts +43 -0
- package/src/entify/lib/searchProducts.ts +7 -0
- package/src/entify/view-model/models.ts +0 -8
- package/src/react/components/ContactForm/index.tsx +6 -29
- package/src/react/components/Medias/index.tsx +270 -273
- package/src/react/components/ProductCard/ProductCta/index.tsx +1 -1
- package/src/react/components/RichTextOutline/index.tsx +4 -5
- package/src/react/components/RichTextOutline/useAcitviedHeading.ts +81 -54
|
@@ -1,32 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Post,
|
|
3
|
+
PostBoolExp,
|
|
4
|
+
PostOrderBy,
|
|
5
|
+
PostDistinctExp,
|
|
6
|
+
PostFields,
|
|
7
|
+
PublishableStatus,
|
|
8
|
+
PostAssciations,
|
|
9
|
+
PostQueryOptions,
|
|
10
|
+
MediaQueryOptions,
|
|
11
|
+
UserQueryOptions,
|
|
12
|
+
UserFields,
|
|
13
|
+
} from "@rxdrag/rxcms-models";
|
|
2
14
|
import { queryEntityList } from "./queryEntityList";
|
|
3
15
|
import { ListResult } from "@rxdrag/entify-hooks";
|
|
4
16
|
import { EnvVariables, TSize } from "../types";
|
|
5
17
|
import { TPost } from "../view-model";
|
|
6
18
|
|
|
7
19
|
export interface ListConditions {
|
|
8
|
-
category?: string
|
|
20
|
+
category?: string; //category slug
|
|
9
21
|
page?: number;
|
|
10
22
|
pageSize: number;
|
|
11
23
|
}
|
|
12
24
|
|
|
13
25
|
export async function queryPosts(
|
|
14
|
-
conditions: ListConditions,
|
|
15
|
-
coverSize: TSize | undefined,
|
|
26
|
+
conditions: ListConditions,
|
|
27
|
+
coverSize: TSize | undefined,
|
|
16
28
|
envVariables: EnvVariables,
|
|
17
29
|
selectFields?: (keyof Post)[]
|
|
18
30
|
) {
|
|
19
31
|
const { category: categorySlug, page = 1, pageSize } = conditions;
|
|
20
32
|
|
|
21
|
-
let where = {}
|
|
33
|
+
let where = {};
|
|
22
34
|
if (categorySlug) {
|
|
23
35
|
where = {
|
|
24
36
|
[PostAssciations.category]: {
|
|
25
37
|
slug: {
|
|
26
|
-
|
|
27
|
-
}
|
|
38
|
+
_eq: categorySlug,
|
|
39
|
+
},
|
|
28
40
|
},
|
|
29
|
-
}
|
|
41
|
+
};
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
// 默认查询字段
|
|
@@ -44,49 +56,54 @@ export async function queryPosts(
|
|
|
44
56
|
// 使用指定的字段或默认字段
|
|
45
57
|
const fields = selectFields || defaultFields;
|
|
46
58
|
|
|
47
|
-
const queryOptions = new PostQueryOptions(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
const queryOptions = new PostQueryOptions(fields, {
|
|
60
|
+
offset: (page - 1) * pageSize,
|
|
61
|
+
limit: pageSize,
|
|
62
|
+
where: {
|
|
63
|
+
[PostFields.status]: {
|
|
64
|
+
_eq: PublishableStatus.published,
|
|
65
|
+
},
|
|
66
|
+
lang: {
|
|
67
|
+
abbr: {
|
|
68
|
+
_eq: envVariables.language,
|
|
55
69
|
},
|
|
56
|
-
...where,
|
|
57
70
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
...where,
|
|
72
|
+
},
|
|
73
|
+
orderBy: [
|
|
74
|
+
{
|
|
75
|
+
[PostFields.createdAt]: "desc",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
65
79
|
|
|
66
80
|
// 只有在需要查询封面图时才添加封面图查询
|
|
67
|
-
if (!selectFields || selectFields.includes(
|
|
81
|
+
if (!selectFields || selectFields.includes("cover" as keyof Post)) {
|
|
68
82
|
queryOptions.cover(
|
|
69
|
-
new MediaQueryOptions().file(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
83
|
+
new MediaQueryOptions().file([
|
|
84
|
+
"thumbnail",
|
|
85
|
+
coverSize
|
|
86
|
+
? `resize(width:${coverSize.width}, height:${coverSize.height})`
|
|
87
|
+
: "resize(width:480, height:180)",
|
|
88
|
+
])
|
|
75
89
|
);
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
// 只有在需要查询作者时才添加作者查询
|
|
79
|
-
if (!selectFields || selectFields.includes(
|
|
93
|
+
if (!selectFields || selectFields.includes("author" as keyof Post)) {
|
|
80
94
|
queryOptions.author(
|
|
81
|
-
new UserQueryOptions([UserFields.id, UserFields.name])
|
|
82
|
-
|
|
95
|
+
new UserQueryOptions([UserFields.id, UserFields.name]).avatar(
|
|
96
|
+
new MediaQueryOptions().file(["thumbnail"])
|
|
97
|
+
)
|
|
83
98
|
);
|
|
84
99
|
}
|
|
85
100
|
|
|
86
|
-
const result = await queryEntityList<
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
const result = await queryEntityList<
|
|
102
|
+
Post,
|
|
103
|
+
PostBoolExp,
|
|
104
|
+
PostOrderBy,
|
|
105
|
+
PostDistinctExp
|
|
106
|
+
>(queryOptions, envVariables);
|
|
107
|
+
|
|
91
108
|
return result as ListResult<TPost> | undefined;
|
|
92
109
|
}
|
|
@@ -15,6 +15,13 @@ export async function queryProductCategories(envVariables: EnvVariables) {
|
|
|
15
15
|
ProductCategoryFields.description,
|
|
16
16
|
],
|
|
17
17
|
{
|
|
18
|
+
where: {
|
|
19
|
+
lang: {
|
|
20
|
+
abbr: {
|
|
21
|
+
_eq: envVariables.language,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
18
25
|
orderBy: [
|
|
19
26
|
{ [ProductCategoryFields.seqValue]: "asc" }
|
|
20
27
|
]
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ProductFields,
|
|
3
|
+
ProductQueryOptions,
|
|
4
|
+
PublishableStatus,
|
|
5
|
+
} from "@rxdrag/rxcms-models";
|
|
2
6
|
import { queryEntityList } from "./queryEntityList";
|
|
3
7
|
import { EnvVariables } from "../types";
|
|
4
8
|
import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
@@ -6,25 +10,23 @@ import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
|
6
10
|
export async function queryProductsInMenu(envVariables: EnvVariables) {
|
|
7
11
|
const result = await queryEntityList(
|
|
8
12
|
new ProductQueryOptions(
|
|
9
|
-
[
|
|
10
|
-
ProductFields.id,
|
|
11
|
-
ProductFields.slug,
|
|
12
|
-
ProductFields.title,
|
|
13
|
-
],
|
|
13
|
+
[ProductFields.id, ProductFields.slug, ProductFields.title],
|
|
14
14
|
{
|
|
15
15
|
where: {
|
|
16
|
+
lang: {
|
|
17
|
+
abbr: {
|
|
18
|
+
_eq: envVariables.language,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
16
21
|
showInNavMenu: {
|
|
17
|
-
|
|
22
|
+
_eq: true,
|
|
18
23
|
},
|
|
19
24
|
[ProductFields.status]: {
|
|
20
|
-
|
|
25
|
+
_eq: PublishableStatus.published,
|
|
21
26
|
},
|
|
22
27
|
},
|
|
23
28
|
}
|
|
24
|
-
)
|
|
25
|
-
.mediaPivots(
|
|
26
|
-
newQueryProductsMediaOptions()
|
|
27
|
-
),
|
|
29
|
+
).mediaPivots(newQueryProductsMediaOptions()),
|
|
28
30
|
envVariables
|
|
29
31
|
);
|
|
30
32
|
return result;
|
|
@@ -17,11 +17,10 @@ export async function queryWebSiteSettings(envVariables: EnvVariables) {
|
|
|
17
17
|
WebsiteSettingsDistinctExp
|
|
18
18
|
>(
|
|
19
19
|
new WebsiteSettingsQueryOptions([
|
|
20
|
-
WebsiteSettingsFields.footerCode,
|
|
21
|
-
WebsiteSettingsFields.headerCode,
|
|
22
|
-
WebsiteSettingsFields.gaTrackingId,
|
|
23
20
|
WebsiteSettingsFields.noticeEmail,
|
|
24
21
|
WebsiteSettingsFields.smtpConfig,
|
|
22
|
+
WebsiteSettingsFields.replyToEmail,
|
|
23
|
+
WebsiteSettingsFields.useCustomizedSmtp,
|
|
25
24
|
]),
|
|
26
25
|
envVariables
|
|
27
26
|
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Website,
|
|
3
|
+
WebsiteBoolExp,
|
|
4
|
+
WebsiteOrderBy,
|
|
5
|
+
WebsiteDistinctExp,
|
|
6
|
+
WebsiteQueryOptions,
|
|
7
|
+
WebsiteFields,
|
|
8
|
+
LangFields,
|
|
9
|
+
} from "@rxdrag/rxcms-models";
|
|
10
|
+
import { queryOneEntity } from "./queryOneEntity";
|
|
11
|
+
import { EnvVariables } from "../types";
|
|
12
|
+
|
|
13
|
+
export async function queryWebsite(envVariables: EnvVariables) {
|
|
14
|
+
const website = await queryOneEntity<
|
|
15
|
+
Website,
|
|
16
|
+
WebsiteBoolExp,
|
|
17
|
+
WebsiteOrderBy,
|
|
18
|
+
WebsiteDistinctExp
|
|
19
|
+
>(
|
|
20
|
+
new WebsiteQueryOptions(
|
|
21
|
+
[WebsiteFields.id, WebsiteFields.name, WebsiteFields.title],
|
|
22
|
+
{
|
|
23
|
+
where: {
|
|
24
|
+
id: {
|
|
25
|
+
_eq: envVariables.websiteId,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
.baseLang([
|
|
31
|
+
LangFields.id,
|
|
32
|
+
LangFields.abbr,
|
|
33
|
+
LangFields.localName,
|
|
34
|
+
LangFields.cnName,
|
|
35
|
+
LangFields.urlFragment,
|
|
36
|
+
LangFields.htmlLang,
|
|
37
|
+
])
|
|
38
|
+
.setNoQuery(!envVariables.websiteId),
|
|
39
|
+
{ ...envVariables, websiteId: undefined }
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return website as Website | undefined;
|
|
43
|
+
}
|
|
@@ -110,9 +110,7 @@ export type TWebsiteSettings = {
|
|
|
110
110
|
facebook?: string;
|
|
111
111
|
twitter?: string;
|
|
112
112
|
instagram?: string;
|
|
113
|
-
footerCode?: string;
|
|
114
113
|
websiteName?: string;
|
|
115
|
-
map301?: string;
|
|
116
114
|
};
|
|
117
115
|
|
|
118
116
|
export type TBreadcrumbItem = {
|
|
@@ -120,11 +118,6 @@ export type TBreadcrumbItem = {
|
|
|
120
118
|
href?: string;
|
|
121
119
|
};
|
|
122
120
|
|
|
123
|
-
export type TPage = {
|
|
124
|
-
title?: string;
|
|
125
|
-
breadcrumbs?: TBreadcrumbItem[];
|
|
126
|
-
};
|
|
127
|
-
|
|
128
121
|
export type TPagination = {
|
|
129
122
|
urlPrefix?: string;
|
|
130
123
|
current?: number;
|
|
@@ -138,6 +131,5 @@ export const entityMaps: Record<string, string> = {
|
|
|
138
131
|
PostCategory: "TPostCategory",
|
|
139
132
|
User: "TUser",
|
|
140
133
|
Media: "TMedia",
|
|
141
|
-
Page: "TPage",
|
|
142
134
|
WebsiteSettings: "TWebsiteSettings",
|
|
143
135
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { forwardRef,
|
|
1
|
+
import { forwardRef, useState } from "react";
|
|
2
2
|
import { Input } from "./Input";
|
|
3
3
|
import { Submit } from "./Submit";
|
|
4
4
|
import { Textarea } from "./Textarea";
|
|
5
|
-
import { DATA_POPUP_CTA } from "../../../controller/consts";
|
|
6
5
|
import clsx from "clsx";
|
|
7
|
-
import {
|
|
6
|
+
import { modal } from "../../../controller";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* 简单的加密函数,用于生成防机器人的加密字段
|
|
@@ -91,7 +90,7 @@ interface FormErrors {
|
|
|
91
90
|
export type ContactFormProps = {
|
|
92
91
|
submitAlign?: "left" | "center" | "right";
|
|
93
92
|
actionUrl?: string;
|
|
94
|
-
|
|
93
|
+
formSalt: string;
|
|
95
94
|
labels?: {
|
|
96
95
|
name?: string;
|
|
97
96
|
email?: string;
|
|
@@ -106,7 +105,7 @@ export const ContactForm = forwardRef<HTMLDivElement, ContactFormProps>(
|
|
|
106
105
|
const {
|
|
107
106
|
submitAlign = "right",
|
|
108
107
|
actionUrl = "/api/ask-for-quote",
|
|
109
|
-
|
|
108
|
+
formSalt,
|
|
110
109
|
labels = {},
|
|
111
110
|
} = props;
|
|
112
111
|
const [formData, setFormData] = useState<QuoteRequest>({
|
|
@@ -114,7 +113,6 @@ export const ContactForm = forwardRef<HTMLDivElement, ContactFormProps>(
|
|
|
114
113
|
email: "",
|
|
115
114
|
company: "",
|
|
116
115
|
message: "",
|
|
117
|
-
fromCta: "",
|
|
118
116
|
phone: "", // 初始化蜜罐字段
|
|
119
117
|
});
|
|
120
118
|
// 错误状态
|
|
@@ -124,26 +122,6 @@ export const ContactForm = forwardRef<HTMLDivElement, ContactFormProps>(
|
|
|
124
122
|
success?: boolean;
|
|
125
123
|
message?: string;
|
|
126
124
|
}>({});
|
|
127
|
-
//最近被点击过的cta
|
|
128
|
-
|
|
129
|
-
useEffect(() => {
|
|
130
|
-
const unsub = popover.onOpenAll((event) => {
|
|
131
|
-
setFormData((prev) => ({
|
|
132
|
-
...prev,
|
|
133
|
-
fromCta: event.target?.getAttribute(DATA_POPUP_CTA) || undefined,
|
|
134
|
-
}));
|
|
135
|
-
});
|
|
136
|
-
const unsub2 = popover.onCloseAll(() => {
|
|
137
|
-
setFormData((prev) => ({
|
|
138
|
-
...prev,
|
|
139
|
-
fromCta: "",
|
|
140
|
-
}));
|
|
141
|
-
});
|
|
142
|
-
return () => {
|
|
143
|
-
unsub();
|
|
144
|
-
unsub2();
|
|
145
|
-
};
|
|
146
|
-
}, []);
|
|
147
125
|
|
|
148
126
|
// 处理输入变化
|
|
149
127
|
const handleChange = (
|
|
@@ -205,12 +183,12 @@ export const ContactForm = forwardRef<HTMLDivElement, ContactFormProps>(
|
|
|
205
183
|
try {
|
|
206
184
|
setSubmitting(true);
|
|
207
185
|
setSubmitStatus({}); // 重置提交状态
|
|
208
|
-
|
|
209
186
|
const response = await fetch(actionUrl, {
|
|
210
187
|
method: "POST",
|
|
211
188
|
body: JSON.stringify({
|
|
212
189
|
...formData,
|
|
213
|
-
|
|
190
|
+
fromCta: modal.lastCta,
|
|
191
|
+
encryptedField: encrypt(formData.phone, formSalt),
|
|
214
192
|
}),
|
|
215
193
|
headers: {
|
|
216
194
|
"X-Request-URL": window.location.href,
|
|
@@ -236,7 +214,6 @@ export const ContactForm = forwardRef<HTMLDivElement, ContactFormProps>(
|
|
|
236
214
|
email: "",
|
|
237
215
|
company: "",
|
|
238
216
|
message: "",
|
|
239
|
-
fromCta: "产品页面",
|
|
240
217
|
phone: "",
|
|
241
218
|
});
|
|
242
219
|
window.location.href = "/thanks";
|