@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.
Files changed (71) hide show
  1. package/index.ts +1 -1
  2. package/package.json +10 -6
  3. package/src/component-logic/gsap.d.ts +4 -0
  4. package/src/component-logic/index.ts +8 -0
  5. package/src/component-logic/link-client.ts +33 -0
  6. package/src/component-logic/link.ts +50 -0
  7. package/src/component-logic/modal.ts +36 -0
  8. package/src/component-logic/motion.ts +272 -0
  9. package/src/component-logic/number.ts +45 -0
  10. package/src/component-logic/popover.ts +51 -0
  11. package/src/component-logic/tabs.ts +10 -0
  12. package/src/controller/AnimateController.ts +138 -0
  13. package/src/controller/AosController.ts +240 -0
  14. package/src/controller/FlipController.ts +339 -0
  15. package/src/controller/ModalController.ts +127 -0
  16. package/src/controller/NumberController.ts +161 -0
  17. package/src/controller/PageLoader.ts +163 -0
  18. package/src/controller/PopoverController.ts +116 -0
  19. package/src/controller/TabsController.ts +271 -0
  20. package/src/controller/applyAnimation.ts +86 -0
  21. package/src/controller/applyInitialState.ts +79 -0
  22. package/src/{scripts → controller}/consts.ts +0 -2
  23. package/src/controller/index.ts +9 -0
  24. package/src/controller/popup.ts +346 -0
  25. package/src/controller/utils.ts +48 -0
  26. package/src/entify/Entify.ts +354 -365
  27. package/src/entify/IEntify.ts +91 -0
  28. package/src/entify/index.ts +3 -2
  29. package/src/entify/lib/newQueryProductOptions.ts +2 -3
  30. package/src/entify/lib/newQueryProductsMediaOptions.ts +19 -18
  31. package/src/entify/lib/queryAllProducts.ts +11 -3
  32. package/src/entify/lib/queryFeaturedProducts.ts +3 -3
  33. package/src/entify/lib/queryLatestPosts.ts +2 -2
  34. package/src/entify/lib/queryOneTheme.ts +1 -1
  35. package/src/entify/lib/queryPostCategories.ts +3 -3
  36. package/src/entify/lib/queryPostSlugs.ts +2 -2
  37. package/src/entify/lib/queryPosts.ts +92 -92
  38. package/src/entify/lib/queryProductCategories.ts +3 -3
  39. package/src/entify/lib/queryProducts.ts +69 -69
  40. package/src/entify/lib/queryUserPosts.ts +2 -2
  41. package/src/entify/lib/searchProducts.ts +2 -2
  42. package/src/index.ts +3 -1
  43. package/src/lib/formatDate.ts +15 -0
  44. package/src/lib/index.ts +3 -0
  45. package/src/lib/pagination.ts +114 -0
  46. package/src/lib/utils.ts +119 -0
  47. package/src/motion/consts.ts +428 -598
  48. package/src/motion/convertToGsapVars.ts +102 -0
  49. package/src/motion/index.ts +5 -1
  50. package/src/motion/normalizeAnimation.ts +28 -0
  51. package/src/motion/normalizeAosAnimation.ts +22 -0
  52. package/src/motion/normalizePopupAnimation.ts +24 -0
  53. package/src/motion/types.ts +133 -46
  54. package/src/react/components/AttachmentIcon/index.tsx +53 -0
  55. package/src/react/components/ContactForm/index.tsx +341 -0
  56. package/src/react/components/Icon/index.tsx +10 -0
  57. package/src/react/components/Medias/index.tsx +347 -347
  58. package/src/react/components/ProductCard/ProductCta/index.tsx +7 -5
  59. package/src/react/components/RichTextOutline/index.tsx +76 -76
  60. package/src/react/components/Scroller.tsx +5 -1
  61. package/src/react/components/SearchInput.tsx +36 -34
  62. package/src/react/components/ToTop.tsx +63 -28
  63. package/src/react/components/index.ts +3 -1
  64. package/src/react/hooks/useScroll.ts +16 -10
  65. package/src/react/components/EnquiryForm/index.tsx +0 -334
  66. package/src/scripts/actions.ts +0 -304
  67. package/src/scripts/events.ts +0 -33
  68. package/src/scripts/index.ts +0 -3
  69. /package/src/react/components/{EnquiryForm → ContactForm}/Input.tsx +0 -0
  70. /package/src/react/components/{EnquiryForm → ContactForm}/Submit.tsx +0 -0
  71. /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
- DEFAULT_ENQUIRY_POPUP,
8
- openPopup,
7
+ popover,
9
8
  PopupRole,
10
- } from "../../../../scripts";
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 = DEFAULT_ENQUIRY_POPUP } = props;
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
- openPopup(roleProps[DATA_POPUP_CTA] || popupKey, ref.current);
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 function Scroller(props: { threshold?: number }) {
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
- const [keyword, setKeyword] = useState<string>();
8
-
9
- // const navigate = useNavigate();
10
- // const [, setOpen] = useXModalState();
11
-
12
- const handleKeyEnter = (event: React.KeyboardEvent<HTMLElement>) => {
13
- if (event.key !== "Enter" || !keyword) {
14
- return;
15
- }
16
- // setOpen?.(false);
17
- const encodedKeyword = encodeURIComponent(keyword || "");
18
- if (encodedKeyword) {
19
- //navigate(`/search?keyword=${encodedKeyword}`);
20
- }
21
- };
22
-
23
- return (
24
- <input
25
- ref={ref}
26
- name="q"
27
- onKeyDown={handleKeyEnter}
28
- value={keyword}
29
- onChange={(e) => setKeyword(e.target.value)}
30
- {...props}
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 XToTopProps = {
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 ToTop = forwardRef<HTMLDivElement, XToTopProps>((
10
- props, ref) => {
11
- const { className, children, ...rest } = props
12
- const handleClick = () => {
13
- window.scrollTo({ top: 0, behavior: "smooth" })
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
- return <div
17
- ref={ref}
18
- className={
19
- clsx(
20
- "fixed bottom-4 right-4 hidden user-select-none scrolling:flex cursor-pointer transition duration-300 ease-in-out z-50",
21
- className,
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
- {...rest}
25
- onClick={handleClick}
26
- >
27
- {
28
- children || <svg className="h-6 w-6" width="1.5rem" height="1.5rem" fill="none" viewBox="0 0 24 24" stroke="currentColor">
29
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 15l7-7 7 7" />
30
- </svg>
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
- </div>
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
+ });
@@ -1,4 +1,6 @@
1
- export * from "./EnquiryForm";
1
+ export * from "./AttachmentIcon";
2
+ export * from "./ContactForm";
3
+ export * from "./Icon";
2
4
  export * from "./Medias";
3
5
  export * from "./ProductCard";
4
6
  export * from "./RichTextOutline";
@@ -2,22 +2,28 @@ import { useCallback, useEffect } from "react";
2
2
 
3
3
  export const defualtThreshold = 10;
4
4
 
5
- export function useScroll(threshold: number = defualtThreshold) {
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
- const scrolling = (window.scrollY > threshold);
12
+ if (!win || !doc) return;
13
+
14
+ const scrolling = win.scrollY > threshold;
9
15
 
10
16
  if (scrolling) {
11
- document.body.classList.add('scrolling');
17
+ doc.body.classList.add("scrolling");
12
18
  } else {
13
- document.body.classList.remove('scrolling');
19
+ doc.body.classList.remove("scrolling");
14
20
  }
15
-
16
- }, [threshold]);
21
+ }, [threshold, win, doc]);
17
22
 
18
23
  useEffect(() => {
19
- window.addEventListener("scroll", onScroll);
20
- return () => window.removeEventListener("scroll", onScroll);
21
- }, [onScroll]);
22
-
24
+ if (!win) return;
25
+
26
+ win.addEventListener("scroll", onScroll);
27
+ return () => win.removeEventListener("scroll", onScroll);
28
+ }, [onScroll, win]);
23
29
  }