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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fy-dynamic-form

v0.2.2

Published

Vue 3 drag-and-drop form builder with standalone renderer. Design forms visually and export as JSON.

Readme

dynamic-form-builder

基于 Vue 3 + TypeScript + Element Plus 的表单构建器 npm 包。导出两个组件:

  • FormBuilder — 拖拽式表单设计器(三栏布局:组件面板 + 画布 + 属性面板)
  • FormRender — 根据 JSON 配置渲染可交互表单

安装

npm install fy-dynamic-form

使用者项目只需额外安装以下两个依赖(其余依赖由 npm 自动安装):

npm install vue@^3.5 element-plus@^2.9

pinia 也是必需的 peer dependency,安装 Element Plus 时通常已间接依赖它。如果项目中没有,手动 npm install pinia 即可。

必需的项目初始化

// main.ts — 只需导入 Vue、Element Plus、Pinia,以及我们的 CSS
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createPinia } from 'pinia'
import 'fynix-dynamic-form-builder/dist/style.css'

const app = createApp(App)
app.use(createPinia())
app.use(ElementPlus)
app.mount('#app')

使用方法

FormBuilder — 表单设计器

<script setup lang="ts">
import { FormBuilder } from 'dynamic-form-builder'
import 'dynamic-form-builder/style.css'
</script>

<template>
  <FormBuilder />
</template>

FormRender — 表单渲染器

<script setup lang="ts">
import { ref } from 'vue'
import { FormRender } from 'dynamic-form-builder'
import type { FormConfig } from 'dynamic-form-builder'
import 'dynamic-form-builder/style.css'

const config: FormConfig = {
  formId: 'my-form',
  formMeta: { title: '示例', labelWidth: 100, labelPosition: 'right', labelSuffix: '', size: 'default', hideRequiredAsterisk: false },
  items: [
    { compId: 'c1', type: 'input', label: '姓名', prop: 'name', commonProps: { placeholder: '请输入' }, typeProps: { clearable: true }, rules: [], visibilityRule: null, autoFill: null },
  ],
}

const formData = ref({})
</script>

<template>
  <FormRender :config="config" v-model="formData" @submit="(d) => console.log(d)" />
</template>

两大组件

本项目提供两个核心组件,分别用于设计阶段运行阶段

| 组件 | 用途 | 对应文件 | |---|---|---| | 🏗️ FormBuilder(表单设计器) | 拖拽搭建表单、配置属性、导出 JSON | src/App.vue(编排)、FormCanvas.vuePropertyPanel.vueComponentPalette.vue | | 📋 FormRender(表单渲染器) | 根据 JSON 配置直接渲染一个可用的、带验证的表单 | src/components/FormRender.vue |


高级功能示例

条件可见性

让"邮箱"字段仅在 notify 开关开启时才显示:

{
  compId: 'c4',
  type: 'input',
  label: '通知邮箱',
  prop: 'email',
  // ...
  visibilityRule: {
    enabled: true,
    topLogic: 'and',
    groups: [
      {
        logic: 'and',
        conditions: [
          { compId: 'c_notify', operator: 'eq', value: true },
        ],
      },
    ],
  },
}

支持的运算符:eq neq gt lt gte lte in notIn empty notEmpty

动态数据源

下拉选项从接口获取,支持 {{prop}} 模板替换:

typeProps: {
  dataSource: {
    mode: 'dynamic',
    apiUrl: 'https://api.example.com/departments?q={{keyword}}',
    method: 'GET',
    labelKey: 'name',
    valueKey: 'id',
  },
}

栅格布局

多个组件并排排列:

{
  gridId: 'g1',
  type: 'grid-row',
  columns: [
    { colId: 'col1', span: 12, components: [ /* 占半行的组件 */ ] },
    { colId: 'col2', span: 12, components: [ /* 占半行的组件 */ ] },
  ],
}

数据模型(FormConfig JSON 结构)

FormConfig
├── formId: string                ← 表单唯一标识
├── formMeta: FormMeta            ← 表单全局设置
│   ├── title                     ← 表单标题
│   ├── labelWidth                ← 标签宽度(px)
│   ├── labelPosition             ← "left" | "right" | "top"
│   ├── labelSuffix               ← 标签后缀(如 ":")
│   ├── size                      ← "small" | "default" | "large"
│   └── hideRequiredAsterisk      ← 是否隐藏必填星号
│
└── items: CanvasItem[]           ← 组件列表(扁平数组)
    ├── FormComponent
    │   ├── compId: string        ← 组件唯一 ID
    │   ├── type: ComponentType   ← 18 种类型之一
    │   ├── label: string         ← 显示标签
    │   ├── prop: string          ← 表单字段名(v-model 绑定 key)
    │   ├── commonProps           ← 通用属性(placeholder, required, disabled...)
    │   ├── typeProps             ← 类型专属属性(options, format, rangeMode...)
    │   ├── rules: FormRule[]     ← 验证规则
    │   ├── visibilityRule        ← 条件可见性规则(AND/OR 逻辑组)
    │   └── autoFill             ← 自动填充规则(联动赋值)
    │
    └── GridRow                   ← 多列布局容器
        ├── gridId: string
        ├── type: "grid-row"
        └── columns[] → { colId, span, components: FormComponent[] }