@wix/headless-stores 0.0.34 → 0.0.35

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.
@@ -1,34 +0,0 @@
1
- import { type Signal } from "@wix/services-definitions/core-services/signals";
2
- export interface SharingPlatform {
3
- name: string;
4
- icon: string;
5
- color: string;
6
- shareUrl: string;
7
- }
8
- export interface SocialSharingServiceAPI {
9
- availablePlatforms: Signal<SharingPlatform[]>;
10
- shareCount: Signal<number>;
11
- lastSharedPlatform: Signal<string | null>;
12
- shareToFacebook: (url: string, title: string, description?: string) => void;
13
- shareToTwitter: (url: string, text: string, hashtags?: string[]) => void;
14
- shareToLinkedIn: (url: string, title: string, summary?: string) => void;
15
- shareToWhatsApp: (url: string, text: string) => void;
16
- shareToEmail: (url: string, subject: string, body: string) => void;
17
- copyToClipboard: (url: string) => Promise<boolean>;
18
- shareNative: (data: {
19
- title: string;
20
- text: string;
21
- url: string;
22
- }) => Promise<boolean>;
23
- trackShare: (platform: string) => void;
24
- }
25
- export declare const SocialSharingServiceDefinition: string & {
26
- __api: SocialSharingServiceAPI;
27
- __config: {};
28
- isServiceDefinition?: boolean;
29
- } & SocialSharingServiceAPI;
30
- export declare const SocialSharingService: import("@wix/services-definitions").ServiceFactory<string & {
31
- __api: SocialSharingServiceAPI;
32
- __config: {};
33
- isServiceDefinition?: boolean;
34
- } & SocialSharingServiceAPI, {}>;
@@ -1,129 +0,0 @@
1
- import { defineService, implementService } from "@wix/services-definitions";
2
- import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
3
- import { SocialPlatform, SocialPlatformShareUrl, } from "../enums/social-platform-enums.js";
4
- export const SocialSharingServiceDefinition = defineService("socialSharing");
5
- export const SocialSharingService = implementService.withConfig()(SocialSharingServiceDefinition, ({ getService }) => {
6
- const signalsService = getService(SignalsServiceDefinition);
7
- // Platform metadata is handled in components layer, only business logic here
8
- const availablePlatforms = signalsService.signal([
9
- {
10
- name: "Facebook",
11
- icon: "facebook",
12
- color: "#1877F2",
13
- shareUrl: SocialPlatformShareUrl.FACEBOOK,
14
- },
15
- {
16
- name: "Twitter",
17
- icon: "twitter",
18
- color: "#1DA1F2",
19
- shareUrl: SocialPlatformShareUrl.TWITTER,
20
- },
21
- {
22
- name: "LinkedIn",
23
- icon: "linkedin",
24
- color: "#0A66C2",
25
- shareUrl: SocialPlatformShareUrl.LINKEDIN,
26
- },
27
- {
28
- name: "WhatsApp",
29
- icon: "whatsapp",
30
- color: "#25D366",
31
- shareUrl: SocialPlatformShareUrl.WHATSAPP,
32
- },
33
- {
34
- name: "Email",
35
- icon: "mail",
36
- color: "#EA4335",
37
- shareUrl: SocialPlatformShareUrl.EMAIL,
38
- },
39
- ]);
40
- const shareCount = signalsService.signal(0);
41
- const lastSharedPlatform = signalsService.signal(null);
42
- const openShareWindow = (url, platform) => {
43
- const width = 600;
44
- const height = 400;
45
- const left = (window.screen.width - width) / 2;
46
- const top = (window.screen.height - height) / 2;
47
- window.open(url, `share-${platform}`, `width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`);
48
- trackShare(platform);
49
- };
50
- const shareToFacebook = (url, title, description) => {
51
- const shareUrl = new URL(SocialPlatformShareUrl.FACEBOOK);
52
- shareUrl.searchParams.set("u", url);
53
- shareUrl.searchParams.set("quote", `${title}${description ? ` - ${description}` : ""}`);
54
- openShareWindow(shareUrl.toString(), SocialPlatform.FACEBOOK);
55
- };
56
- const shareToTwitter = (url, text, hashtags) => {
57
- const shareUrl = new URL(SocialPlatformShareUrl.TWITTER);
58
- shareUrl.searchParams.set("url", url);
59
- shareUrl.searchParams.set("text", text);
60
- if (hashtags && hashtags.length > 0) {
61
- shareUrl.searchParams.set("hashtags", hashtags.join(","));
62
- }
63
- openShareWindow(shareUrl.toString(), SocialPlatform.TWITTER);
64
- };
65
- const shareToLinkedIn = (url, title, summary) => {
66
- const shareUrl = new URL(SocialPlatformShareUrl.LINKEDIN);
67
- shareUrl.searchParams.set("url", url);
68
- shareUrl.searchParams.set("title", title);
69
- if (summary) {
70
- shareUrl.searchParams.set("summary", summary);
71
- }
72
- openShareWindow(shareUrl.toString(), SocialPlatform.LINKEDIN);
73
- };
74
- const shareToWhatsApp = (url, text) => {
75
- const message = `${text} ${url}`;
76
- const shareUrl = `${SocialPlatformShareUrl.WHATSAPP}?text=${encodeURIComponent(message)}`;
77
- openShareWindow(shareUrl, SocialPlatform.WHATSAPP);
78
- };
79
- const shareToEmail = (url, subject, body) => {
80
- const emailBody = `${body}\n\n${url}`;
81
- const mailtoUrl = `${SocialPlatformShareUrl.EMAIL}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(emailBody)}`;
82
- window.location.href = mailtoUrl;
83
- trackShare(SocialPlatform.EMAIL);
84
- };
85
- const copyToClipboard = async (url) => {
86
- try {
87
- await navigator.clipboard.writeText(url);
88
- trackShare(SocialPlatform.CLIPBOARD);
89
- return true;
90
- }
91
- catch (err) {
92
- console.error("Failed to copy to clipboard:", err);
93
- return false;
94
- }
95
- };
96
- const shareNative = async (data) => {
97
- try {
98
- if (navigator.share) {
99
- await navigator.share(data);
100
- trackShare(SocialPlatform.NATIVE);
101
- return true;
102
- }
103
- return false;
104
- }
105
- catch (err) {
106
- console.error("Failed to share natively:", err);
107
- return false;
108
- }
109
- };
110
- const trackShare = (platform) => {
111
- const currentCount = shareCount.get();
112
- shareCount.set(currentCount + 1);
113
- lastSharedPlatform.set(platform);
114
- console.log(`Shared to ${platform} - Total shares: ${currentCount + 1}`);
115
- };
116
- return {
117
- availablePlatforms,
118
- shareCount,
119
- lastSharedPlatform,
120
- shareToFacebook,
121
- shareToTwitter,
122
- shareToLinkedIn,
123
- shareToWhatsApp,
124
- shareToEmail,
125
- copyToClipboard,
126
- shareNative,
127
- trackShare,
128
- };
129
- });