UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

79 lines 3.42 kB
/** * This file helps avoid jest errors that arise from codemirror node_module files. * Errors like 'Cannot read keyword of undefined', * '(view, highlightActiveLine) is not a function', * 'EditorView is not a constructor' * This errors do not exist during compilation only during testing. */ //Todo this should become redundant with later patches that avoid this error import { EditorView, placeholder, highlightSpecialChars, lineNumbers, highlightActiveLine } from "@codemirror/view"; import { syntaxHighlighting, foldGutter, codeFolding } from "@codemirror/language"; import { Compartment } from "@codemirror/state"; import { lintGutter } from "@codemirror/lint"; /** placeholder extension, current error '_view.placeholder is not a function' */ export var adaptedPlaceholder = function (text) { return typeof placeholder === "function" ? placeholder(text !== null && text !== void 0 ? text : "") : (function () { }); }; function isConstructor(f) { try { new f(); } catch (err) { // verify err is the expected error and then return false; } return true; } /** current error '_view.Editor is not a constructor' */ export var AdaptedEditorView = isConstructor(EditorView) ? EditorView : /** @class */ (function () { function view() { } view.prototype.destroy = function () { }; return view; }()); /** Creates a new compartment or a mock of a compartment. */ export var compartment = function () { if (isConstructor(Compartment)) { return new Compartment(); } else { var extension_1 = undefined; return { of: function (ext) { extension_1 = ext; return ext; }, reconfigure: function (_content) { return {}; }, get: function (_state) { return extension_1; } }; } }; var emptyExtension = (function () { }); /** extension adding event handlers, current error '(view, domEventHandlers) is not a function' */ export var AdaptedEditorViewDomEventHandlers = typeof (EditorView === null || EditorView === void 0 ? void 0 : EditorView.domEventHandlers) == "function" ? EditorView === null || EditorView === void 0 ? void 0 : EditorView.domEventHandlers : emptyExtension; export var adaptedSyntaxHighlighting = function (style) { return typeof syntaxHighlighting === "function" ? syntaxHighlighting(style) : emptyExtension; }; export var adaptedHighlightSpecialChars = function (props) { return typeof highlightSpecialChars === "function" ? highlightSpecialChars(props) : emptyExtension; }; export var adaptedLineNumbers = function (props) { return typeof lineNumbers === "function" ? lineNumbers(props) : emptyExtension; }; export var adaptedHighlightActiveLine = function () { return typeof highlightActiveLine === "function" ? highlightActiveLine() : emptyExtension; }; export var adaptedFoldGutter = function (props) { return typeof foldGutter === "function" ? foldGutter(props) : emptyExtension; }; export var adaptedCodeFolding = function (props) { return typeof codeFolding === "function" ? codeFolding(props) : emptyExtension; }; export var adaptedLintGutter = function (props) { return typeof lintGutter === "function" ? lintGutter(props) : emptyExtension; }; //# sourceMappingURL=codemirrorTestHelper.js.map