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

vue-simple-drag-resize

v0.0.2

Published

Draggable and resizable component for vue

Downloads

7

Readme

vue DragResize

Inspired by vue-draggable-resizable

Targeted for use with SVG elements but can be used on DOM elements too. This component only handles smooth prop update on mouse move. Transform update is entirely up to your implementation.

Not tested in production!
I couldn't find simple customisable draggable and resizable solution for svg so I gave it a go on my own. My aim was to create something that will handle move and resize logic but the rest of the implementation can be handled elsewhere.

Install

npm i --save vue-simple-drag-resize

Example Usage

<template>
  <svg>
    <DragResize
      :x="x"
      :y="y"
      :width="width"
      :height="height"
      :transform="transform"
      @transform="updateSize"
      @transformEnd="() => (transform = null)"
      @mousedown="transform = 'move'"
    />
  </svg>
</template>
<script>
import { DragResize } from "vue-simple-drag-resize";

export default {
  name: "test",

  data: () => ({
    x: 200,
    y: 60,
    width: 100,
    height: 60,
    transform: null
  }),

  components: { DragResize },

  methods: {
    updateSize(size) {
      this.x = size.x;
      this.y = size.y;
      this.width = size.width;
      this.height = size.height;
    }
  }
};
</script>
<style>
svg {
  width: 100%;
  height: 300px;
}
</style>

Or register as global component using:

  import Vue from 'vue';
  import DragResize from "vue-simple-drag-resize";

  Vue.use(DragResize);

then in your component use directly

<template>
  <drag-resize :x="x" :y="y" :width="width" :height="height" />
</template>

Props

el

default: rect
Can be any custom or DOM element

transform

default: null
one of:

[
  "move", // moves the whole element
  "n", // resize from top
  "w", // resize from right
  "e", // resize from left
  "s" // resize from bottom
];

x

default: 0
Current x position

y

default: 0
Current y position

width

default: 0
Current width

height

default: 0
Current height

widthMax

default: Infinity
Maximum width of the element

widthMin

default: 0 Minimum width of the element

heightMax

default: Infinity
Maximum height of the element

heightMin

default: 0 Minimum height of the element

boundaryEl

default: window.document.body
Boundary element for dragging/resizing. Set to null to remove boundaries

grid

default: [] [x, y] - Grid that should be followed when resizing/dragging. Can be set to x or y individually or both.

mappingOnRoot

default: a => a
type: Function
Mapping position attributes [x, y, width, height] to root element. By default it's equivalent. Function takes object with attributes and values as an argument. Use when you want to use with DOM element as per example:

function mappingOnRoot(attrs) {
  return {
    top: attrs.y + "px",
    left: attrs.x + "px",
    width: attrs.width + "px",
    height: attrs.height + "px"
  };
}

Events

@transform

Emits on every transform with position object: { x, y, width, height }

@transformEnd

Emits when mouseup is registered (even away from element)

Dev

Clone this repo

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build-lib

Run your unit tests

npm run test:unit