# @tntd/formula-edit

> react计算公式编辑器

Latest version **2.2.0** (published 2026-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tntd/formula-edit
pnpm add @tntd/formula-edit
yarn add @tntd/formula-edit
bun add @tntd/formula-edit
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-01-20 |
| First published | 2020-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 37 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | bo.liu@tongdun.cn |
| Maintainers | td-tnt, bruceliu68, bernardzhang, mizy, zhouzefei, xiaofei.wang, anthonyli, popoqaq, ezios, z337198954, kobingogo, mcfly001, mgcr, a1226062445 |
| Keywords | formula, formula-edit, formula-edit-react |

## Links

- npm: https://www.npmjs.com/package/@tntd/formula-edit
- Repository: https://github.com/tntd/formula-editor
- Homepage: https://github.com/tntd/formula-editor#readme
- Issues: https://github.com/tntd/formula-editor/issues
- npm.io page: https://npm.io/package/@tntd/formula-edit

## Dependencies (7)

- [antd](https://npm.io/package/antd.md) ^3.26.20
- [react](https://npm.io/package/react.md) ^16.8.6
- [react-dom](https://npm.io/package/react-dom.md) ^16.8.6
- [codemirror](https://npm.io/package/codemirror.md) ^5.46.0
- [js-beautify](https://npm.io/package/js-beautify.md) ^1.13.13
- [universal-cookie](https://npm.io/package/universal-cookie.md) ^4.0.4
- [intersection-observer](https://npm.io/package/intersection-observer.md) ^0.12.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2026-01-20
- 2.1.18 — 2025-10-30
- 2.1.17 — 2025-01-15
- 2.1.16 — 2025-01-15
- 2.1.15 — 2024-08-14
- 2.1.14 — 2024-07-31
- 2.1.13 — 2024-07-25
- 2.1.12 — 2024-07-01
- 2.1.11 — 2024-04-20
- 2.1.10 — 2024-03-12
- 2.1.9 — 2024-02-26
- 2.1.8 — 2023-10-16
- 2.1.7 — 2023-10-11
- 2.1.6 — 2023-10-11
- 2.1.5 — 2023-10-11
- … 27 more at https://npm.io/package/@tntd/formula-edit/versions

## README

# @tntd/formula-edit

react计算公式编辑器

## Usage

### @tntd/formula-edit

安装

```sh
npm install --save-dev @tntd/formula-edit
```
使用

```
<FormulaEdit
    value='@hahahdsdhjbewdbu1#avg(,)andhhhhhhh' //传入组件自动转化成cnCode
    fieldList={testData} // @唤起
    regRxp="@[^\\+\\*\\/#%\\(\\),;\\!\\<\\>\\-=@]*" //中文转英文默认正则
    typeMap={{'OBJECT':{'displayName':'对象','color': 'blue'}}} // 下拉框 自定义展示类型和颜色
    methodList={methodList} // #唤起
    normalList={normalList} // 自定义无需校验关键词
    onChange={(enCode,data)=>{}} // 回调
    // defaultValue={defaultCode} // 初始化值 已去除该属性
    // readOnly={false} // 是否只读 默认false
    // lineNumber={true} // 是否显示列数 默认true
    // theme="night" // 主题 默认night
    // height={300} // 高度 默认300
/>
```

## fieldList 输入@符号才能调起
```
fieldList: [
    { name: "放款金额", value: "fkje"},
    { name: "实际放款金额", value: "sjfkje"},
    { name: "借款人姓名", value: "jkrxm"},
    { name: "借款人手机号", value: "jkrsjh"},
    { name: "借款人身份证", value: "jkrsfz"},
],
```
## methodList 输入#符号才能调起
```
methodList: [
    { name: "平均值", value: "平均值(,)", realValue: "avg" },
    { name: "最大值", value: "最大值(,)", realValue: "max" },
    { name: "最小值", value: "最小值(,)", realValue: "min" },
    { name: "求和", value: "求和(,)", realValue: "sum" }
],
```
## normalList 自定义无需校验关键词
```
normalList: [
    { name: "且", value: "and" },
    { name: "或", value: "or" }
],
```

## 特殊数据场景 @STRINGαC_S_CARDNO
```
const typeKeyWords = ['αINT', 'αSTRING', 'αDOUBLE', 'αBOOLEAN', 'αDATETIME', 'αLONG', 'αENUM', 'αJSON'];

const enCodeToCnExtraLogic = (enCode) => {
    const regExp = new RegExp(`(${typeKeyWords.join('|')})`, 'g');
    const cnCode = enCode.replace(regExp, () => {
        return '';
    });
    return cnCode;
};

<FormulaEdit
    value='@hahahdsdhjbewdbu1#avg(,)andhhhhhhh' //传入组件自动转化成cnCode
    fieldList={testData} // @唤起
    regRxp="@[^\\+\\*\\/#%\\(\\),;\\!\\<\\>\\-=@]*" //中文转英文默认正则
    typeMap={{'OBJECT':{'displayName':'对象','color': 'blue'}}} // 下拉框 自定义展示类型和颜色
    methodList={methodList} // #唤起
    normalList={normalList} // 自定义无需校验关键词
    onChange={(enCode,data)=>{}} // 回调
    cnCodeToEnExtraLogic={(item) => {
        return `α${item.type}`;
    }}
    enCodeToCnExtraLogic={enCodeToCnExtraLogic}
/>
```

## 编辑器效果
![Image text](https://github.com/bruceliu68/formulaEdit-react/blob/master/src/img/pic1.png)
![Image text](https://github.com/bruceliu68/formulaEdit-react/blob/master/src/img/pic2.png)

## props参数：
|    参数    | 类型    |  默认值   |  是否必填  | 说明         |
| :------:  | :-----: | :----:   | :------: | :----------: |
| defaultValue | string  |  无      |   非必填    | 初始化赋值  2.0已废弃   |
| value | string  |  无      |   非必填    | 赋值  传入组件自动转化成cnCode |
| height    | number  |  300     |   非必填  | 高度设置       |
| theme    | string  |  night     |   非必填  | 主题: 目前只支持两种：day，night |
| readOnly  | boolean |  false   |   非必填  | 设置只读       |
| lineNumber  | boolean |  false   |   非必填  | 设置行号       |
| typeMap | object   |  无      |   非必填  | 自定义变量类型和颜色       |
| isEndMark | boolean   |  false      |   非必填  | 是否需要@结束符       |
| fieldList | array   |  无      |   非必填  | 字段列表       |
| methodList | array   |  无      |   非必填  | 方法列表       |
| normalList | array   |  无      |   非必填  | 自定义关键词列表       |
| onChange  | function(enCode, obj)|  无      |   非必填    | enCode, obj(里面有cnCode)      |

## 支持ref对外暴露方法
|    方法    | 类型    | 说明         |
| :------:  | :-----: | :----------: |
| fullScreen() | function  | 全屏     |
| exitFullScreen() | function  | 退出全屏     |
| insertValue(value) | function  | 光标处插入值     |

## License
MIT

---
_Source: https://npm.io/package/@tntd/formula-edit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
