@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
55 lines • 3.33 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import React from "react";
import { Classes as BlueprintClassNames } from "@blueprintjs/core";
import { EditorState } from "@codemirror/state";
import { EditorView, lineNumbers } from "@codemirror/view";
import { CLASSPREFIX as eccgui } from "../../configuration/constants.js";
import { CodeEditor } from "../../extensions/codemirror/CodeMirror.js";
/** Supports single-line and multiline editing. */
export var ExtendedCodeEditor = function (_a) {
var _b = _a.multiline, multiline = _b === void 0 ? false : _b, _c = _a.initialValue, initialValue = _c === void 0 ? "" : _c, onKeyDown = _a.onKeyDown, _d = _a.enableTab, enableTab = _d === void 0 ? false : _d, mode = _a.mode, setCM = _a.setCM, onFocusChange = _a.onFocusChange, onMouseDown = _a.onMouseDown, onChange = _a.onChange, placeholder = _a.placeholder, onCursorChange = _a.onCursorChange, onSelection = _a.onSelection, codeEditorProps = _a.codeEditorProps, height = _a.height, readOnly = _a.readOnly;
var initialContent = React.useRef(multiline ? initialValue : initialValue.replace(/[\r\n]/g, " "));
var multilineExtensions = multiline
? [lineNumbers(), EditorView.lineWrapping]
: [
EditorState === null || EditorState === void 0 ? void 0 : EditorState.transactionFilter.of(function (tr) { return (tr.newDoc.lines > 1 ? [] : tr); }),
];
return (React.createElement(CodeEditor, __assign({ defaultValue: initialContent.current, setEditorView: setCM, onSelection: onSelection, onMouseDown: onMouseDown, onChange: onChange, placeholder: placeholder, onCursorChange: onCursorChange, onFocusChange: onFocusChange, onKeyDown: onKeyDown, shouldHaveMinimalSetup: false, preventLineNumbers: !multiline, mode: mode, height: height, readOnly: readOnly, name: "", enableTab: enableTab, additionalExtensions: __spreadArray([], __read(multilineExtensions), false), className: multiline ? undefined : "".concat(eccgui, "-singlelinecodeeditor ").concat(BlueprintClassNames.INPUT) }, codeEditorProps)));
};
export default ExtendedCodeEditor;
//# sourceMappingURL=ExtendedCodeEditor.js.map