@placeholderco/placeholder-ui 3.0.2 → 3.0.3

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.
@@ -28,6 +28,10 @@
28
28
  iconSize?: string;
29
29
  /** Link target attribute (when href is provided) */
30
30
  target?: undefined | '_self' | '_blank';
31
+ /** Relationship attribute (when href is provided). `rel="external"` skips client-side navigation */
32
+ rel?: string;
33
+ /** Download the linked URL instead of navigating (when href is provided). `true` keeps the server's filename */
34
+ download?: boolean | string;
31
35
  /** Button type attribute (when rendered as a button, not a link) */
32
36
  type?: 'button' | 'submit' | 'reset';
33
37
  /** Additional CSS classes */
@@ -51,6 +55,8 @@
51
55
  rightSvg = undefined,
52
56
  iconSize = '18px',
53
57
  target = undefined,
58
+ rel = undefined,
59
+ download = undefined,
54
60
  type = 'button',
55
61
  class: buttonClass = '',
56
62
  children,
@@ -89,6 +95,8 @@
89
95
  {#if isLink && href && !disabled}
90
96
  <a
91
97
  {target}
98
+ {rel}
99
+ download={download === true ? '' : download || undefined}
92
100
  class={elClass}
93
101
  aria-label={ariaLabel}
94
102
  href={href?.startsWith('/') ? resolve(href as any) : href}
@@ -22,6 +22,10 @@ export interface ButtonProps {
22
22
  iconSize?: string;
23
23
  /** Link target attribute (when href is provided) */
24
24
  target?: undefined | '_self' | '_blank';
25
+ /** Relationship attribute (when href is provided). `rel="external"` skips client-side navigation */
26
+ rel?: string;
27
+ /** Download the linked URL instead of navigating (when href is provided). `true` keeps the server's filename */
28
+ download?: boolean | string;
25
29
  /** Button type attribute (when rendered as a button, not a link) */
26
30
  type?: 'button' | 'submit' | 'reset';
27
31
  /** Additional CSS classes */
@@ -10,6 +10,8 @@
10
10
  rel?: string;
11
11
  /** Link target attribute */
12
12
  target?: '_self' | '_blank' | undefined;
13
+ /** Download the linked URL instead of navigating. `true` keeps the server's filename */
14
+ download?: boolean | string;
13
15
  /** Additional CSS classes */
14
16
  class?: string;
15
17
  /** Link content */
@@ -24,6 +26,7 @@
24
26
  href,
25
27
  rel = '',
26
28
  target = undefined,
29
+ download = undefined,
27
30
  class: classes = '',
28
31
  children,
29
32
  onclick,
@@ -36,6 +39,7 @@
36
39
  class={classes}
37
40
  href={href?.startsWith('/') ? resolve(href as any) : href}
38
41
  {rel}
42
+ download={download === true ? '' : download || undefined}
39
43
  aria-current={ariaCurrent}
40
44
  onclick={(e) => interceptLinkClick(e, { href, target, onclick })}
41
45
  data-sveltekit-preload-data="hover"
@@ -6,6 +6,8 @@ export interface LinkProps {
6
6
  rel?: string;
7
7
  /** Link target attribute */
8
8
  target?: '_self' | '_blank' | undefined;
9
+ /** Download the linked URL instead of navigating. `true` keeps the server's filename */
10
+ download?: boolean | string;
9
11
  /** Additional CSS classes */
10
12
  class?: string;
11
13
  /** Link content */
@@ -242,7 +242,7 @@
242
242
  if (href) {
243
243
  event.preventDefault();
244
244
  if (newTabIntent) window.open(href, '_blank', 'noopener');
245
- else navigateTo(href);
245
+ else navigateTo(href).catch(console.error);
246
246
  }
247
247
  }
248
248
 
@@ -1 +1,6 @@
1
- export declare function navigateTo(url: string): void;
1
+ /**
2
+ * Navigates client-side when the URL is a page route in the app. URLs the client router can't
3
+ * reach (`+server.ts` endpoints, static files, external URLs) fall back to a full browser
4
+ * navigation. Cancelled navigations resolve quietly; any other failure rejects.
5
+ */
6
+ export declare function navigateTo(url: string): Promise<void>;
@@ -1,5 +1,27 @@
1
1
  import { goto } from '$app/navigation';
2
2
  import { resolve } from '$app/paths';
3
- export function navigateTo(url) {
4
- goto(resolve(url));
3
+ // SvelteKit puts the error code in the message in both dev and prod builds
4
+ const FALLBACK_ERRORS = ['/e/kit/navigation_route_missing', '/e/kit/navigation_external_url'];
5
+ // Rejections for navigations superseded by another one, or cancelled via beforeNavigate
6
+ const CANCELLED_ERRORS = ['navigation cancelled', 'navigation aborted'];
7
+ /**
8
+ * Navigates client-side when the URL is a page route in the app. URLs the client router can't
9
+ * reach (`+server.ts` endpoints, static files, external URLs) fall back to a full browser
10
+ * navigation. Cancelled navigations resolve quietly; any other failure rejects.
11
+ */
12
+ export async function navigateTo(url) {
13
+ const resolved = resolve(url);
14
+ try {
15
+ await goto(resolved);
16
+ }
17
+ catch (error) {
18
+ const message = error instanceof Error ? error.message : String(error);
19
+ if (FALLBACK_ERRORS.some((code) => message.includes(code))) {
20
+ window.location.assign(resolved);
21
+ return;
22
+ }
23
+ if (CANCELLED_ERRORS.includes(message))
24
+ return;
25
+ throw error;
26
+ }
5
27
  }
@@ -26,8 +26,25 @@ export function interceptLinkClick(event, options) {
26
26
  if (event.button !== 0) {
27
27
  return;
28
28
  }
29
+ // Honour SvelteKit's standard opt-outs from client-side navigation
30
+ const anchor = event.currentTarget instanceof HTMLAnchorElement ? event.currentTarget : null;
31
+ if (anchor && isClientNavOptOut(anchor)) {
32
+ return;
33
+ }
29
34
  // Prevent default navigation and use SvelteKit's client-side navigation
30
35
  event.preventDefault();
31
- if (href)
32
- navigateTo(href);
36
+ navigateTo(href).catch((error) => {
37
+ console.error(error);
38
+ // The click must still go somewhere, as a plain anchor would
39
+ window.location.assign(anchor?.href ?? href);
40
+ });
41
+ }
42
+ /** `download`, `rel="external"` and `data-sveltekit-reload` (on the link or an ancestor) */
43
+ function isClientNavOptOut(anchor) {
44
+ if (anchor.hasAttribute('download'))
45
+ return true;
46
+ if (anchor.relList.contains('external'))
47
+ return true;
48
+ const reload = anchor.closest('[data-sveltekit-reload]')?.getAttribute('data-sveltekit-reload');
49
+ return reload != null && reload !== 'off';
33
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placeholderco/placeholder-ui",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
5
5
  "license": "MIT",
6
6
  "author": "Placeholderco",