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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@danielres/svelte-dageditor

v0.0.5

Published

An advanced editable DAG (directed acyclic graph) component for Svelte[Kit].

Downloads

9

Readme

@danielres/svelte-dageditor

An advanced editable DAG (directed acyclic graph) component for Svelte[Kit].

This is basically a treeview of interconnected nodes, with the ability to add, remove, rename, delete, and move nodes around. The major difference with a traditional tree structure, is that nodes can have multiple parents.

This allows to create flexible multi-dimensional datastructures/taxonomies/classification systems beyond the limitations of the more common flat or tree-like structures.

  • No extra dependencies
  • Written in TypeScript
  • Supports Svelte 3 and SvelteKit
  • Provides undo/redo
  • Uses (svelte native) drag and drop
  • Comes with default styles (copy them to your project and customize them as you wish)
  • 9Kb (unpacked, all included)

Disclaimer

This is an early alpha version, seems to work well. But it is not yet ready for production use. Major breaking changes are expected.

Installation

npm install @danielres/svelte-dageditor

or

pnpm install @danielres/svelte-dageditor

or

yarn add @danielres/svelte-dageditor

Example usage

<script>
  // import editable DAG tree logic (stores, commands, etc.):
  import { makeDagStore } from '@danielres/svelte-dageditor'

  // import the Tree component:
  import { Tree } from '@danielres/svelte-dageditor'

  // import default styles:
  import '@danielres/svelte-dageditor/dist/styles.css'

  import { onMount } from 'svelte'

  // Provide nodes and relations (could be fetched from a server / db):
  const data = {
    nodes: [
      { name: '<root>', id: '<root>' },
      { name: 'tag1', id: 'tag1' },
      { name: 'tag2', id: 'tag2' },
    ],
    relations: [
      { id: 'aaa', parentId: '<root>', childId: 'tag1' },
      { id: 'aaa', parentId: '<root>', childId: 'tag2' },
    ],
  }

  // Generate the editable tree stores
  // The first argument ("<root>" in this example) should be the
  // id of the node that we wish to use as the root:
  const dag = makeDagStore('<root>', data.nodes, data.relations)

  const { commands } = dag

  // Optional: use undo/redo features
  // Optional: get the undos/redos counts
  // Optional: get the history store containing executed commands
  const { undo, redo, undos, redos, history } = commands

  onMount(() => {
    // All actions that can be done through the UI are also available programmatically.
    // Example: execute some commands:
    commands.rename({ id: 'tag1', to: 'tag1-renamed' })
    commands.rename({ id: 'tag2', to: 'tag2-renamed' })
    commands.move({ id: 'tag2', from: '<root>', to: 'tag1' })
  })
</script>

<div class="flex justify-between items-center">
  <div class="flex items-center gap-2">
    <button on:click={undo} disabled={!$undos}>Undo ({$undos})</button>
    <button on:click={redo} disabled={!$redos}>Redo ({$redos})</button>
  </div>
</div>

<div class="grid grid-cols-2">
  <main class="py-4 px-8 grid gap-8 h-fit">
    <!-- The DAG rendered as an editable tree -->
    <!-- root={true} allows to render the root node differently  -->
    <Tree {dag} root={true} />
  </main>
</div>

<!-- Optional: inspect the internals (commands, history) -->
<div>
  <h2>Commands:</h2>
  <pre>{JSON.stringify($commands, null, 2)}</pre>

  <h2>History:</h2>
  <pre>{JSON.stringify($history, null, 2)}</pre>
</div>

<style lang="postcss">
  button {
    @apply text-sm text-gray-600 bg-gray-200 rounded opacity-75;
    @apply px-2 py-1;
    @apply transition-opacity;
  }
  button:disabled {
    @apply opacity-25;
  }
  button:not(:disabled) {
    @apply cursor-pointer;
  }
  button:not(:disabled):hover {
    @apply opacity-100;
  }
</style>