@rxdrag/website-lib-react 0.0.7 → 0.0.8

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.
Files changed (72) hide show
  1. package/package.json +22 -23
  2. package/forms.ts +0 -1
  3. package/index.ts +0 -1
  4. package/media.ts +0 -1
  5. package/richtext.ts +0 -1
  6. package/src/components/Analytics/eventHandlers.ts +0 -173
  7. package/src/components/Analytics/index.tsx +0 -21
  8. package/src/components/Analytics/singleton.ts +0 -214
  9. package/src/components/Analytics/tracking.ts +0 -221
  10. package/src/components/Analytics/types.ts +0 -60
  11. package/src/components/Analytics/utils.ts +0 -95
  12. package/src/components/AttachmentIcon/index.tsx +0 -53
  13. package/src/components/BackgroundHlsVideoPlayer.tsx +0 -97
  14. package/src/components/BackgroundVideoPlayer.tsx +0 -32
  15. package/src/components/Bulletin.tsx +0 -30
  16. package/src/components/ContactForm/ContactForm.tsx +0 -296
  17. package/src/components/ContactForm/FileUpload2.tsx +0 -423
  18. package/src/components/ContactForm/Input.tsx +0 -48
  19. package/src/components/ContactForm/Input2.tsx +0 -59
  20. package/src/components/ContactForm/Submit.tsx +0 -48
  21. package/src/components/ContactForm/TelInput.tsx +0 -215
  22. package/src/components/ContactForm/TelInput2.tsx +0 -213
  23. package/src/components/ContactForm/Textarea.tsx +0 -48
  24. package/src/components/ContactForm/Textarea2.tsx +0 -89
  25. package/src/components/ContactForm/countryDialCodes.ts +0 -243
  26. package/src/components/ContactForm/factory.tsx +0 -60
  27. package/src/components/ContactForm/funcs.ts +0 -64
  28. package/src/components/ContactForm/hooks/useInlineLabelPadding.ts +0 -43
  29. package/src/components/ContactForm/hooks/useTelControl.ts +0 -81
  30. package/src/components/ContactForm/index.ts +0 -7
  31. package/src/components/ContactForm/types.ts +0 -68
  32. package/src/components/Icon/index.tsx +0 -20
  33. package/src/components/Medias/MainMedia.tsx +0 -257
  34. package/src/components/Medias/Thumbnail.tsx +0 -62
  35. package/src/components/Medias/VideoPlayer.tsx +0 -114
  36. package/src/components/Medias/index.tsx +0 -271
  37. package/src/components/ProductCard/ProductCard.tsx +0 -24
  38. package/src/components/ProductCard/ProductCta/index.tsx +0 -28
  39. package/src/components/ProductCard/ProductCta/style.css +0 -4
  40. package/src/components/ProductCard/ProductDescription/index.tsx +0 -13
  41. package/src/components/ProductCard/ProductDescription/style.css +0 -6
  42. package/src/components/ProductCard/ProductMedia/index.tsx +0 -35
  43. package/src/components/ProductCard/ProductMedia/style.css +0 -6
  44. package/src/components/ProductCard/ProductTitle/index.tsx +0 -7
  45. package/src/components/ProductCard/ProductTitle/style.css +0 -4
  46. package/src/components/ProductCard/ProductView.tsx +0 -36
  47. package/src/components/ProductCard/index.ts +0 -5
  48. package/src/components/ProductCard/useQueryProduct.ts +0 -32
  49. package/src/components/ReactModalTrigger.tsx +0 -28
  50. package/src/components/ReactVideoPlayer.tsx +0 -332
  51. package/src/components/RichTextOutline/index.tsx +0 -74
  52. package/src/components/RichTextOutline/parseOutline.ts +0 -63
  53. package/src/components/RichTextOutline/useAcitviedHeading.ts +0 -142
  54. package/src/components/RichTextOutline/useAnchorScroll.ts +0 -24
  55. package/src/components/Scroller.tsx +0 -39
  56. package/src/components/SearchInput.tsx +0 -21
  57. package/src/components/Share/index.tsx +0 -86
  58. package/src/components/Share/socials.tsx +0 -80
  59. package/src/components/Share//350/265/204/346/226/231.md +0 -7
  60. package/src/components/ToTop.tsx +0 -72
  61. package/src/components/VideoPlayIcon.tsx +0 -43
  62. package/src/components/all.ts +0 -25
  63. package/src/components/index.ts +0 -12
  64. package/src/forms.ts +0 -1
  65. package/src/index.ts +0 -1
  66. package/src/media.ts +0 -1
  67. package/src/richtext.ts +0 -1
  68. package/src/types/view-model.ts +0 -37
  69. package/src/ui.ts +0 -10
  70. package/src/video.ts +0 -2
  71. package/ui.ts +0 -1
  72. package/video.ts +0 -1
@@ -1,296 +0,0 @@
1
- import React, { forwardRef, useState } from "react";
2
- import { Submit } from "./Submit";
3
- import { type UploadedFile } from "./FileUpload2";
4
- import clsx from "clsx";
5
- import { encrypt } from "./funcs";
6
- import { ContactFormProps, QuoteRequest } from "./types";
7
- import { getControl, getFileUpload } from "./factory";
8
-
9
- interface FormErrors {
10
- name?: string;
11
- email?: string;
12
- message?: string;
13
- }
14
-
15
- export const ContactForm = forwardRef<HTMLDivElement, ContactFormProps>(
16
- (props, ref) => {
17
- const {
18
- submit,
19
- actionUrl = "/api/ask-for-quote",
20
- formSalt,
21
- fields = [],
22
- className,
23
- classNames,
24
- fromCta,
25
- ...rest
26
- } = props;
27
- const [formData, setFormData] = useState<QuoteRequest>({
28
- name: "",
29
- email: "",
30
- company: "",
31
- message: "",
32
- phone: "", // 初始化蜜罐字段
33
- attachments: [], // 附件 ID 列表
34
- });
35
- // 错误状态
36
- const [errors, setErrors] = useState<FormErrors>({});
37
- const [submitting, setSubmitting] = useState(false);
38
- const [isUploading, setIsUploading] = useState(false);
39
- const [submitStatus, setSubmitStatus] = useState<{
40
- success?: boolean;
41
- message?: string;
42
- }>({});
43
- const lastCta =
44
- typeof window === "undefined"
45
- ? undefined
46
- : (window as Window & { lastCta?: string }).lastCta;
47
-
48
- // 处理输入变化
49
- const handleChange = (
50
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
51
- isExtends?: boolean
52
- ) => {
53
- const { name, value } = e.target;
54
- if (isExtends) {
55
- setFormData((prev) => ({
56
- ...prev,
57
- extents: {
58
- ...(prev.extends || {}),
59
- [name]: value,
60
- },
61
- }));
62
- } else {
63
- setFormData((prev) => ({
64
- ...prev,
65
- [name]: value,
66
- }));
67
- }
68
-
69
- setSubmitStatus({}); // 重置提交状态
70
-
71
- // 清除对应字段的错误
72
- if (errors[name as keyof FormErrors]) {
73
- setErrors((prev) => ({
74
- ...prev,
75
- [name]: undefined,
76
- }));
77
- }
78
- };
79
-
80
- // 处理文件上传变化(单文件)
81
- const handleFileChange = (fileInfo: UploadedFile | null) => {
82
- setFormData((prev) => ({
83
- ...prev,
84
- attachments: fileInfo ? [fileInfo] : [], // 存储完整的文件信息
85
- }));
86
- };
87
-
88
- // 处理文件上传状态变化
89
- const handleFileUploadStateChange = (uploading: boolean) => {
90
- setIsUploading(uploading);
91
- };
92
- // 验证表单
93
- const validateForm = (): boolean => {
94
- const newErrors: FormErrors = {};
95
-
96
- // if (!formData.name?.trim()) {
97
- // newErrors.name = "Please enter your name";
98
- // }
99
-
100
- if (!formData.email?.trim()) {
101
- newErrors.email = "Please enter your email";
102
- } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
103
- newErrors.email = "Please enter a valid email address";
104
- }
105
-
106
- if (!formData.message?.trim()) {
107
- newErrors.message = "Please enter your message";
108
- }
109
-
110
- // 检查蜜罐字段 - 如果填写了则表示是机器人
111
- if (formData.phone) {
112
- // 悄悄失败,不显示错误信息
113
- console.log("Honeypot triggered - likely spam submission");
114
- return false;
115
- }
116
-
117
- setErrors(newErrors);
118
- return Object.keys(newErrors).length === 0;
119
- };
120
-
121
- const handleClick = async (event: React.MouseEvent) => {
122
- event.preventDefault(); // 阻止表单默认提交行为
123
-
124
- // 验证表单
125
- if (!validateForm()) {
126
- return; // 如果验证失败,不继续提交
127
- }
128
-
129
- try {
130
- setSubmitting(true);
131
- setSubmitStatus({}); // 重置提交状态
132
- const response = await fetch(actionUrl, {
133
- method: "POST",
134
- body: JSON.stringify({
135
- ...formData,
136
- //TODO:后面改成从window 或者传入
137
- fromCta: fromCta || lastCta,
138
- encryptedField: encrypt(formData.phone, formSalt),
139
- }),
140
- headers: {
141
- "X-Request-URL":
142
- typeof window === "undefined" ? "" : window.location.href,
143
- "Content-Type": "application/json",
144
- },
145
- });
146
-
147
- if (!response.ok) {
148
- throw new Error(`Server responded with status: ${response.status}`);
149
- }
150
-
151
- const result = await response.json();
152
-
153
- setSubmitStatus({
154
- success: result.success,
155
- message: result.message,
156
- });
157
-
158
- if (result.success) {
159
- // 重置表单
160
- setFormData({
161
- name: "",
162
- email: "",
163
- company: "",
164
- message: "",
165
- phone: "",
166
- attachments: [],
167
- });
168
- if (typeof window !== "undefined") {
169
- window.location.href = "/thanks";
170
- }
171
- }
172
- } catch (error) {
173
- // 如果出现错误,打印错误信息
174
- console.error("Form submission error:", error);
175
- setSubmitStatus({
176
- success: false,
177
- message:
178
- error instanceof Error
179
- ? `Error: ${error.message}`
180
- : "Failed to submit the form. Please try again later.",
181
- });
182
- } finally {
183
- setSubmitting(false);
184
- }
185
- };
186
-
187
- return (
188
- <div
189
- ref={ref}
190
- className={clsx(
191
- "py-4 grid max-w-2xl grid-cols-1 gap-x-6 sm:grid-cols-2 w-full",
192
- className || "gap-y-6"
193
- )}
194
- {...rest}
195
- >
196
- {fields.map((field, index) => {
197
- const {
198
- controlName,
199
- feildStyle,
200
- isExtends,
201
- name,
202
- className,
203
- inputClassName,
204
- labelClassName,
205
- ...rest
206
- } = field;
207
-
208
- // FileUpload 组件特殊处理
209
- if (controlName === "FileUpload") {
210
- const FileUploadControl = getFileUpload(feildStyle);
211
- return (
212
- <FileUploadControl
213
- key={name || index}
214
- name={name || "attachments"}
215
- formSalt={formSalt}
216
- className={clsx(classNames?.inputContainer, className)}
217
- inputClassName={clsx(classNames?.input, inputClassName)}
218
- labelClassName={clsx(classNames?.label, labelClassName)}
219
- maxSize={3 * 1024 * 1024}
220
- onChange={handleFileChange}
221
- onUploadStateChange={handleFileUploadStateChange}
222
- placeholder="Click to select file"
223
- uploadingText="Uploading..."
224
- selectedText="Selected: {name}"
225
- accept="*/*"
226
- {...rest}
227
- />
228
- );
229
- }
230
-
231
- // 普通输入控件
232
- const Control = getControl(controlName, feildStyle);
233
- return (
234
- <Control
235
- key={name || index}
236
- name={name}
237
- className={clsx(classNames?.inputContainer, className)}
238
- labelClassName={clsx(classNames?.label, labelClassName)}
239
- inputClassName={clsx(classNames?.input, inputClassName)}
240
- requiredClassName={classNames?.required}
241
- value={formData[name as keyof QuoteRequest] as string}
242
- onChange={(e) => handleChange(e, isExtends)}
243
- error={errors[name as keyof FormErrors]}
244
- {...rest}
245
- />
246
- );
247
- })}
248
-
249
- {/* 蜜罐字段 - 对用户隐藏但对机器人可见 */}
250
- <div style={{ display: "none" }}>
251
- <input
252
- type="text"
253
- name="phone"
254
- value={formData.phone}
255
- onChange={handleChange}
256
- tabIndex={-1}
257
- autoComplete="off"
258
- />
259
- </div>
260
- <div
261
- className={clsx(
262
- "col-span-full flex items-center gap-x-6 px-0 py-2",
263
- submit?.containerClassName
264
- )}
265
- >
266
- {submitStatus.message && !submitStatus.success && (
267
- <div
268
- className={`text-sm ${
269
- submitStatus.success ? "text-green-600" : "text-red-600"
270
- }`}
271
- >
272
- {submitStatus.message}
273
- </div>
274
- )}
275
- <Submit
276
- className={clsx(
277
- "flex gap-2 items-center relative shadow-sm btn btn-lg nowrap",
278
- submit?.className || "btn-primary"
279
- )}
280
- title={submit?.title || "Send Message"}
281
- spinner={
282
- <div className="left-8 flex items-center justify-center">
283
- <div className="animate-spin rounded-full h-5 w-5 border-t-2 border-b-2 border-white" />
284
- </div>
285
- }
286
- rawHtml={submit?.rawHtml}
287
- needClasses={submit?.needClasses}
288
- submitting={submitting}
289
- disabled={submitting || isUploading}
290
- onClick={handleClick}
291
- />
292
- </div>
293
- </div>
294
- );
295
- }
296
- );