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

@showlotus/babel-plugin-jsx

v0.0.1-beta

Published

Babel plugin for JSX

Downloads

2

Readme

Babel Plugin JSX

NPM version

Forked from babel-plugin-jsx

安装

安装插件

npm install @showlotus/babel-plugin-jsx

配置 Babel

{
  "plugins": ["@showlotus/babel-plugin-jsx"]
}

使用

参数

isReactiveRoot

Type: boolean

Default: false

是否返回一个响应式的结果。

输入

import { Fragment, Select } from '.';

function useFn() {
  return (
    <Fragment title="name" showOverflow>
      <Select />
    </Fragment>
  );
}

输出

  • false 时:

    import { Fragment, Select } from '.';
    function useFn() {
      return {
        props: {
          title: 'name',
          showOverflow: true,
        },
        slots: {
          default: {
            component: Select,
          },
        },
      };
    }
  • true 时:

    import { reactive as _reactive } from 'vue';
    import { Fragment, Select } from '.';
    function useFn() {
      return _reactive({
        props: {
          title: 'name',
          showOverflow: true,
        },
        slots: {
          default: {
            component: Select,
          },
        },
      });
    }

librarySource

Type: string

Default: vue,可选值:vuevue-demi@vue/composition-api

reactive 来源。

import { reactive as _reactive } from 'vue';
import { reactive as _reactive } from 'vue-demi';
import { reactive as _reactive } from '@vue/composition-api';

injectKey

Type: boolean

Default: false

是否注入 key,为每个组件都生成一个唯一的 key。开启后,可搭配 customKeystringFunction) 共同使用。

输入

import { Fragment, Select } from '.';

function useFn() {
  return (
    <Fragment title="name" showOverflow>
      <Select />
    </Fragment>
  );
}

输出

  • 不指定 customKey,默认为 "BABEL_PLUGIN_JSX"

    import { Fragment, Select } from '.';
    function useFn() {
      return {
        key: 'BABEL_PLUGIN_JSX_1',
        props: {
          title: 'name',
          showOverflow: true,
        },
        slots: {
          default: {
            key: 'BABEL_PLUGIN_JSX_0',
            component: Select,
          },
        },
      };
    }
  • 指定 customKey"Only_You"

    import { Fragment, Select } from '.';
    function useFn() {
      return {
        key: 'Only_You_1',
        props: {
          title: 'name',
          showOverflow: true,
        },
        slots: {
          default: {
            key: 'Only_You_0',
            component: Select,
          },
        },
      };
    }
  • 指定 customKey 为一个函数,则需要确保每次调用时,都返回一个唯一的结果,否则可能会导致不同组件有相同的 key

    let count = 1;
    function customKey() {
      return `Custom_Key_${count++}`;
    }
    import { Fragment, Select } from '.';
    function useFn() {
      return {
        key: 'Custom_Key_2',
        props: {
          title: 'name',
          showOverflow: true,
        },
        slots: {
          default: {
            key: 'Custom_Key_1',
            component: Select,
          },
        },
      };
    }

组件

Dialog

弹窗组件,所有组件名为 Dialog 的组件,会放在根组件的具名插槽 dialog 下。

输入:

import { Dialog, Form, FormItem } from '.';

function useFn() {
  return (
    <Form>
      <FormItem label="name" prop="name" />
      <FormItem label="age" prop="age" />
      <Dialog visible={visible} title="title" />
    </Form>
  );
}

输出:

import { Dialog, Form, FormItem } from '.';
function useFn() {
  return {
    component: Form,
    slots: {
      default: [
        {
          component: FormItem,
          props: {
            label: 'name',
            prop: 'name',
          },
        },
        {
          component: FormItem,
          props: {
            label: 'age',
            prop: 'age',
          },
        },
      ],
      dialog: [
        {
          props: {
            visible: visible,
            title: 'title',
          },
        },
      ],
    },
  };
}

Fragment

component 属性的组件。

输入:

import { Fragment, Option, Select } from '.';

function useFn() {
  return (
    <Fragment title="name" showOverflow>
      <Select>
        <Option label="1" value={1} />
        <Option label="2" value={2} />
        <Option label="3" value={3} />
      </Select>
    </Fragment>
  );
}

输出:

import { Fragment, Option, Select } from '.';
function useFn() {
  return {
    props: {
      title: 'name',
      showOverflow: true,
    },
    slots: {
      default: {
        component: Select,
        slots: {
          default: [
            {
              component: Option,
              props: {
                label: '1',
                value: 1,
              },
            },
            {
              component: Option,
              props: {
                label: '2',
                value: 2,
              },
            },
            {
              component: Option,
              props: {
                label: '3',
                value: 3,
              },
            },
          ],
        },
      },
    },
  };
}

Template

具名插槽组件。通过配置 slot 属性指定插槽名称。

输入:

import { Button, Form, FormItem, Fragment, Option, Select, Template } from '.';

function useFn() {
  return (
    <Fragment title="name" showOverflow>
      <Template slot="header" title="xxx" />
      <Template slot="default">
        <Form>
          <FormItem label="name" prop="name" />
          <FormItem label="age" prop="age" />
        </Form>
      </Template>
      <Template slot="footer">
        <Button type="default" text="cancel" />
        <Button type="primary" text="confirm" />
      </Template>
    </Fragment>
  );
}

输出:

import { Button, Form, FormItem, Fragment, Option, Select, Template } from '.';
function useFn() {
  return {
    props: {
      title: 'name',
      showOverflow: true,
    },
    slots: {
      header: {
        props: {
          title: 'xxx',
        },
      },
      default: {
        component: Form,
        slots: {
          default: [
            {
              component: FormItem,
              props: {
                label: 'name',
                prop: 'name',
              },
            },
            {
              component: FormItem,
              props: {
                label: 'age',
                prop: 'age',
              },
            },
          ],
        },
      },
      footer: [
        {
          component: Button,
          props: {
            type: 'default',
            text: 'cancel',
          },
        },
        {
          component: Button,
          props: {
            type: 'primary',
            text: 'confirm',
          },
        },
      ],
    },
  };
}

在 TypeScript 中使用

tsconfig.json:

{
  "compilerOptions": {
    "jsx": "preserve"
  }
}