@rxdrag/website-lib-core 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 (71) hide show
  1. package/index.ts +1 -1
  2. package/package.json +11 -7
  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
@@ -9,7 +9,7 @@ import {
9
9
  } from "@rxdrag/rxcms-models";
10
10
  import { queryEntityList } from "./queryEntityList";
11
11
  import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
12
- import { ListResult, OrderBy } from "@rxdrag/entify-hooks";
12
+ import { ListResult } from "@rxdrag/entify-hooks";
13
13
  import { EnvVariables } from "../types";
14
14
  import { TProduct } from "../view-model";
15
15
 
@@ -56,7 +56,7 @@ export async function searchProducts(
56
56
  ...keyArray,
57
57
  ],
58
58
  },
59
- orderBy: [{ [ProductFields.seqValue]: OrderBy.asc }],
59
+ orderBy: [{ [ProductFields.seqValue]: "asc" }],
60
60
  }
61
61
  ).mediaPivots(newQueryProductsMediaOptions());
62
62
 
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./entify";
2
+ export * from "./component-logic";
2
3
  export * from "./motion";
3
4
  export * from "./react";
4
- export * from "./scripts";
5
+ export * from "./controller";
5
6
  export * from "./robots";
7
+ export * from "./lib";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 格式化日期为可读字符串
3
+ * @param date 日期对象或日期字符串
4
+ * @returns 格式化后的日期字符串,例如:2023年1月1日
5
+ */
6
+ export function formatDate(date: Date | string | number): string {
7
+ const d = new Date(date);
8
+
9
+ // 使用 Intl.DateTimeFormat 进行本地化日期格式化
10
+ return new Intl.DateTimeFormat('zh-CN', {
11
+ year: 'numeric',
12
+ month: 'long',
13
+ day: 'numeric'
14
+ }).format(d);
15
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./pagination";
2
+ export * from "./formatDate";
3
+ export * from "./utils";
@@ -0,0 +1,114 @@
1
+ export type PageItem = number | "ellipsis";
2
+
3
+ export interface PaginationProps {
4
+ currentPage: number;
5
+ totalPages: number;
6
+ baseUrl: string;
7
+ }
8
+
9
+ export interface PaginationData {
10
+ pages: PageItem[];
11
+ hasPreviousPage: boolean;
12
+ hasNextPage: boolean;
13
+ previousPageUrl: string;
14
+ nextPageUrl: string;
15
+ pageUrls: Record<number, string>;
16
+ currentPage: number;
17
+ }
18
+
19
+ export function generatePagination(current: number, total: number) {
20
+ const result: PageItem[] = [];
21
+ const edgePageCount = 1; // 边缘页数
22
+ const middlePagesSiblingCount = 2; // 中间页数的兄弟数量
23
+ const totalVisiblePages = edgePageCount * 2 + middlePagesSiblingCount * 2 + 1;
24
+
25
+ // 如果总页数较少,直接显示所有页码
26
+ if (total <= totalVisiblePages) {
27
+ for (let i = 1; i <= total; i++) {
28
+ result.push(i);
29
+ }
30
+ return result;
31
+ }
32
+
33
+ // 始终显示第一页
34
+ result.push(1);
35
+
36
+ // 计算中间区域的起始和结束
37
+ let leftIndex = Math.max(
38
+ edgePageCount + 1,
39
+ current - middlePagesSiblingCount
40
+ );
41
+ let rightIndex = Math.min(
42
+ total - edgePageCount,
43
+ current + middlePagesSiblingCount
44
+ );
45
+
46
+ // 调整以保持固定数量的页码
47
+ if (leftIndex <= edgePageCount + 1) {
48
+ rightIndex = Math.min(
49
+ total - edgePageCount,
50
+ totalVisiblePages - edgePageCount - 1
51
+ );
52
+ }
53
+ if (rightIndex >= total - edgePageCount) {
54
+ leftIndex = Math.max(
55
+ edgePageCount + 1,
56
+ total - totalVisiblePages + edgePageCount + 1
57
+ );
58
+ }
59
+
60
+ // 添加左省略号
61
+ if (leftIndex > edgePageCount + 1) {
62
+ result.push("ellipsis");
63
+ }
64
+
65
+ // 添加中间页码
66
+ for (let i = leftIndex; i <= rightIndex; i++) {
67
+ result.push(i);
68
+ }
69
+
70
+ // 添加右省略号
71
+ if (rightIndex < total - edgePageCount) {
72
+ result.push("ellipsis");
73
+ }
74
+
75
+ // 始终显示最后一页
76
+ if (total > 1) {
77
+ result.push(total);
78
+ }
79
+
80
+ return result;
81
+ }
82
+
83
+ export function paginate(props: PaginationProps): PaginationData {
84
+ const { currentPage, totalPages, baseUrl } = props;
85
+
86
+ // 生成页码数组
87
+ const pages = generatePagination(currentPage, totalPages);
88
+
89
+ // 判断是否有上一页和下一页
90
+ const hasPreviousPage = currentPage > 1;
91
+ const hasNextPage = currentPage < totalPages;
92
+
93
+ // 生成上一页和下一页的URL
94
+ const previousPageUrl = `${baseUrl}${currentPage - 1}`;
95
+ const nextPageUrl = `${baseUrl}${currentPage + 1}`;
96
+
97
+ // 生成每个页码对应的URL
98
+ const pageUrls: Record<number, string> = {};
99
+ pages.forEach((page) => {
100
+ if (typeof page === "number") {
101
+ pageUrls[page] = `${baseUrl}${page}`;
102
+ }
103
+ });
104
+
105
+ return {
106
+ pages,
107
+ hasPreviousPage,
108
+ hasNextPage,
109
+ previousPageUrl,
110
+ nextPageUrl,
111
+ pageUrls,
112
+ currentPage,
113
+ };
114
+ }
@@ -0,0 +1,119 @@
1
+ import {
2
+ TBreadcrumbItem,
3
+ TPost,
4
+ TPostCategory,
5
+ TProduct,
6
+ TProductCategory,
7
+ } from "../entify";
8
+ import { paginate } from "./pagination";
9
+
10
+ export function postsPagination(options: {
11
+ currentPage: number;
12
+ totalPages: number;
13
+ baseUrl?: string;
14
+ }) {
15
+ return paginate({
16
+ currentPage: options.currentPage,
17
+ totalPages: options.totalPages,
18
+ baseUrl: options.baseUrl || "/posts/page/",
19
+ });
20
+ }
21
+
22
+ export function productsPagination(options: {
23
+ currentPage: number;
24
+ totalPages: number;
25
+ baseUrl?: string;
26
+ }) {
27
+ return paginate({
28
+ currentPage: options.currentPage,
29
+ totalPages: options.totalPages,
30
+ baseUrl: options.baseUrl || "/products/page/",
31
+ });
32
+ }
33
+
34
+ export function productBreadcrumbs(product?: TProduct) {
35
+ // 生成面包屑
36
+ const breadcrumbs: TBreadcrumbItem[] = [
37
+ { title: "Home", href: "/" },
38
+ { title: "Products", href: "/products/page/1" },
39
+ ];
40
+
41
+ const category = product?.category;
42
+ if (category?.name) {
43
+ breadcrumbs.push({
44
+ title: category.name,
45
+ href: `/products/categories/${category.slug}/1`,
46
+ });
47
+ }
48
+
49
+ breadcrumbs.push({ title: product?.title || "Product" });
50
+
51
+ return breadcrumbs;
52
+ }
53
+
54
+ export function productListBreadcrumbs(category?: TProductCategory | null) {
55
+ // 生成面包屑
56
+ const breadcrumbs: TBreadcrumbItem[] = [
57
+ { title: "Home", href: "/" },
58
+ { title: "Products", href: "/products/page/1" },
59
+ ];
60
+ if (category?.name) {
61
+ breadcrumbs.push({
62
+ title: category.name,
63
+ });
64
+ }
65
+ return breadcrumbs;
66
+ }
67
+
68
+ export function postBreadcrumbs(post?: TPost) {
69
+ // 生成面包屑
70
+ const breadcrumbs: TBreadcrumbItem[] = [
71
+ { title: "Home", href: "/" },
72
+ { title: "Posts", href: "/posts/page/1" },
73
+ ];
74
+
75
+ const category = post?.category;
76
+ if (category?.name) {
77
+ breadcrumbs.push({
78
+ title: category.name,
79
+ href: `/posts/categories/${category.slug}/1`,
80
+ });
81
+ }
82
+
83
+ breadcrumbs.push({ title: post?.title || "Post" });
84
+
85
+ return breadcrumbs;
86
+ }
87
+
88
+ export function postListBreadcrumbs(category?: TPostCategory) {
89
+ // 生成面包屑
90
+ const breadcrumbs: TBreadcrumbItem[] = [
91
+ { title: "Home", href: "/" },
92
+ { title: "Blog", href: "/posts/page/1" },
93
+ ];
94
+ if (category?.name) {
95
+ breadcrumbs.push({
96
+ title: category.name,
97
+ });
98
+ }
99
+ return breadcrumbs;
100
+ }
101
+
102
+ export function pageBreadcrumbs(title: string) {
103
+ // 生成面包屑
104
+ const breadcrumbs: TBreadcrumbItem[] = [
105
+ { title: "Home", href: "/" },
106
+ { title },
107
+ ];
108
+ return breadcrumbs;
109
+ }
110
+
111
+ export const rxPage = {
112
+ postsPagination,
113
+ productsPagination,
114
+ postBreadcrumbs,
115
+ postListBreadcrumbs,
116
+ breadcrumbs: pageBreadcrumbs,
117
+ productBreadcrumbs,
118
+ productListBreadcrumbs,
119
+ };