@rxdrag/website-lib-core 0.0.127 → 0.0.128
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/README.md +1 -1
- package/index.ts +1 -1
- package/package.json +4 -4
- package/src/astro/animation.ts +146 -146
- package/src/astro/background.ts +82 -86
- package/src/astro/base.ts +7 -0
- package/src/astro/business.ts +13 -0
- package/src/astro/grid/consts.ts +80 -80
- package/src/astro/grid/index.ts +2 -2
- package/src/astro/grid/types.ts +35 -35
- package/src/astro/image.ts +239 -239
- package/src/astro/index.ts +12 -10
- package/src/astro/link.ts +20 -21
- package/src/astro/media.ts +123 -123
- package/src/astro/nav.ts +13 -13
- package/src/astro/section/index.ts +7 -12
- package/src/component-logic/index.ts +1 -1
- package/src/component-logic/link-client.ts +32 -32
- package/src/component-logic/link.ts +61 -61
- package/src/design-tokens.ts +160 -160
- package/src/entify/Entify.ts +533 -530
- package/src/entify/IEntify.ts +151 -177
- package/src/entify/index.ts +4 -4
- package/src/entify/lib/collectCategoryIds.ts +20 -20
- package/src/entify/lib/fulltextSearch.ts +63 -62
- package/src/entify/lib/langFields.ts +14 -14
- package/src/entify/lib/listToTree.ts +23 -23
- package/src/entify/lib/newAvatarQueryOptions.ts +4 -4
- package/src/entify/lib/newOgImageQueryOptions.ts +5 -5
- package/src/entify/lib/newQueryPostOptions.ts +42 -45
- package/src/entify/lib/newQueryProductOptions.ts +96 -98
- package/src/entify/lib/newQueryProductsMediaOptions.ts +28 -28
- package/src/entify/lib/queryAllProducts.ts +40 -40
- package/src/entify/lib/queryBulletin.ts +28 -16
- package/src/entify/lib/queryEntityList.ts +41 -41
- package/src/entify/lib/queryFeaturedProducts.ts +69 -68
- package/src/entify/lib/queryLangs.ts +36 -60
- package/src/entify/lib/queryLatestPosts.ts +92 -91
- package/src/entify/lib/queryOneEntity.ts +63 -63
- package/src/entify/lib/queryOneMedia.ts +27 -27
- package/src/entify/lib/queryOnePostById.ts +21 -21
- package/src/entify/lib/queryOnePostBySlug.ts +40 -39
- package/src/entify/lib/queryOnePostCategoryBySlug.ts +35 -35
- package/src/entify/lib/queryOneProductById.ts +20 -20
- package/src/entify/lib/queryOneProductBySlug.ts +53 -52
- package/src/entify/lib/queryOneProductCategoryBySlug.ts +50 -49
- package/src/entify/lib/queryOneTheme.ts +54 -72
- package/src/entify/lib/queryOneUser.ts +38 -38
- package/src/entify/lib/queryPostCategories.ts +67 -67
- package/src/entify/lib/queryPostSlugs.ts +37 -37
- package/src/entify/lib/queryPosts.ts +175 -174
- package/src/entify/lib/queryProductCategories.ts +59 -59
- package/src/entify/lib/queryProducts.ts +145 -144
- package/src/entify/lib/queryProductsInMenu.ts +45 -45
- package/src/entify/lib/queryTagCategories.ts +58 -58
- package/src/entify/lib/queryTags.ts +57 -57
- package/src/entify/lib/queryUserIds.ts +24 -24
- package/src/entify/lib/queryUserPosts.ts +80 -79
- package/src/entify/lib/queryWebSiteSettings.ts +28 -28
- package/src/entify/lib/queryWebsite.ts +43 -43
- package/src/entify/lib/sendEmail.ts +7 -7
- package/src/entify/lib/toQueryOptions.ts +19 -19
- package/src/entify/lib/upsertEntity.ts +8 -8
- package/src/entify/types/index.ts +1 -1
- package/src/entify/types/utils.ts +11 -6
- package/src/entify/types/variables.ts +5 -6
- package/src/entify/view-model/funcs.ts +230 -230
- package/src/entify/view-model/index.ts +1 -1
- package/src/entify/view-model/models.ts +135 -135
- package/src/global.d.ts +7 -7
- package/src/index.ts +8 -8
- package/src/lib/formatDate.ts +15 -15
- package/src/lib/index.ts +3 -3
- package/src/lib/pagination.ts +114 -114
- package/src/lib/utils.ts +135 -135
- package/src/react/components/Analytics/eventHandlers.ts +173 -173
- package/src/react/components/Analytics/index.tsx +21 -21
- package/src/react/components/Analytics/singleton.ts +214 -214
- package/src/react/components/Analytics/tracking.ts +221 -221
- package/src/react/components/Analytics/types.ts +60 -60
- package/src/react/components/Analytics/utils.ts +95 -95
- package/src/react/components/AttachmentIcon/index.tsx +53 -53
- package/src/react/components/BackgroundHlsVideoPlayer.tsx +97 -97
- package/src/react/components/BackgroundVideoPlayer.tsx +32 -32
- package/src/react/components/Bulletin.tsx +30 -30
- package/src/react/components/ContactForm/ContactForm.tsx +289 -289
- package/src/react/components/ContactForm/Input.tsx +48 -48
- package/src/react/components/ContactForm/Input2.tsx +59 -59
- package/src/react/components/ContactForm/Submit.tsx +48 -48
- package/src/react/components/ContactForm/TelInput.tsx +215 -215
- package/src/react/components/ContactForm/Textarea.tsx +48 -48
- package/src/react/components/ContactForm/Textarea2.tsx +89 -89
- package/src/react/components/ContactForm/funcs.ts +64 -64
- package/src/react/components/ContactForm/index.ts +7 -7
- package/src/react/components/ContactForm/types.ts +68 -68
- package/src/react/components/GoogleConsent/CookieItemPanel.tsx +80 -80
- package/src/react/components/GoogleConsent/CumtomizedModal.tsx +148 -148
- package/src/react/components/GoogleConsent/GoogleConsent.tsx +100 -100
- package/src/react/components/GoogleConsent/gtags.ts +67 -67
- package/src/react/components/GoogleConsent/index.ts +2 -2
- package/src/react/components/GoogleConsent/types.ts +18 -18
- package/src/react/components/GoogleConsent//345/217/202/350/200/203.md +4 -4
- package/src/react/components/Icon/index.tsx +19 -19
- package/src/react/components/Medias/MainMedia.tsx +257 -257
- package/src/react/components/Medias/Thumbnail.tsx +62 -62
- package/src/react/components/Medias/VideoPlayer.tsx +114 -114
- package/src/react/components/Medias/index.tsx +271 -271
- package/src/react/components/ProductCard/ProductCard.tsx +24 -24
- package/src/react/components/ProductCard/ProductCta/index.tsx +28 -28
- package/src/react/components/ProductCard/ProductCta/style.css +3 -3
- package/src/react/components/ProductCard/ProductDescription/index.tsx +12 -12
- package/src/react/components/ProductCard/ProductDescription/style.css +5 -5
- package/src/react/components/ProductCard/ProductMedia/index.tsx +35 -35
- package/src/react/components/ProductCard/ProductMedia/style.css +5 -5
- package/src/react/components/ProductCard/ProductTitle/index.tsx +7 -7
- package/src/react/components/ProductCard/ProductTitle/style.css +3 -3
- package/src/react/components/ProductCard/ProductView.tsx +36 -36
- package/src/react/components/ProductCard/index.ts +4 -4
- package/src/react/components/ProductCard/useQueryProduct.ts +32 -32
- package/src/react/components/ReactModalTrigger.tsx +28 -28
- package/src/react/components/ReactVideoPlayer.tsx +29 -52
- package/src/react/components/RichTextOutline/index.tsx +75 -75
- package/src/react/components/RichTextOutline/useAnchorScroll.ts +23 -23
- package/src/react/components/Scroller.tsx +39 -39
- package/src/react/components/SearchInput.tsx +21 -21
- package/src/react/components/Share/index.tsx +86 -86
- package/src/react/components/Share/socials.tsx +79 -77
- package/src/react/components/Share//350/265/204/346/226/231.md +7 -7
- package/src/react/components/ToTop.tsx +72 -72
- package/src/react/components/VideoPlayIcon.tsx +43 -0
- package/src/react/components/all.ts +38 -38
- package/src/react/components/index.ts +16 -16
- package/src/robots.ts +4 -4
- package/src/entify/lib/newPageMetaOptions.ts +0 -18
- package/src/entify/lib/newQueryPageOptions.ts +0 -14
- package/src/entify/lib/queryOneIcon.ts +0 -27
- package/src/entify/lib/queryPageBySlug.ts +0 -43
- package/src/entify/lib/queryPageByType.ts +0 -44
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { extractOutlineFromTiptap, mdxToTiptap } from "@rxdrag/tiptap-preview";
|
|
2
|
-
import { forwardRef, 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 = 200, ...rest } = props;
|
|
20
|
-
const activiedId = useAcitviedHeading(yOffset);
|
|
21
|
-
const doc = mdxToTiptap(value ?? "");
|
|
22
|
-
const outline = extractOutlineFromTiptap(doc);
|
|
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
|
-
}, [yOffset]);
|
|
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 y =
|
|
61
|
-
element.getBoundingClientRect().top +
|
|
62
|
-
window.scrollY +
|
|
63
|
-
yOffset;
|
|
64
|
-
window.scrollTo({ top: y, behavior: "smooth" });
|
|
65
|
-
}
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
{item?.text}
|
|
69
|
-
</a>
|
|
70
|
-
</li>
|
|
71
|
-
);
|
|
72
|
-
})}
|
|
73
|
-
</ul>
|
|
74
|
-
) : null;
|
|
75
|
-
});
|
|
1
|
+
import { extractOutlineFromTiptap, mdxToTiptap } from "@rxdrag/tiptap-preview";
|
|
2
|
+
import { forwardRef, 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 = 200, ...rest } = props;
|
|
20
|
+
const activiedId = useAcitviedHeading(yOffset);
|
|
21
|
+
const doc = mdxToTiptap(value ?? "");
|
|
22
|
+
const outline = extractOutlineFromTiptap(doc);
|
|
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
|
+
}, [yOffset]);
|
|
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 y =
|
|
61
|
+
element.getBoundingClientRect().top +
|
|
62
|
+
window.scrollY +
|
|
63
|
+
yOffset;
|
|
64
|
+
window.scrollTo({ top: y, behavior: "smooth" });
|
|
65
|
+
}
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
{item?.text}
|
|
69
|
+
</a>
|
|
70
|
+
</li>
|
|
71
|
+
);
|
|
72
|
+
})}
|
|
73
|
+
</ul>
|
|
74
|
+
) : null;
|
|
75
|
+
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { useCallback, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
export function useAnchorScroll() {
|
|
4
|
-
const handleAnchorClick = useCallback((event: MouseEvent): void => {
|
|
5
|
-
const target = event.target as HTMLAnchorElement;
|
|
6
|
-
if (target.tagName === 'A' && target.getAttribute('href')?.startsWith('#')) {
|
|
7
|
-
event.preventDefault();
|
|
8
|
-
const id = target.getAttribute('href')?.slice(1);
|
|
9
|
-
const element = document.getElementById(id || '');
|
|
10
|
-
if (element) {
|
|
11
|
-
const yOffset = -100; // 假设你想要元素距离顶部100px
|
|
12
|
-
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
|
13
|
-
window.scrollTo({ top: y, behavior: 'smooth' });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}, []);
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
document.addEventListener('click', handleAnchorClick);
|
|
20
|
-
return () => document.removeEventListener('click', handleAnchorClick);
|
|
21
|
-
}, [handleAnchorClick]);
|
|
22
|
-
}
|
|
23
|
-
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useAnchorScroll() {
|
|
4
|
+
const handleAnchorClick = useCallback((event: MouseEvent): void => {
|
|
5
|
+
const target = event.target as HTMLAnchorElement;
|
|
6
|
+
if (target.tagName === 'A' && target.getAttribute('href')?.startsWith('#')) {
|
|
7
|
+
event.preventDefault();
|
|
8
|
+
const id = target.getAttribute('href')?.slice(1);
|
|
9
|
+
const element = document.getElementById(id || '');
|
|
10
|
+
if (element) {
|
|
11
|
+
const yOffset = -100; // 假设你想要元素距离顶部100px
|
|
12
|
+
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
|
13
|
+
window.scrollTo({ top: y, behavior: 'smooth' });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
document.addEventListener('click', handleAnchorClick);
|
|
20
|
+
return () => document.removeEventListener('click', handleAnchorClick);
|
|
21
|
+
}, [handleAnchorClick]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
24
|
export default useAnchorScroll;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
|
|
3
|
-
export const defaultThreshold = 10;
|
|
4
|
-
|
|
5
|
-
export type ScrollerProps = {
|
|
6
|
-
threshold?: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export function Scroller(props: ScrollerProps) {
|
|
10
|
-
const { threshold = defaultThreshold } = props;
|
|
11
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
12
|
-
const [win, setWin] = useState<Window | null>(null);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (ref.current) {
|
|
16
|
-
setWin(ref.current.ownerDocument.defaultView);
|
|
17
|
-
}
|
|
18
|
-
}, []);
|
|
19
|
-
|
|
20
|
-
const onScroll = useCallback(() => {
|
|
21
|
-
if (!win) return;
|
|
22
|
-
const scrolled = win.scrollY > threshold;
|
|
23
|
-
const doc = win.document;
|
|
24
|
-
|
|
25
|
-
if (scrolled) {
|
|
26
|
-
doc.body.classList.add("scrolled");
|
|
27
|
-
} else {
|
|
28
|
-
doc.body.classList.remove("scrolled");
|
|
29
|
-
}
|
|
30
|
-
}, [threshold, win]);
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!win) return;
|
|
34
|
-
win.addEventListener("scroll", onScroll);
|
|
35
|
-
return () => win.removeEventListener("scroll", onScroll);
|
|
36
|
-
}, [onScroll, win]);
|
|
37
|
-
|
|
38
|
-
return <div ref={ref} style={{ display: "none" }} />;
|
|
39
|
-
}
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export const defaultThreshold = 10;
|
|
4
|
+
|
|
5
|
+
export type ScrollerProps = {
|
|
6
|
+
threshold?: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function Scroller(props: ScrollerProps) {
|
|
10
|
+
const { threshold = defaultThreshold } = props;
|
|
11
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
12
|
+
const [win, setWin] = useState<Window | null>(null);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (ref.current) {
|
|
16
|
+
setWin(ref.current.ownerDocument.defaultView);
|
|
17
|
+
}
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
const onScroll = useCallback(() => {
|
|
21
|
+
if (!win) return;
|
|
22
|
+
const scrolled = win.scrollY > threshold;
|
|
23
|
+
const doc = win.document;
|
|
24
|
+
|
|
25
|
+
if (scrolled) {
|
|
26
|
+
doc.body.classList.add("scrolled");
|
|
27
|
+
} else {
|
|
28
|
+
doc.body.classList.remove("scrolled");
|
|
29
|
+
}
|
|
30
|
+
}, [threshold, win]);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!win) return;
|
|
34
|
+
win.addEventListener("scroll", onScroll);
|
|
35
|
+
return () => win.removeEventListener("scroll", onScroll);
|
|
36
|
+
}, [onScroll, win]);
|
|
37
|
+
|
|
38
|
+
return <div ref={ref} style={{ display: "none" }} />;
|
|
39
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
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
|
-
return (
|
|
12
|
-
<input
|
|
13
|
-
ref={ref}
|
|
14
|
-
name="q"
|
|
15
|
-
value={keyword}
|
|
16
|
-
onChange={(e) => setKeyword(e.target.value)}
|
|
17
|
-
{...rest}
|
|
18
|
-
/>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
);
|
|
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
|
+
return (
|
|
12
|
+
<input
|
|
13
|
+
ref={ref}
|
|
14
|
+
name="q"
|
|
15
|
+
value={keyword}
|
|
16
|
+
onChange={(e) => setKeyword(e.target.value)}
|
|
17
|
+
{...rest}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
);
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useState } from "react";
|
|
2
|
-
import type { IconListType } from "./socials";
|
|
3
|
-
import { iconList } from "./socials";
|
|
4
|
-
import clsx from "clsx";
|
|
5
|
-
|
|
6
|
-
export type ShareProps = {
|
|
7
|
-
socials?: string[];
|
|
8
|
-
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
9
|
-
className?: string;
|
|
10
|
-
classNames?: {
|
|
11
|
-
item?: string;
|
|
12
|
-
itemIcon?: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function getPageDetails() {
|
|
17
|
-
if (typeof window === "undefined") {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const details = {
|
|
21
|
-
url: window?.location?.href,
|
|
22
|
-
title: document?.title || "null",
|
|
23
|
-
description: "null", // 默认为空字符串
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const descriptionMetaTag = document.querySelector('meta[name="description"]');
|
|
27
|
-
if (descriptionMetaTag) {
|
|
28
|
-
details.description = (descriptionMetaTag as HTMLMetaElement).content;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return details;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const Share = forwardRef<HTMLDivElement, ShareProps>(
|
|
35
|
-
(props: ShareProps, ref) => {
|
|
36
|
-
const { className, classNames, ...rest } = props;
|
|
37
|
-
const [socialList, setSolicalList] = useState<IconListType>();
|
|
38
|
-
|
|
39
|
-
const details = getPageDetails();
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
setSolicalList(iconList);
|
|
43
|
-
}, [props.socials]);
|
|
44
|
-
|
|
45
|
-
// 生成每个社交媒体的分享链接
|
|
46
|
-
const generateLink = (key: string) => {
|
|
47
|
-
const social = iconList[key];
|
|
48
|
-
if (!social) return "#";
|
|
49
|
-
return social.url(
|
|
50
|
-
details?.url || "",
|
|
51
|
-
details?.title,
|
|
52
|
-
details?.description
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div ref={ref} className={clsx("flex items-center", className)} {...rest}>
|
|
58
|
-
<div className="flex space-x-3">
|
|
59
|
-
{Object.keys(socialList || {}).map((key) => (
|
|
60
|
-
<a
|
|
61
|
-
key={key}
|
|
62
|
-
href={generateLink(key)}
|
|
63
|
-
target="_blank"
|
|
64
|
-
rel="noopener noreferrer"
|
|
65
|
-
title={`Share on ${iconList[key].title}`}
|
|
66
|
-
className={clsx(
|
|
67
|
-
"flex h-6 w-6 items-center justify-center ",
|
|
68
|
-
classNames?.item
|
|
69
|
-
)}
|
|
70
|
-
>
|
|
71
|
-
<svg
|
|
72
|
-
className={clsx("w-5 h-5", classNames?.itemIcon)}
|
|
73
|
-
fill="currentColor"
|
|
74
|
-
viewBox="0 0 24 24"
|
|
75
|
-
focusable="false"
|
|
76
|
-
aria-hidden="true"
|
|
77
|
-
>
|
|
78
|
-
{iconList[key].path}
|
|
79
|
-
</svg>
|
|
80
|
-
</a>
|
|
81
|
-
))}
|
|
82
|
-
</div>
|
|
83
|
-
</div>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
);
|
|
1
|
+
import { forwardRef, useEffect, useState } from "react";
|
|
2
|
+
import type { IconListType } from "./socials";
|
|
3
|
+
import { iconList } from "./socials";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
|
|
6
|
+
export type ShareProps = {
|
|
7
|
+
socials?: string[];
|
|
8
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl";
|
|
9
|
+
className?: string;
|
|
10
|
+
classNames?: {
|
|
11
|
+
item?: string;
|
|
12
|
+
itemIcon?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function getPageDetails() {
|
|
17
|
+
if (typeof window === "undefined") {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const details = {
|
|
21
|
+
url: window?.location?.href,
|
|
22
|
+
title: document?.title || "null",
|
|
23
|
+
description: "null", // 默认为空字符串
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const descriptionMetaTag = document.querySelector('meta[name="description"]');
|
|
27
|
+
if (descriptionMetaTag) {
|
|
28
|
+
details.description = (descriptionMetaTag as HTMLMetaElement).content;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return details;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Share = forwardRef<HTMLDivElement, ShareProps>(
|
|
35
|
+
(props: ShareProps, ref) => {
|
|
36
|
+
const { className, classNames, ...rest } = props;
|
|
37
|
+
const [socialList, setSolicalList] = useState<IconListType>();
|
|
38
|
+
|
|
39
|
+
const details = getPageDetails();
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setSolicalList(iconList);
|
|
43
|
+
}, [props.socials]);
|
|
44
|
+
|
|
45
|
+
// 生成每个社交媒体的分享链接
|
|
46
|
+
const generateLink = (key: string) => {
|
|
47
|
+
const social = iconList[key];
|
|
48
|
+
if (!social) return "#";
|
|
49
|
+
return social.url(
|
|
50
|
+
details?.url || "",
|
|
51
|
+
details?.title,
|
|
52
|
+
details?.description
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div ref={ref} className={clsx("flex items-center", className)} {...rest}>
|
|
58
|
+
<div className="flex space-x-3">
|
|
59
|
+
{Object.keys(socialList || {}).map((key) => (
|
|
60
|
+
<a
|
|
61
|
+
key={key}
|
|
62
|
+
href={generateLink(key)}
|
|
63
|
+
target="_blank"
|
|
64
|
+
rel="noopener noreferrer"
|
|
65
|
+
title={`Share on ${iconList[key].title}`}
|
|
66
|
+
className={clsx(
|
|
67
|
+
"flex h-6 w-6 items-center justify-center ",
|
|
68
|
+
classNames?.item
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
<svg
|
|
72
|
+
className={clsx("w-5 h-5", classNames?.itemIcon)}
|
|
73
|
+
fill="currentColor"
|
|
74
|
+
viewBox="0 0 24 24"
|
|
75
|
+
focusable="false"
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
>
|
|
78
|
+
{iconList[key].path}
|
|
79
|
+
</svg>
|
|
80
|
+
</a>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
);
|