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

dyno-item

v0.0.9

Published

Vue3 Library Component for draggable and resizable items.

Downloads

10

Readme

dyno-item

Build Status NPM Downloads Snyk Vulnerabilities for npm package NPM License NPM Version npm collaborators coverage functions coverage lines

resize draggable :bomb: Features Live Demo

Vue3 Library Component for draggable and resizable items.

demo

:rocket: Features

  • No dependencies
  • Use draggable, resizable or both
  • Limit size and movement to parent element
  • Snap element to custom grid
  • Limit drag to vertical or horizontal axis
  • Maintain aspect ratio
  • Touch enabled
  • Custom styling
  • Define handles for resizing
  • Provide your own markup for handles

Install and basic usage

$ npm install --save dyno-item

Register the component

import DynoItemPlugin from 'dyno-item';

// optionally import default styles
import 'dyno-item/dist/dyno-item.common.css';

createApp(App)
  .use(DynoItemPlugin)
  .mount('#app');

Now your component inside a code:

<template>
  <div style="height: 500px; width: 500px; border: 1px solid red; position: relative;">
    <DynoItem  @dragging="onDrag" @resizing="onResize" :parent="true">
      <p>I'm a draggable and resizable item</p>
      Position: [x={{x}}, y={{y}}]
      Dimension: [w={{width}}, h={{height}}]
    </DynoItem>
  </div>
</template>

<script>
import { defineComponent } from 'vue';
import { DynoItem } from 'dyno-item';

export default defineComponent({
  components: {
    DynoItem,
  },
  name: 'App',
  setup() {
    const x = ref(0);
    const y = ref(0);
    const width = ref(0);
    const height = ref(0);
    const onDrag = (x,y) => {
      x.value = x; 
      y.value = y;
    }
    const onResize = (x,y, width, height) => {
      x.value = x; 
      y.value = y;
      width.value = width;
      height.value = height;
    }  
    return {
      x,
      y,
      width,
      height,
      onDrag,
      onResize
    };
  },
});
</script>

Props

className

Type: String Required: false Default: vdr

Used to set the custom class of a draggable-resizable component.

<DynoItem class-name="my-class">

classNameDraggable

Type: String Required: false Default: draggable

Used to set the custom class of a draggable-resizable component when draggable is enable.

<DynoItem class-name-draggable="my-draggable-class">

classNameResizable

Type: String Required: false Default: resizable

Used to set the custom class of a draggable-resizable component when resizable is enable.

<DynoItem class-name-resizable="my-resizable-class">

classNameDragging

Type: String Required: false Default: dragging

Used to set the custom class of a draggable-resizable component when is dragging.

<DynoItem class-name-dragging="my-dragging-class">

classNameResizing

Type: String Required: false Default: resizing

Used to set the custom class of a draggable-resizable component when is resizing.

<DynoItem class-name-resizing="my-resizing-class">

classNameActive

Type: String Required: false Default: active

Used to set the custom class of a draggable-resizable component when is active.

<DynoItem class-name-active="my-active-class">

classNameHandle

Type: String Required: false Default: handle

Used to set the custom common class of each handle element. This way you can style each handle individually using the selector <your class>-<handle code>, where handle code identifies one of the handles provided by the handle prop.

So for example, this component:

<DynoItem class-name-handle="my-handle-class"></DynoItem>

renders the following:

<div ...>
  <div class="my-handle-class my-handle-class-tl"></div>
  <div class="my-handle-class my-handle-class-tm"></div>
  <div class="my-handle-class my-handle-class-tr"></div>
  [...]
</div>

scale

Type: Number|Array Required: false Default: 1

The scale prop controls the scale property when the CSS 3 scale transformation is applied to one of the parent elements. If not provided the default value is 1.

<DynoItem :scale="0.5">

<DynoItem :scale="[0.5, 0.4]">

disableUserSelect

Type: Boolean Required: false Default: true

By default, the component adds the style declaration 'user-select:none' to itself to prevent text selection during drag. You can disable this behaviour by setting this prop to false.

<DynoItem :disable-user-select="false">

enableNativeDrag

Type: Boolean Required: false Default: false

By default, the browser's native drag and drop funcionality (usually used for images and some other elements) is disabled, as it may conflict with the one provided by the component. If you need, for whatever reason, to have this functionality back you can set this prop to true.

<DynoItem :enable-native-drag="true">

active

Type: Boolean Required: false Default: false

Determines if the component should be active or not. The prop reacts to changes and also can be used with the syncmodifier to keep the state in sync with the parent. You can use along with the preventDeactivation prop in order to fully control the active behavior from outside the component.

<DynoItem :active="true">

preventDeactivation

Type: Boolean Required: false Default: false

Determines if the component should be deactivated when the user clicks/taps outside it.

<DynoItem :prevent-deactivation="true">

draggable

Type: Boolean Required: false Default: true

Defines it the component should be draggable or not.

<DynoItem :draggable="false">

resizable

Type: Boolean Required: false Default: true

Defines it the component should be resizable or not.

<DynoItem :resizable="false">

w

Type: Number|String Required: false Default: 200

Define the initial width of the element. It also supports auto, but when you start resizing the value will fallback to a number.

<DynoItem :w="200">

h

Type: Number|String Required: false Default: 200

Define the initial height of the element. It also supports auto, but when you start resizing the value will fallback to a number.

<DynoItem :h="200">

minWidth

Type: Number Required: false Default: 50

Define the minimal width of the element.

<DynoItem :min-width="50">

minHeight

Type: Number Required: false Default: 50

Define the minimal height of the element.

<DynoItem :min-height="50">

maxWidth

Type: Number Required: false Default: null

Define the maximum width of the element.

<DynoItem :max-width="400">

maxHeight

Type: Number Required: false Default: null

Define the maximum height of the element.

<DynoItem :max-height="50">

x

Type: Number Required: false Default: 0

Define the initial x position of the element.

<DynoItem :x="0">

y

Type: Number Required: false Default: 0

Define the initial y position of the element.

<DynoItem :y="0">

z

Type: Number|String Required: false Default: auto

Define the zIndex of the element.

<DynoItem :z="999">

handles

Type: Array Required: false Default: ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']

Define the array of handles to restrict the element resizing:

  • tl - Top left
  • tm - Top middle
  • tr - Top right
  • mr - Middle right
  • br - Bottom right
  • bm - Bottom middle
  • bl - Bottom left
  • ml - Middle left
<DynoItem :handles="['tm','bm','ml','mr']">

axis

Type: String Required: false Default: both

Define the axis on which the element is draggable. Available values are x, y or both.

<DynoItem axis="x">

grid

Type: Array Required: false Default: [1,1]

Define the grid on which the element is snapped.

<DynoItem :grid="[1,1]">

parent

Type: Boolean Required: false Default: false

Restricts the movement and the dimensions of the component to the parent.

<DynoItem :parent="true">

dragHandle

Type: String Required: false

Defines the selector that should be used to drag the component.

<DynoItem drag-handle=".drag">

dragCancel

Type: String Required: false

Defines a selector that should be used to prevent drag initialization.

<DynoItem drag-cancel=".drag">

lockAspectRatio

Type: Boolean Required: false Default: false

The lockAspectRatio property is used to lock aspect ratio. This property doesn't play well with grid, so make sure to use only one at a time.

<DynoItem :lock-aspect-ratio="true">

onDragStart

Type: Function Required: false Default: null

Called when dragging starts (element is clicked or touched). If false is returned by any handler, the action will cancel. You can use this function to prevent bubbling of events.

<DynoItem :onDragStart="onDragStartCallback">
function onDragStartCallback(ev){
   ...
   // return false; — for cancel
}

onDrag

Type: Function Required: false Default: null

Called before the element is dragged. The function receives the next values of x and y. If false is returned by any handler, the action will cancel.

<DynoItem :onDrag="onDragCallback">
function onDragStartCallback(x, y){
   ...
   // return false; — for cancel
}

onResizeStart

Type: Function Required: false Default: null

Called when resizing starts (handle is clicked or touched). If false is returned by any handler, the action will cancel.

<DynoItem :onResizeStart="onResizeStartCallback">

function onResizeStartCallback(handle, ev){
   ...
   // return false; — for cancel
}

onResize

Type: Function Required: false Default: null

Called before the element is resized. The function receives the handle and the next values of x, y, width and height. If false is returned by any handler, the action will cancel.

<DynoItem :onResize="onResizeCallback">

function onResizeStartCallback(handle, x, y, width, height) {
   ...
   // return false; — for cancel
}

Events

activated

Parameters: -

Called whenever the component gets clicked, in order to show handles.

<DynoItem @activated="onActivated">

deactivated

Parameters: -

Called whenever the user clicks anywhere outside the component, in order to deactivate it.

<DynoItem @deactivated="onDeactivated">

resizing

Parameters:

  • left the X position of the element
  • top the Y position of the element
  • width the width of the element
  • height the height of the element

Called whenever the component gets resized.

<DynoItem @resizing="onResizing">

resizestop

Parameters:

  • left the X position of the element
  • top the Y position of the element
  • width the width of the element
  • height the height of the element

Called whenever the component stops getting resized.

<DynoItem @resizestop="onResizstop">

dragging

Parameters:

  • left the X position of the element
  • top the Y position of the element

Called whenever the component gets dragged.

<DynoItem @dragging="onDragging">

dragstop

Parameters:

  • left the X position of the element
  • top the Y position of the element

Called whenever the component stops getting dragged.

<DynoItem @dragstop="onDragstop">