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

@wowpic/xform

v1.0.0

Published

> 通过配置的方式生成表单方案

Readme

XForm

通过配置的方式生成表单方案

🏃快速入门

安装

nenpm install @wowpic/xform-react

使用

XForm通过配置Schema的形式来初始化表单,其中Schema是一份由JS对象组成的数组,数组中的每个成员都代表一个表单项的配置

import { XForm } from '@wowpic/xform-react';
import schema from './schema.js';
import 'antd/dist/antd.css';
import '@wowpic/xform-react/lib/xform.css';

export default function () {
    const formRef = useRef(null);

    const onSubmit = () => {
        formRef.current.submit().then(data => {
            const { valid, value } = data;
            console.log(valid, value);
        });
    };

    const onReset = () => {
        formRef.current.reset();
    };

    return (
        <>
            <XForm
                ref={formRef}
                schema={schema}
                labelCol={{ span: 6 }}
                wrapperCol={{ span: 12 }}
            />
            <div>
                <Button type="primary" onClick={onSubmit}>提交</Button>
                <Button onClick={onReset}>重置</Button>
            </div>
        </>
    );
};

Schema例子如下:

export default [
    {
        key: 'input',
        type: 'Input',
        ui: {
            label: '输入框',
            required: true
        },
        props: {
            placeholder: '请输入'
        },
        rules: [
            {
                required: true,
                message: '输入内容不能为空'
            }
        ]
    }
];

🎬技术方案

分为core(核心层)和react(渲染层),表单数据维护在核心层中,通过事件的方式传递状态对渲染层代码进行渲染

✨命令

调试:

npm run setup // lerna 进行关联,并安装 npm 包
npm run build // 初次构建
npm run watch // 监听文件变化自动构建
npm run dev // 启动测试环境

发布:

nenpm run publish // 必须要nenpm才能发布,具体原因我也不知

单元测试:

npm run test

文档:

npm run docs

🏷工程目录

.
├── README.md // 开发文档
├── docs // 用户使用文档
├── examples // 本地调试案例
├── lerna.json
├── package.json
├── packages
│   ├── core // 核心层
│   │   ├── README.md
│   │   ├── package.json
│   │   ├── src
│   │   │   ├── __tests__ // 测试用例
│   │   │   ├── fetch.ts // 请求封装
│   │   │   ├── field.ts // 字段
│   │   │   ├── fieldGroup.ts // Object字段
│   │   │   ├── fieldList.ts // Array字段
│   │   │   ├── form.ts // 表单
│   │   │   ├── listenerManager.ts // 联动
│   │   │   ├── optionManager.ts // options
│   │   │   ├── utils.ts // 工具
│   │   │   └── validator.ts // 校验
│   │   └── tsconfig.json
│   ├── react // 渲染层
│   │   ├── README.md
│   │   ├── package.json
│   │   ├── src
│   │   │   ├── component.tsx
│   │   │   ├── components
│   │   │   │   ├── autoComplete.tsx
│   │   │   │   ├── cascader.tsx
│   │   │   │   ├── checkbox.tsx
│   │   │   │   ├── checkboxAll.tsx
│   │   │   │   ├── dateTimePicker.tsx
│   │   │   │   ├── index.ts
│   │   │   │   ├── input.tsx
│   │   │   │   ├── radio.tsx
│   │   │   │   ├── radioButton.tsx
│   │   │   │   ├── select.tsx
│   │   │   │   ├── switch.tsx
│   │   │   │   ├── textArea.tsx
│   │   │   │   ├── transfer.tsx
│   │   │   │   └── treeSelect.tsx
│   │   │   ├── field.tsx
│   │   │   ├── fieldGroup.tsx
│   │   │   ├── fieldList.tsx
│   │   │   ├── form.tsx
│   │   │   ├── index.less
│   │   │   ├── index.tsx
│   │   │   ├── switcher.tsx
│   │   │   ├── typings
│   │   │   │   └── module.d.ts
│   │   │   └── utils.ts
│   │   └── tsconfig.json
│   └── types // 类型定义
│       ├── package.json
│       ├── src
│       │   ├── field.ts
│       │   ├── form.ts
│       │   ├── index.ts
│       │   ├── listener.ts
│       │   ├── option.ts
│       │   ├── react.ts
│       │   └── validate.ts
│       └── tsconfig.json
├── scripts
│   └── webpack.config.js
└── tsconfig.json

📚参考资料