Skip to content

CommonFoma Editor

Currently, the editor only supports formula editing and validation, to be improved in the future.

Features

  1. Variable/Function Auto-completion: Automatically prompts allowed variables and functions when typing in the editor
  2. AST Syntax Validation: Real-time expression syntax validation to ensure only allowed variables and functions are used
  3. Visual Variable Blocks: Variables and functions are displayed with special styles in the editor
  4. Read-only Mode: Editability can be controlled via the readonly property
  5. Custom Dimensions: Supports setting minimum and maximum height of the editor

Basic Usage

code1+code2
展开代码
复制代码

Read-only Mode

展开代码
复制代码

Disable Validation

展开代码
复制代码

Props

Prop NameDescriptionTypeDefault
readonlyWhether it is read-onlybooleanfalse
checkRulesWhether to enable rule checkingbooleantrue
maxHeightMaximum height of the editornumber400
minHeightMinimum height of the editornumber200
allowedVarsList of allowed variablesArray<VarType>[]
allowedFunsList of allowed functionsArray<VarType>[]

Methods

The following methods can be called by getting the component instance via ref:

Method NameDescriptionParameters
insertAtMousePositionInsert content at mouse positioncontent: string | VarType| FunctionType, mouseEvent: MouseEvent, type: 'var' | 'function'
insertVariableInsert variablevariable: VarType, position?: number
insertTextInsert texttext: string
insertFunctionInsert functionvariable: FunctionType, args: string[] = [], position?: number