UNPKG

@eccenca/gui-elements

Version:

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

73 lines 4.1 kB
"use strict"; /** * 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 Object.defineProperty(exports, "__esModule", { value: true }); exports.adaptedLintGutter = exports.adaptedCodeFolding = exports.adaptedFoldGutter = exports.adaptedHighlightActiveLine = exports.adaptedLineNumbers = exports.adaptedHighlightSpecialChars = exports.adaptedSyntaxHighlighting = exports.AdaptedEditorViewDomEventHandlers = exports.compartment = exports.AdaptedEditorView = exports.adaptedPlaceholder = void 0; const view_1 = require("@codemirror/view"); const language_1 = require("@codemirror/language"); const state_1 = require("@codemirror/state"); const lint_1 = require("@codemirror/lint"); /** placeholder extension, current error '_view.placeholder is not a function' */ const adaptedPlaceholder = (text) => typeof view_1.placeholder === "function" ? (0, view_1.placeholder)(text !== null && text !== void 0 ? text : "") : (() => { }); exports.adaptedPlaceholder = adaptedPlaceholder; 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' */ exports.AdaptedEditorView = isConstructor(view_1.EditorView) ? view_1.EditorView : class view { constructor() { } destroy() { } }; /** Creates a new compartment or a mock of a compartment. */ const compartment = () => { if (isConstructor(state_1.Compartment)) { return new state_1.Compartment(); } else { let extension = undefined; return { of: (ext) => { extension = ext; return ext; }, reconfigure: (_content) => { return {}; }, get: (_state) => extension }; } }; exports.compartment = compartment; const emptyExtension = (() => { }); /** extension adding event handlers, current error '(view, domEventHandlers) is not a function' */ exports.AdaptedEditorViewDomEventHandlers = typeof (view_1.EditorView === null || view_1.EditorView === void 0 ? void 0 : view_1.EditorView.domEventHandlers) == "function" ? view_1.EditorView === null || view_1.EditorView === void 0 ? void 0 : view_1.EditorView.domEventHandlers : emptyExtension; const adaptedSyntaxHighlighting = (style) => typeof language_1.syntaxHighlighting === "function" ? (0, language_1.syntaxHighlighting)(style) : emptyExtension; exports.adaptedSyntaxHighlighting = adaptedSyntaxHighlighting; const adaptedHighlightSpecialChars = (props) => typeof view_1.highlightSpecialChars === "function" ? (0, view_1.highlightSpecialChars)(props) : emptyExtension; exports.adaptedHighlightSpecialChars = adaptedHighlightSpecialChars; const adaptedLineNumbers = (props) => typeof view_1.lineNumbers === "function" ? (0, view_1.lineNumbers)(props) : emptyExtension; exports.adaptedLineNumbers = adaptedLineNumbers; const adaptedHighlightActiveLine = () => typeof view_1.highlightActiveLine === "function" ? (0, view_1.highlightActiveLine)() : emptyExtension; exports.adaptedHighlightActiveLine = adaptedHighlightActiveLine; const adaptedFoldGutter = (props) => typeof language_1.foldGutter === "function" ? (0, language_1.foldGutter)(props) : emptyExtension; exports.adaptedFoldGutter = adaptedFoldGutter; const adaptedCodeFolding = (props) => typeof language_1.codeFolding === "function" ? (0, language_1.codeFolding)(props) : emptyExtension; exports.adaptedCodeFolding = adaptedCodeFolding; const adaptedLintGutter = (props) => typeof lint_1.lintGutter === "function" ? (0, lint_1.lintGutter)(props) : emptyExtension; exports.adaptedLintGutter = adaptedLintGutter; //# sourceMappingURL=codemirrorTestHelper.js.map