1.0.5 • Published 2 years ago

@dsyx/custom-syntax-editor v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

@dsyx/custom-syntax-editor

React自定义语法编辑器

Usage

安装

npm install @dsyx/custom-syntax-editor

使用

import CustomEditor from "@dsyx/custom-syntax-editor";

const keywords = [
	// groovy 关键词
	"as", "catch", "def", "enum", "for", "import", "new", "super", "throws", "while",
	"assert", "class", "default", "extends", "goto", "in", "null", "switch", "trait", "break",
	"const", "do", "false", "if", "instanceof", "package", "this", "true", "case", "continue", "else",
	"finally", "implements", "interface", "return", "throw", "try",
	// java 关键词
	"abstract", "transient", "int", "strictfp", "synchronized", "boolean", "char", "do",
	"final", "private", "short", "void", "double", "long", "protected", "static", "volatile",
	"byte", "float", "native", "public",
	// JDK 常用类
	"System", "Runtime", "String", "StringBuffer", "StringBuilder", "Date", "DateFormat",
	"SimpleDateFormat", "Calendar", "GregorianGalendar", "Math", "Integer", "Double", "Float",
	"Boolean", "List", "HashMap", "Map", "ArrayList", "Arrays", "Random", "Iterator"
];

const Demo = props => {
	
	const getCode = (code) => {
		console.log(code);
	};

    return (
       <CustomEditor
			defaultCode="" // 默认""
			readOnly={false} // 默认false
			height="400px" // 默认300px
			theme="night" // 默认day
			activeLine={true} // 默认true
			fold={true} // 默认true
			keywords={keywords} // 默认[]
			onChange={getCode}
		/>
    )
};

ReactDOM.render(
    <Demo />,
    document.getElementById('root')
);

编辑器效果

Image text

props参数:

参数类型默认值是否必填说明
defaultCodestring""非必填初始化赋值
readOnlybooleanfalse非必填设置只读
heightnumber300非必填编辑器高度
themestring"day"非必填主题:"day"和"night"
activeLinebooleantrue非必填当前行选中标识
indentUnitnumber4非必填tab按几个空格缩进
foldbooleantrue非必填代码折叠
keywordsarray[]非必填自定义提示关键词
onChangefunction非必填返回code
Ctrl+F键盘事件-内置自动格式化代码