New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-data-mapping

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-data-mapping

数据/字段映射React组件

  • 1.3.18
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

一个基于React的数据/字段映射组件

npm version download gzip size license

English | 简体中文

✨ 特性

  • 支持定制字段属性
  • 支持表名定制
  • 支持字段连接数量限制
  • 支持字段排序
  • 支持延迟渲染,自动适配高宽,四周留白等配置
  • 支持空字段内容定制

🔨快速本地DEMO


git clone git@github.com:aliyun/react-data-mapping.git
npm install
cd example
npm install
npm start

📦 安装


npm install react-data-mapping

API

DataMapping属性

参数说明类型默认值
width组件宽度number默认500,自适应的话可以设置"auto"
height组件高度number默认500,自适应的话可以设置"auto"
type映射类型stringsingle | mutiply ,默认 single
className组件类名string-
sourceClassName来源表类名string-
targetClassName目标表类名string-
columns每列的属性Columns | Array<Columns> undefined
sourceData来源表数据SourceData | Object | Array<SourceData>undefined
targetData目标表数据TargetData | Object | Array<TargetData>undefined
mappingData初始映射关系,见mappingData Proparray[ ]
emptyContent当表字段为空时显示内容string | ReactNode-
emptyWidth当表字段为空时,表容器的宽度string | number150
config组件的额外属性配置,见config Propobject{ }
isConnect每次连线前触发,判断是否可以连线function(edge): boolean
onChange每次连线触发事件function
onRowMouseOver鼠标移入某一行数据时触发function(row)
onRowMouseOut鼠标移出某一行数据时触发function(row)
onEdgeClick点击连线时触发function(row)
readonly是否只读boolean默认false

Column

列描述数据对象,是Columns中的一项

参数说明类型默认值
key列数据在数据项中对应的路径string-
title列头显示文字string-
width列宽度number-
primaryKey此属性是否为该组数据唯一标识boolean必须且仅有一个属性为true
render自定义渲染函数,参数分别为当前行的值,当前行数据,行索引function(text, record, index) {}-

sourceData

来源表数据,当typesingle 时,sourceData的类型为{ };当typemutiply 时,sourceData的类型为[ ]

参数说明类型默认值
id列标识, single 类型下,id可不填, mutiply 为必填string-
title列标题string-
fileds数据数组array-
checked勾选框是否已勾选booleanfalse
disable禁止连线booleanfalse

targetData

目标表数据,当typesingle 时,targetData的类型为{ };当typemutiply 时,targetData的类型为[ ],属性详情见sourceData


mappingData

参数说明类型
source来源表当前行数据的唯一标识-
target目标表当前行数据的唯一标识-
sourceNode来源表的id,见sourceData IDstring
targetNode目标表的id,见targetData IDstring

config

组件的额外属性配置

参数说明类型默认值
delayDraw延迟渲染,此组件一定要确保画布容器渲染(包括动画执行)完毕才能渲染, 否则坐标都产生偏移, 如:antd的modal的动画number0
extraPos画布渲染的时候会留padding,extraPos Prop { }-
sortable排序支持boolean | object-
linkNumLimit连线数量支持number | object-
checkable来源表,目标表是否有勾选框checkable Prop { }-

extraPos

画布渲染的时候预留padding

参数说明类型默认值
paddingLeft左侧padding间距number0
paddingRight右侧padding间距number0
paddingTop顶部padding间距number0
paddingBottom底部padding间距number0
paddingCenter水平间距number150
nodeVerticalPadding节点垂直间距number10
rowHeight节点每行的高度number26

checkable

来源表,目标表是否有勾选框

参数说明类型默认值
source源表是否有勾选框booleanfalse
target目标表是否有勾选框booleanfalse

🔗API

interface columns { // 设置每列的属性
  title ? : string; // 每列的title,类似thead的概念
  key: string; // 每列的唯一标志,对应数据上的key值
  width ? : number; // 每列宽度
  primaryKey: boolean // 这列的key对应的value是否作为键值对
}

interface config {
  delayDraw: number; // 延迟渲染,此组件一定要确保画布容器渲染(包括动画执行)完毕才能渲染,否则坐标都产生偏移,如:antd的modal的动画
  extraPos ? : { // 画布渲染的时候会留padding
      paddingLeft ? : number,
      paddingRight ? : number,
      paddingTop ? : number,
      paddingBottom ? : number,
      paddingCenter ? : number,
    },
    sortable ? : boolean | { // 排序支持,假如是true,会整个画布都支持排序
      source ? : boolean, // 假如是true,单纯左侧来源表支持排序
      target ? : boolean // 假如是true,单纯左侧目标表支持排序
    },
    linkNumLimit ? : number | { // 连线数量支持,假如是number,会整个画布都支持n条连线
      source ? : number, // 假如是number,单纯左侧来源表支持n条连线
      target ? : number // 假如是number,单纯左侧来源表支持n条连线
    },
    checkable ?: {  // 源表目标表是否有勾选框
      source ? : boolean, // 假如是true,单纯左侧来源表支持勾选框
      target ? : boolean
    }
}

interface ComProps { // 组件props属性
  width ? : number | string; // 组件的宽度,自适应的话可以设置"auto"
  height ? : number | string; // 组件的高度,自适应的话可以设置"auto"
  type ? : string; // "single"or"mutiply",单表映射(上图一) or 多表映射(上图二)
  className ? : string; // 组件类名
  sourceClassName ? : string; // 来源表类名
  targetClassName ? : string; // 目标表类名
  columns: Array < columns > ; // 请参考上述interface columns
  sourceData: Array < any > | Object; // 单表映射对应Object,多表映射Array,可参考demo
  targetData: Array < any > | Object; // 单表映射对应Object,多表映射Array,可参考demo
  mappingData: Array < any > ; // 初始化对应关系数据,可参考demo
  emptyContent ? : string | JSX.Element; // 当表字段为空时显示内容
  emptyWidth ? : number | string; // 当表字段为空时表容器宽度
  isConnect?(edge: any): boolean; // 每次连线前触发isConnect,返回true则进行连线,false则不会
  onChange(data: any): void; // 每次连线都是触发onChange事件
  onRowMouseOver?(row:any):void, // 鼠标移入某一行数据时触发
  onRowMouseOut?(row:any):void, // 鼠标移出某一行数据时触发
};
import ButterflyDataMapping from 'react-data-mapping';
import 'react-data-mapping/dist/index.css';

<ButterflyDataMapping
  width={500}
  height={1000}
  type={'single'}
  columns={columns}
  sourceData={sourceData}
  targetData={targetData}
  mappingData={mappingData}
  className={'butterfly-data-mappint'}
  sourceClassName={'source-column'}
  targetClassName={'target-column'}
/>

如需要更多定制的需求,您可以提issue或者参考Butterfly来定制您需要的需求

Keywords

FAQs

Package last updated on 22 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc