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

lowcode-render

v0.0.6

Published

## Usage ### 入口: ```vue <script setup lang="ts"> import { RenderEngine, EnginePropsType } from "@/components/engine"; import * as ElComponents from "element-plus"; import { addBaseFunc } from "./BaseActions";

Downloads

3

Readme

Vue3 lowcode-render

Usage

入口:

<script setup lang="ts">
import { RenderEngine, EnginePropsType } from "@/components/engine";
import * as ElComponents from "element-plus";
import { addBaseFunc } from "./BaseActions";

const schema = {
  componentName: "ElButton",
  props: {
    innerText: {
      type: EnginePropsType.Model,
      value: "span",
      defaultValue: "xxxxxx",
    },
    type: "danger",
    onClick: {
      type: EnginePropsType.Action,
      actionKey: "clickTest",
    },
  },
};
</script>

<template>
  <RenderEngine
    :schema="schema"  // schema,描述页面UI及逻辑
    :components="ElComponents" // 渲染使用到的组件Map
    :add-action-func="addBaseFunc" // 自定义动作
  />
</template>

组件定义:

import * as ElComponents from "element-plus";
// 此处使用element-plus作为渲染组件库,格式{name: ComponentClass}

动作定义:

function,入参形如{getModel, setModel, remoteKey}, 返回Map{actionKey: function}

import { get } from "lodash";
import { computed } from "vue";

export function addBaseFunc({ getModel, setModel, remoteKey }: ActionFunc) {
  const router = useRouter();
  return {
    jump(params: RouterParams) { // 路由跳转动作
      router.push({
        path: params.path,
        query: params.query ?? {},
      });
    },
    toast(params: ToastParams) { // toast动作
      (ElMessage as any)[params.type]?.(params.msg);
    },
    dialog(params: DialogParams) { // Modal动作
      setModel(params.model, !getModel(params.model));
    },
    async fetch(params: FetchParams) { // 网络请求
      let customParams = {};
      if (params.fetchKey) {
        customParams = params.params ?? {};
        params = remoteKey[params.fetchKey];
      }
      const {
        url = "",
        method = "",
        params: fetchParams,
        confirmText,
      } = params;
      if (confirmText) {
        ElMessageBox.confirm(confirmText, "提示", {
          confirmButtonText: "确认发送",
        }).then(async () => {
          await sendRequest(
            url,
            method,
            [{ ...fetchParams, ...customParams }],
            params.lrMap
          );
        });
      } else {
        await sendRequest(
          url,
          method,
          [{ ...fetchParams, ...customParams }],
          params.lrMap
        );
      }
    },
    toggle() { // 添加computed追踪依赖变化
      const model = getModel("table1[0]");
      model.cateId = computed(() => `${getModel("form1.cateId")}_table`);
      setModel("condition", !getModel("condition"));
    },
    clickTest() { // 测试例子
      setModel("span", "zzzz");
    },
  };
}

整体方案

  1. 组件库,schema,Action(逻辑)分离,均支持自定义实现
  2. 使用vue3 reactive保持数据响应性,顶层数据管理,数据驱动,实现数据及数据修改和UI分离

schema定义

节点定义

interface Component {
    id?: string;
    componentName: string;
    props: {[key: string]: Props || any}; // 非Props类型时type默认为plain,节省数据开销
    condition: {}; // 渲染条件
    loop: [] || {}; // 循环数据,比如select下的options描述
    slots: {}; // 插槽
    children: Component[];
}

数据类型

无type情况下直接取值

export const EnginePropsType = {
  Plain: 'PLAIN', // 普通类型
  Model: 'MODEL', // model里面的key
  Loop: 'LOOP', // 循环绑定
  VModel: 'VMODEL', // 双向绑定
  Action: 'ACTION', // action里面的key
  Slot: 'SLOT', // JSX插槽
  SlotContext: 'SLOT_CONTEXT', // 插槽入参
  JSFunction: 'JS_FUNCTION' // 自定义函数
};

动态数据

取模型中对应的字段(key)

{
  type: EnginePropsType.Model,
  value: 'table1',
  defaultValue: []
}

循环

{
  type: EnginePropsType.Loop,
  value: 'value' // key名
}

双向绑定

VModel:比较特殊,需单独绑定,指定form和field

{
  type: EnginePropsType.VModel,
  form: 'form1',
  field: 'select'
}

Action

{
  type: EnginePropsType.Action,
  actionKey: 'reset',
  params: { sets: [{ localKey: 'table1', remoteKey: 'data.cate' }], formKey: 'form1' } // 传入action fun中的参数
}

Slot及SlotContext:

{
  slots: {
      default:
        [
          {
            componentName: 'img',
            key: '19',
            props: {
              src: {
                type: EnginePropsType.SlotContext,
                value: 'row.imgUrl'
              },
              style: {
                width: '100px'
              }
            }
          }
        ]
  }
}