@flatbiz/antd
Version:
116 lines (112 loc) • 4.16 kB
JavaScript
/*! @flatjs/forge MIT @flatbiz/antd */
import { _ as _objectWithoutProperties, a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js';
import { classNames } from '@dimjs/utils/class-names/class-names';
import { hooks } from '@wove/react/hooks';
import { isObject } from '@dimjs/lang/is-object';
import { useState, useRef, useMemo } from 'react';
import Ace from 'react-ace';
import { isUndefinedOrNull } from '@flatbiz/utils';
import { E as ErrorBoundaryWrapper } from './error-boundary-DtShAEtQ.js';
import 'ace-builds/src-noconflict/ext-language_tools.js';
import 'ace-builds/src-noconflict/mode-java.js';
import 'ace-builds/src-noconflict/snippets/java.js';
import { jsx } from 'react/jsx-runtime';
var _excluded = ["value", "onChange", "height", "autoCompleterList", "onLoad"];
/**
* java编辑器
* ```
* 1. 受控组件,需要使用value、onChange配合显示数据
* 2. heigth 默认为100%,如果外层无高度,需要自定义设置height属性
* 3. 通过 autoCompleterList 配置自动提示关键字
* 4. 通过 hiddenVerifyBtn、hiddenFormatterBtn可隐藏底部操作按钮
* 5. 通过 theme 配置编辑器主题,例如:
* 5.1 顶部引入 import 'ace-builds/src-noconflict/theme-xxxx';
* 5.2 配置 theme = xxxx
* ```
*/
var AceEditorJava = function AceEditorJava(props) {
var value = props.value,
onChange = props.onChange,
height = props.height,
autoCompleterList = props.autoCompleterList,
onLoad = props.onLoad,
otherProps = _objectWithoutProperties(props, _excluded);
var heightFt = isUndefinedOrNull(height) ? '100%' : height;
var _useState = useState(Date.now()),
_useState2 = _slicedToArray(_useState, 2),
rootNodekey = _useState2[0],
setRootNodekey = _useState2[1];
var editorRef = useRef();
var valueNew = useMemo(function () {
if (isObject(value)) {
return JSON.stringify(value, null, 2);
}
return value;
}, [value]);
var getCompletions = hooks.useCallbackRef(function (_a, _b, _c, _d, callback) {
callback(null, autoCompleterList === null || autoCompleterList === void 0 ? void 0 : autoCompleterList.map(function (item) {
return {
name: item.name,
value: item.name,
// score: 100,
meta: item.desc
};
}));
});
var onLoadHandle = function onLoadHandle(editor) {
editorRef.current = editor;
/** 向编辑器中添加自动补全列表 */
var findIndex = editor.completers.findIndex(function (item) {
return item.id === 'custom';
});
if (findIndex >= 0) {
editor.completers[findIndex] = {
getCompletions: getCompletions,
id: 'custom'
};
} else {
editor.completers.push({
getCompletions: getCompletions,
id: 'custom'
});
}
onLoad === null || onLoad === void 0 || onLoad(editor);
};
var Element = (Ace === null || Ace === void 0 ? void 0 : Ace['default']) || Ace;
return /*#__PURE__*/jsx("div", {
className: classNames('ace-editor-java', props.className),
style: _objectSpread2({
height: heightFt
}, props.style),
children: /*#__PURE__*/jsx(ErrorBoundaryWrapper, {
onRenderReset: function onRenderReset() {
onChange === null || onChange === void 0 || onChange(undefined);
setRootNodekey(Date.now());
},
children: /*#__PURE__*/jsx(Element, _objectSpread2(_objectSpread2({
fontSize: 14,
showPrintMargin: true,
showGutter: true,
highlightActiveLine: true,
height: "100%",
width: "auto",
placeholder: "\u8BF7\u8F93\u5165"
}, otherProps), {}, {
setOptions: _objectSpread2({
useWorker: false,
enableBasicAutocompletion: false,
enableLiveAutocompletion: true,
enableSnippets: false,
showLineNumbers: true,
tabSize: 2
}, otherProps.setOptions),
mode: "java",
onLoad: onLoadHandle,
onChange: onChange,
value: valueNew
}))
})
}, rootNodekey);
};
export { AceEditorJava as A };
//# sourceMappingURL=editor-BLm68Fsh.js.map