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

grid-drag

v1.0.5

Published

A flexible and intelligent Vue 3 grid layout component with drag & drop, resize, and smart collision detection.

Readme

Vue Grid Layout

A flexible and intelligent Vue 3 grid layout component with drag & drop, resize, and smart collision detection.

Features

  • 🎯 24-column grid system - Fixed 24-column layout for consistent design
  • 🖱️ Drag & Drop - Smooth dragging with smart grid snapping
  • 📏 Resize - Intelligent resizing with collision detection
  • 🧠 Smart Layout - Automatic component arrangement and collision avoidance
  • 📱 Responsive - Adapts to container size changes
  • 🎨 Customizable - Flexible styling and configuration options
  • 🔧 TypeScript - Full TypeScript support

Installation

npm install grid-drag

Usage

Basic Usage

<template>
  <div class="demo-container">
    <GridHeader :component-library="componentLibrary" @confirm-add="addComponents" @save="saveLayout">
    </GridHeader>
    <div class="demo-content">
      <GridLayout ref="gridLayoutRef" :layout.sync="layout" :col-num="24" :row-height="30" :prevent-overflow="true"
        :is-bounded="true">
        <GridItem v-for="item in layout" class="component-item" :key="item.i" :x="item.x" :y="item.y" :w="item.w"
          :h="item.h" :i="item.i" :static="item.static" @remove="removeItem">
        </GridItem>
      </GridLayout>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { GridLayout, GridItem, GridHeader } from 'grid-drag'
import 'grid-drag/lib/style.css'
import {
  gridItemWidthToColNum,
  gridItemHeightToRowNum,
  type Layout,
  type LayoutItem
} from 'grid-drag';

const componentLibrary = ref([
  {
    type: 'line-bar',
    name: '折线图',
    w: 400,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'chart-bar',
    name: '柱状图',
    w: 350,   // 像素
    h: 200,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'chart-pie',
    name: '饼图',
    w: 300,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'table',
    name: '数据表格',
    w: 600,   // 像素
    h: 400,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'card',
    name: '数据卡片',
    w: 300,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'metric',
    name: '指标卡',
    w: 300,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'text',
    name: '文本组件',
    w: 320,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'image',
    name: '图片组件',
    w: 400,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  },
  {
    type: 'progress',
    name: '进度条',
    w: 360,   // 像素
    h: 300,  // 像素
    i: useId(),
    x: 0,
    y: 0
  }
])

const layout = ref<Layout>([])
const addComponents = (components: Layout) => {
  // 转换组件尺寸为网格单位
  const convertedComponents = components.map(item => ({
    ...item,
    w: gridItemWidthToColNum(
      gridLayoutRef.value.width,
      gridLayoutRef.value.colNum,
      gridLayoutRef.value.margin[0],
      item.w
    ),
    h: gridItemHeightToRowNum(
      gridLayoutRef.value.rowHeightComputed,
      gridLayoutRef.value.margin[1],
      item.h
    )
  }))

  // 使用智能添加方法
  const result = gridLayoutRef.value.addItemsIntelligently(convertedComponents)

  layout.value = [...layout.value, ...result.addedItems]
  if (result.failedItems.length > 0) {
    console.warn(`无法添加 ${result.failedItems.length} 个组件,容器空间不足`)
    // 可以在这里添加用户提示
  }

  if (result.success) {
    console.log(`成功添加 ${result.addedItems.length} 个组件`)
  }
}

const removeItem = (id?: string) => {
  if (id) {
    const index = layout.value.findIndex(item => item.i === id)

    if (index >= 0) {
      layout.value.splice(index, 1)
    }
  }
}
</script>

Advanced Features

Smart Collision Detection

The grid layout includes intelligent collision detection that:

  • Only triggers layout adjustments when components are close (within gap distance)
  • Prevents overlapping during drag operations
  • Automatically arranges new components without disrupting existing layout

Responsive Behavior

  • Container size changes only trigger re-layout when size increases
  • Components maintain their positions when container shrinks
  • Automatic boundary checking and adjustment

Grid Snapping

  • Components snap to the 24-column grid system
  • Smart height snapping based on nearby components
  • Maintains consistent spacing and alignment

Styling

The component comes with default styles, but you can customize them:

.grid-layout {
  // Your custom styles
}

.grid-item {
  // Your custom item styles
}

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.