npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@servlyadmin/runtime-svelte

v0.1.50

Published

Svelte wrapper for Servly runtime renderer

Downloads

1,926

Readme

@servlyadmin/runtime-svelte

Svelte wrapper for Servly runtime renderer. Render Servly components in your Svelte 5 applications with full slot support, state management, and reactive updates.

Installation

npm install @servlyadmin/runtime-svelte
# or
yarn add @servlyadmin/runtime-svelte
# or
pnpm add @servlyadmin/runtime-svelte

Requirements

  • Svelte 5.0.0 or higher
  • @servlyadmin/runtime-core (installed automatically)

Quick Start

<script lang="ts">
  import { ServlyComponent } from '@servlyadmin/runtime-svelte';
</script>

<!-- That's it! Components are fetched from Servly's registry automatically -->
<ServlyComponent
  id="my-component-id"
  props={{ title: 'Hello World' }}
/>

Registry & Caching

Default Registry

Components are fetched from Servly's production registry by default:

  • URL: https://core-api.servly.app/v1/views/registry

To use a custom registry:

import { setRegistryUrl } from '@servlyadmin/runtime-svelte';

setRegistryUrl('https://your-api.com/v1/views/registry');

Cache Strategies

The runtime supports three caching strategies:

| Strategy | Description | Persistence | Best For | |----------|-------------|-------------|----------| | localStorage | Persists across browser sessions | Yes | Production (default) | | memory | In-memory cache, cleared on refresh | No | Development, SSR | | none | No caching, always fetches fresh | No | Testing, debugging |

<!-- Default: localStorage caching -->
<ServlyComponent id="my-component" />

<!-- Explicit cache strategy -->
<ServlyComponent id="my-component" cacheStrategy="memory" />

<!-- No caching -->
<ServlyComponent id="my-component" cacheStrategy="none" />

API Reference

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | id | string | required | Component ID from the registry | | version | string | 'latest' | Version specifier | | props | object | {} | Props to pass to the component | | cacheStrategy | 'localStorage' \| 'memory' \| 'none' | 'localStorage' | Caching strategy | | retryConfig | object | undefined | Retry configuration | | eventHandlers | object | undefined | Event handlers keyed by element ID | | showSkeleton | boolean | true | Show loading skeleton | | enableStateManager | boolean | false | Enable state management | | initialState | object | undefined | Initial state | | slotContent | Record<string, HTMLElement> | {} | Programmatic slot content |

Callbacks

| Callback | Type | Description | |----------|------|-------------| | onload | (data: ComponentData) => void | Called on successful load | | onerror | (error: Error) => void | Called on load failure | | onready | () => void | Called when fully rendered | | onstatechange | (event: StateChangeEvent) => void | Called on state change |

<script lang="ts">
  import { ServlyComponent } from '@servlyadmin/runtime-svelte';

  function handleLoad(data) {
    console.log('Component loaded:', data);
  }

  function handleError(error) {
    console.error('Failed to load:', error);
  }
</script>

<ServlyComponent
  id="my-component"
  onload={handleLoad}
  onerror={handleError}
/>

Advanced Usage

With State Management

<script lang="ts">
  import { ServlyComponent } from '@servlyadmin/runtime-svelte';

  let count = $state(0);

  function handleStateChange(event) {
    if (event.path === 'count') {
      count = event.value;
    }
  }
</script>

<ServlyComponent
  id="counter-component"
  props={{ count }}
  enableStateManager={true}
  initialState={{ count: 0 }}
  onstatechange={handleStateChange}
/>

<p>Count: {count}</p>

With Event Handlers

<script lang="ts">
  import { ServlyComponent } from '@servlyadmin/runtime-svelte';

  const handlers = {
    'submit-btn': {
      click: (event) => {
        console.log('Submit clicked!');
      },
    },
    'email-input': {
      change: (event) => {
        console.log('Email:', event.target.value);
      },
    },
  };
</script>

<ServlyComponent
  id="form-component"
  eventHandlers={handlers}
/>

Accessing Component Methods

<script lang="ts">
  import { ServlyComponent } from '@servlyadmin/runtime-svelte';

  let servlyComponent;

  function reload() {
    servlyComponent.reload();
  }

  function updateProps() {
    servlyComponent.update({ newProp: 'value' });
  }
</script>

<ServlyComponent
  bind:this={servlyComponent}
  id="my-component"
/>

<button onclick={reload}>Reload</button>
<button onclick={updateProps}>Update Props</button>

Reactive Props

<script lang="ts">
  import { ServlyComponent } from '@servlyadmin/runtime-svelte';

  let count = $state(0);
  let title = $state('Hello');
</script>

<ServlyComponent
  id="my-component"
  props={{ count, title }}
/>

<button onclick={() => count++}>Increment</button>
<input bind:value={title} />

Version Specifiers

<!-- Exact version -->
<ServlyComponent id="my-component" version="1.2.3" />

<!-- Caret range (compatible with) -->
<ServlyComponent id="my-component" version="^1.0.0" />

<!-- Tilde range (approximately) -->
<ServlyComponent id="my-component" version="~1.2.0" />

<!-- Latest version (default) -->
<ServlyComponent id="my-component" />

Exported Methods

The ServlyComponent exposes these methods via bind:this:

| Method | Description | |--------|-------------| | reload() | Reload the component from registry | | update(props) | Update component with new props | | getSlotElement(name) | Get a slot element by name | | getSlotNames() | Get all available slot names | | mountIntoSlot(name, element) | Mount an element into a slot | | getStateManager() | Get the state manager instance |

Re-exported Utilities

import {
  // Fetching
  fetchComponent,
  prefetchComponents,
  setRegistryUrl,
  DEFAULT_REGISTRY_URL,
  
  // Caching
  invalidateCache,
  clearAllCaches,
  
  // State management
  StateManager,
  
  // Event system
  EventSystem,
  getEventSystem,
} from '@servlyadmin/runtime-svelte';

Styling

The component includes default styles for loading and error states:

/* Override default styles */
:global(.servly-skeleton) {
  background-color: #e5e7eb;
  animation: pulse 2s infinite;
}

:global(.servly-error) {
  background-color: #fee2e2;
  color: #dc2626;
}

License

MIT