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