@rxdrag/website-lib-core 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.
- package/index.ts +1 -1
- package/package.json +10 -6
- package/src/component-logic/gsap.d.ts +4 -0
- package/src/component-logic/index.ts +8 -0
- package/src/component-logic/link-client.ts +33 -0
- package/src/component-logic/link.ts +50 -0
- package/src/component-logic/modal.ts +36 -0
- package/src/component-logic/motion.ts +272 -0
- package/src/component-logic/number.ts +45 -0
- package/src/component-logic/popover.ts +51 -0
- package/src/component-logic/tabs.ts +10 -0
- package/src/controller/AnimateController.ts +138 -0
- package/src/controller/AosController.ts +240 -0
- package/src/controller/FlipController.ts +339 -0
- package/src/controller/ModalController.ts +127 -0
- package/src/controller/NumberController.ts +161 -0
- package/src/controller/PageLoader.ts +163 -0
- package/src/controller/PopoverController.ts +116 -0
- package/src/controller/TabsController.ts +271 -0
- package/src/controller/applyAnimation.ts +86 -0
- package/src/controller/applyInitialState.ts +79 -0
- package/src/{scripts → controller}/consts.ts +0 -2
- package/src/controller/index.ts +9 -0
- package/src/controller/popup.ts +346 -0
- package/src/controller/utils.ts +48 -0
- package/src/entify/Entify.ts +354 -365
- package/src/entify/IEntify.ts +91 -0
- package/src/entify/index.ts +3 -2
- package/src/entify/lib/newQueryProductOptions.ts +2 -3
- package/src/entify/lib/newQueryProductsMediaOptions.ts +19 -18
- package/src/entify/lib/queryAllProducts.ts +11 -3
- package/src/entify/lib/queryFeaturedProducts.ts +3 -3
- package/src/entify/lib/queryLatestPosts.ts +2 -2
- package/src/entify/lib/queryOneTheme.ts +1 -1
- package/src/entify/lib/queryPostCategories.ts +3 -3
- package/src/entify/lib/queryPostSlugs.ts +2 -2
- package/src/entify/lib/queryPosts.ts +92 -92
- package/src/entify/lib/queryProductCategories.ts +3 -3
- package/src/entify/lib/queryProducts.ts +69 -69
- package/src/entify/lib/queryUserPosts.ts +2 -2
- package/src/entify/lib/searchProducts.ts +2 -2
- package/src/index.ts +3 -1
- package/src/lib/formatDate.ts +15 -0
- package/src/lib/index.ts +3 -0
- package/src/lib/pagination.ts +114 -0
- package/src/lib/utils.ts +119 -0
- package/src/motion/consts.ts +428 -598
- package/src/motion/convertToGsapVars.ts +102 -0
- package/src/motion/index.ts +5 -1
- package/src/motion/normalizeAnimation.ts +28 -0
- package/src/motion/normalizeAosAnimation.ts +22 -0
- package/src/motion/normalizePopupAnimation.ts +24 -0
- package/src/motion/types.ts +133 -46
- package/src/react/components/AttachmentIcon/index.tsx +53 -0
- package/src/react/components/ContactForm/index.tsx +341 -0
- package/src/react/components/Icon/index.tsx +10 -0
- package/src/react/components/Medias/index.tsx +347 -347
- package/src/react/components/ProductCard/ProductCta/index.tsx +7 -5
- package/src/react/components/RichTextOutline/index.tsx +76 -76
- package/src/react/components/Scroller.tsx +5 -1
- package/src/react/components/SearchInput.tsx +36 -34
- package/src/react/components/ToTop.tsx +63 -28
- package/src/react/components/index.ts +3 -1
- package/src/react/hooks/useScroll.ts +16 -10
- package/src/react/components/EnquiryForm/index.tsx +0 -334
- package/src/scripts/actions.ts +0 -304
- package/src/scripts/events.ts +0 -33
- package/src/scripts/index.ts +0 -3
- /package/src/react/components/{EnquiryForm → ContactForm}/Input.tsx +0 -0
- /package/src/react/components/{EnquiryForm → ContactForm}/Submit.tsx +0 -0
- /package/src/react/components/{EnquiryForm → ContactForm}/Textarea.tsx +0 -0
|
@@ -4,15 +4,14 @@ import {
|
|
|
4
4
|
DATA_POPUP,
|
|
5
5
|
DATA_POPUP_CTA,
|
|
6
6
|
DATA_POPUP_ROLE,
|
|
7
|
-
|
|
8
|
-
openPopup,
|
|
7
|
+
popover,
|
|
9
8
|
PopupRole,
|
|
10
|
-
} from "../../../../
|
|
9
|
+
} from "../../../../controller";
|
|
11
10
|
import { useRef } from "react";
|
|
12
11
|
|
|
13
12
|
//TODO: 跟询盘触发器同样的实现原理,给询盘对话框发消息
|
|
14
13
|
export function ProductCta(props: { product?: Product; popupKey?: string }) {
|
|
15
|
-
const { product, popupKey =
|
|
14
|
+
const { product, popupKey = "enquiry-modal" } = props;
|
|
16
15
|
const ref = useRef<HTMLButtonElement>(null);
|
|
17
16
|
const roleProps = {
|
|
18
17
|
[DATA_POPUP_CTA]: `From RichText ProductCard-${product?.title}-${product?.id}`,
|
|
@@ -22,7 +21,10 @@ export function ProductCta(props: { product?: Product; popupKey?: string }) {
|
|
|
22
21
|
|
|
23
22
|
const handleClick = () => {
|
|
24
23
|
if (ref.current) {
|
|
25
|
-
|
|
24
|
+
popover.open(
|
|
25
|
+
roleProps[DATA_POPUP_CTA] || popupKey,
|
|
26
|
+
ref.current
|
|
27
|
+
);
|
|
26
28
|
}
|
|
27
29
|
};
|
|
28
30
|
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { extractOutline, mdxToSlate } from "@rxdrag/slate-preview";
|
|
2
|
-
import { forwardRef, ReactNode, useEffect } from "react";
|
|
3
|
-
import { useAcitviedHeading } from "./useAcitviedHeading";
|
|
4
|
-
import clsx from "clsx";
|
|
5
|
-
|
|
6
|
-
export type RichTextOutlineProps = {
|
|
7
|
-
className?: string;
|
|
8
|
-
itemClassName?: string;
|
|
9
|
-
value?: string;
|
|
10
|
-
//滚动偏移量
|
|
11
|
-
yOffset?: number;
|
|
12
|
-
style?: React.CSSProperties;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const RichTextOutline = forwardRef<
|
|
16
|
-
HTMLUListElement,
|
|
17
|
-
RichTextOutlineProps
|
|
18
|
-
>((props, ref) => {
|
|
19
|
-
const { className, itemClassName, value, yOffset = 100, ...rest } = props;
|
|
20
|
-
const activiedId = useAcitviedHeading();
|
|
21
|
-
const nodes = mdxToSlate(value ?? "");
|
|
22
|
-
const outline = extractOutline(nodes ?? []);
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const handleHashChange = () => {
|
|
26
|
-
const element = document.getElementById(
|
|
27
|
-
window.location.hash.substring(1)
|
|
28
|
-
);
|
|
29
|
-
if (element) {
|
|
30
|
-
const y =
|
|
31
|
-
element.getBoundingClientRect().top + window.scrollY - yOffset;
|
|
32
|
-
window.scrollTo({ top: y, behavior: "smooth" });
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
window.addEventListener("hashchange", handleHashChange);
|
|
37
|
-
|
|
38
|
-
return () => {
|
|
39
|
-
window.removeEventListener("hashchange", handleHashChange);
|
|
40
|
-
};
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
return outline?.length ? (
|
|
44
|
-
<ul ref={ref} className={className} {...rest}>
|
|
45
|
-
{outline?.map((item, index) => {
|
|
46
|
-
return (
|
|
47
|
-
<li
|
|
48
|
-
key={item?.key + index}
|
|
49
|
-
className={clsx(
|
|
50
|
-
activiedId === item?.key ? "actived" : "",
|
|
51
|
-
itemClassName
|
|
52
|
-
)}
|
|
53
|
-
>
|
|
54
|
-
<a
|
|
55
|
-
href={`#${item?.key}`}
|
|
56
|
-
onClick={(e) => {
|
|
57
|
-
e.preventDefault();
|
|
58
|
-
const element = document.getElementById(item?.key);
|
|
59
|
-
if (element) {
|
|
60
|
-
const yOffset = -100; // 偏移量
|
|
61
|
-
const y =
|
|
62
|
-
element.getBoundingClientRect().top +
|
|
63
|
-
window.scrollY +
|
|
64
|
-
yOffset;
|
|
65
|
-
window.scrollTo({ top: y, behavior: "smooth" });
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
>
|
|
69
|
-
{item?.text}
|
|
70
|
-
</a>
|
|
71
|
-
</li>
|
|
72
|
-
);
|
|
73
|
-
})}
|
|
74
|
-
</ul>
|
|
75
|
-
) : null;
|
|
76
|
-
});
|
|
1
|
+
import { extractOutline, mdxToSlate } from "@rxdrag/slate-preview";
|
|
2
|
+
import { forwardRef, ReactNode, useEffect } from "react";
|
|
3
|
+
import { useAcitviedHeading } from "./useAcitviedHeading";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
|
|
6
|
+
export type RichTextOutlineProps = {
|
|
7
|
+
className?: string;
|
|
8
|
+
itemClassName?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
//滚动偏移量
|
|
11
|
+
yOffset?: number;
|
|
12
|
+
style?: React.CSSProperties;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const RichTextOutline = forwardRef<
|
|
16
|
+
HTMLUListElement,
|
|
17
|
+
RichTextOutlineProps
|
|
18
|
+
>((props, ref) => {
|
|
19
|
+
const { className, itemClassName, value, yOffset = 100, ...rest } = props;
|
|
20
|
+
const activiedId = useAcitviedHeading();
|
|
21
|
+
const nodes = mdxToSlate(value ?? "");
|
|
22
|
+
const outline = extractOutline(nodes ?? []);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const handleHashChange = () => {
|
|
26
|
+
const element = document.getElementById(
|
|
27
|
+
window.location.hash.substring(1)
|
|
28
|
+
);
|
|
29
|
+
if (element) {
|
|
30
|
+
const y =
|
|
31
|
+
element.getBoundingClientRect().top + window.scrollY - yOffset;
|
|
32
|
+
window.scrollTo({ top: y, behavior: "smooth" });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
window.addEventListener("hashchange", handleHashChange);
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
window.removeEventListener("hashchange", handleHashChange);
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return outline?.length ? (
|
|
44
|
+
<ul ref={ref} className={className} {...rest}>
|
|
45
|
+
{outline?.map((item, index) => {
|
|
46
|
+
return (
|
|
47
|
+
<li
|
|
48
|
+
key={item?.key + index}
|
|
49
|
+
className={clsx(
|
|
50
|
+
activiedId === item?.key ? "actived" : "",
|
|
51
|
+
itemClassName
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
<a
|
|
55
|
+
href={`#${item?.key}`}
|
|
56
|
+
onClick={(e) => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
const element = document.getElementById(item?.key);
|
|
59
|
+
if (element) {
|
|
60
|
+
const yOffset = -100; // 偏移量
|
|
61
|
+
const y =
|
|
62
|
+
element.getBoundingClientRect().top +
|
|
63
|
+
window.scrollY +
|
|
64
|
+
yOffset;
|
|
65
|
+
window.scrollTo({ top: y, behavior: "smooth" });
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
{item?.text}
|
|
70
|
+
</a>
|
|
71
|
+
</li>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</ul>
|
|
75
|
+
) : null;
|
|
76
|
+
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useScroll } from "../hooks";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type ScrollerProps = {
|
|
4
|
+
threshold?: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function Scroller(props: ScrollerProps) {
|
|
4
8
|
const { threshold } = props;
|
|
5
9
|
useScroll(threshold);
|
|
6
10
|
return <></>;
|
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import { forwardRef, useState } from "react";
|
|
2
|
-
|
|
3
|
-
export type SearchProps = React.InputHTMLAttributes<HTMLInputElement>;
|
|
4
|
-
|
|
5
|
-
export const SearchInput = forwardRef<HTMLInputElement, SearchProps>(
|
|
6
|
-
(props, ref) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
);
|
|
1
|
+
import { forwardRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export type SearchProps = React.InputHTMLAttributes<HTMLInputElement>;
|
|
4
|
+
|
|
5
|
+
export const SearchInput = forwardRef<HTMLInputElement, SearchProps>(
|
|
6
|
+
(props, ref) => {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
const { children, ...rest } = props;
|
|
9
|
+
const [keyword, setKeyword] = useState<string>();
|
|
10
|
+
|
|
11
|
+
// const navigate = useNavigate();
|
|
12
|
+
// const [, setOpen] = useXModalState();
|
|
13
|
+
|
|
14
|
+
const handleKeyEnter = (event: React.KeyboardEvent<HTMLElement>) => {
|
|
15
|
+
if (event.key !== "Enter" || !keyword) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// setOpen?.(false);
|
|
19
|
+
const encodedKeyword = encodeURIComponent(keyword || "");
|
|
20
|
+
if (encodedKeyword) {
|
|
21
|
+
//navigate(`/search?keyword=${encodedKeyword}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<input
|
|
27
|
+
ref={ref}
|
|
28
|
+
name="q"
|
|
29
|
+
onKeyDown={handleKeyEnter}
|
|
30
|
+
value={keyword}
|
|
31
|
+
onChange={(e) => setKeyword(e.target.value)}
|
|
32
|
+
{...rest}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
);
|
|
@@ -1,33 +1,68 @@
|
|
|
1
|
-
import clsx from "clsx"
|
|
2
|
-
import { forwardRef } from "react"
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { forwardRef, useRef, useEffect, useState } from "react";
|
|
3
3
|
|
|
4
|
-
export type
|
|
5
|
-
className?: string
|
|
6
|
-
children?: React.ReactNode
|
|
7
|
-
}
|
|
4
|
+
export type ToTopProps = {
|
|
5
|
+
className?: string;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
};
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export const topIcon = () => (
|
|
10
|
+
<svg
|
|
11
|
+
className="h-6 w-6"
|
|
12
|
+
width="1.5rem"
|
|
13
|
+
height="1.5rem"
|
|
14
|
+
fill="none"
|
|
15
|
+
viewBox="0 0 24 24"
|
|
16
|
+
stroke="currentColor"
|
|
17
|
+
>
|
|
18
|
+
<path
|
|
19
|
+
strokeLinecap="round"
|
|
20
|
+
strokeLinejoin="round"
|
|
21
|
+
strokeWidth={2}
|
|
22
|
+
d="M5 15l7-7 7 7"
|
|
23
|
+
/>
|
|
24
|
+
</svg>
|
|
25
|
+
);
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
export const ToTop = forwardRef<HTMLDivElement, ToTopProps>((props, ref) => {
|
|
28
|
+
const { className, children, ...rest } = props;
|
|
29
|
+
const [win, setWin] = useState<Window | null>(null);
|
|
30
|
+
const innerRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
|
|
32
|
+
// 合并外部传入的ref和内部ref
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!innerRef.current) return;
|
|
35
|
+
|
|
36
|
+
// 获取当前元素所在的window
|
|
37
|
+
const currentWin = innerRef.current.ownerDocument.defaultView;
|
|
38
|
+
setWin(currentWin);
|
|
39
|
+
|
|
40
|
+
// 如果外部传入的是ref对象,则设置其current属性
|
|
41
|
+
if (ref && typeof ref === 'object') {
|
|
42
|
+
ref.current = innerRef.current;
|
|
23
43
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
}, [ref]);
|
|
45
|
+
|
|
46
|
+
const handleClick = () => {
|
|
47
|
+
if (win) {
|
|
48
|
+
win.scrollTo({ top: 0, behavior: "smooth" });
|
|
49
|
+
} else if (typeof window !== 'undefined') {
|
|
50
|
+
// 降级处理:如果没有获取到特定window,使用全局window
|
|
51
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
31
52
|
}
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div
|
|
57
|
+
ref={innerRef}
|
|
58
|
+
className={clsx(
|
|
59
|
+
"fixed bottom-4 right-4 hidden user-select-none shadow-lg scrolling:flex cursor-pointer transition duration-300 ease-in-out z-50",
|
|
60
|
+
className
|
|
61
|
+
)}
|
|
62
|
+
{...rest}
|
|
63
|
+
onClick={handleClick}
|
|
64
|
+
>
|
|
65
|
+
{children || topIcon()}
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
});
|
|
@@ -2,22 +2,28 @@ import { useCallback, useEffect } from "react";
|
|
|
2
2
|
|
|
3
3
|
export const defualtThreshold = 10;
|
|
4
4
|
|
|
5
|
-
export function useScroll(
|
|
5
|
+
export function useScroll(
|
|
6
|
+
threshold: number = defualtThreshold,
|
|
7
|
+
win: Window | undefined = typeof window !== 'undefined' ? window : undefined,
|
|
8
|
+
doc: Document | undefined = typeof document !== 'undefined' ? document : undefined
|
|
9
|
+
) {
|
|
6
10
|
|
|
7
11
|
const onScroll = useCallback(() => {
|
|
8
|
-
|
|
12
|
+
if (!win || !doc) return;
|
|
13
|
+
|
|
14
|
+
const scrolling = win.scrollY > threshold;
|
|
9
15
|
|
|
10
16
|
if (scrolling) {
|
|
11
|
-
|
|
17
|
+
doc.body.classList.add("scrolling");
|
|
12
18
|
} else {
|
|
13
|
-
|
|
19
|
+
doc.body.classList.remove("scrolling");
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
}, [threshold]);
|
|
21
|
+
}, [threshold, win, doc]);
|
|
17
22
|
|
|
18
23
|
useEffect(() => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
if (!win) return;
|
|
25
|
+
|
|
26
|
+
win.addEventListener("scroll", onScroll);
|
|
27
|
+
return () => win.removeEventListener("scroll", onScroll);
|
|
28
|
+
}, [onScroll, win]);
|
|
23
29
|
}
|