-
-
Notifications
You must be signed in to change notification settings - Fork 47
feat: add SvelteKit wrapper and documentation #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Divine-P-77777
wants to merge
3
commits into
AOSSIE-Org:main
Choose a base branch
from
Divine-P-77777:feat/svelte-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <!-- Svelte 4 + 5 compat: disable runes so export-let props work in both versions --> | ||
| <svelte:options runes={false} /> | ||
|
|
||
| <script> | ||
| import { onMount, onDestroy } from 'svelte'; | ||
|
|
||
| export let url = ''; | ||
| export let title = ''; | ||
| export let description = ''; | ||
| export let hashtags = []; | ||
| export let via = ''; | ||
| export let platforms = ['whatsapp', 'facebook', 'twitter', 'linkedin', 'telegram', 'reddit', 'pinterest']; | ||
| export let theme = 'dark'; | ||
| export let buttonText = 'Share'; | ||
| export let customClass = ''; | ||
| export let onShare = null; | ||
| export let onCopy = null; | ||
| export let buttonStyle = 'default'; | ||
| export let modalPosition = 'center'; | ||
| // Analytics — the library itself never collects data. | ||
| // Provide any combination to connect your own analytics tools. | ||
| export let analytics = true; // set to false to disable all event emission | ||
| export let onAnalytics = null; // (payload) => void — direct callback hook | ||
| export let analyticsPlugins = []; // array of adapter instances (see social-share-analytics.js) | ||
| export let componentId = null; // optional string identifier for this instance | ||
| export let debug = false; // log events to console during development | ||
|
Divine-P-77777 marked this conversation as resolved.
|
||
|
|
||
| let container; | ||
| let shareButton = null; | ||
|
|
||
| onMount(() => { | ||
| // SSR guard — SvelteKit pre-renders on the server where window is undefined | ||
| if (typeof window === 'undefined') return; | ||
|
|
||
| if (!window.SocialShareButton) { | ||
| // CDN script may not have loaded yet (network error or ad blocker) | ||
| console.warn('[SocialShareButton] window.SocialShareButton not found. Ensure the CDN script is loaded in app.html before this component mounts.'); | ||
| return; | ||
|
Divine-P-77777 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (container) { | ||
| shareButton = new window.SocialShareButton({ | ||
| container, | ||
| url: url || window.location.href, | ||
| title: title || document.title, | ||
| description, | ||
| hashtags, | ||
| via, | ||
| platforms, | ||
| theme, | ||
| buttonText, | ||
| customClass, | ||
| onShare, | ||
| onCopy, | ||
| buttonStyle, | ||
| modalPosition, | ||
| analytics, | ||
| onAnalytics, | ||
| analyticsPlugins, | ||
| componentId, | ||
| debug, | ||
| }); | ||
| } | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| onDestroy(() => { | ||
| if (shareButton) { | ||
| shareButton.destroy(); | ||
| shareButton = null; | ||
| } | ||
| }); | ||
|
|
||
| // Reactive update — re-runs whenever any prop changes (e.g. SvelteKit route transitions). | ||
| // Without this, the share URL stays stale after client-side navigation. | ||
| $: if (shareButton) { | ||
| shareButton.updateOptions({ | ||
| url: url || (typeof window !== 'undefined' ? window.location.href : ''), | ||
| title: title || (typeof document !== 'undefined' ? document.title : ''), | ||
| description, | ||
| hashtags, | ||
| via, | ||
| platforms, | ||
| theme, | ||
| buttonText, | ||
| customClass, | ||
| onShare, | ||
| onCopy, | ||
| buttonStyle, | ||
| modalPosition, | ||
| analytics, | ||
| onAnalytics, | ||
| analyticsPlugins, | ||
| componentId, | ||
| debug, | ||
| }); | ||
| } | ||
| </script> | ||
|
|
||
| <div bind:this={container}></div> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.