UNPKG

@graphiql/react

Version:

[Changelog](https://github.com/graphql/graphiql/blob/main/packages/graphiql-react/CHANGELOG.md) | [API Docs](https://graphiql-test.netlify.app/typedoc/modules/graphiql_react.html) | [NPM](https://www.npmjs.com/package/@graphiql/react)

80 lines (79 loc) 2.21 kB
import { monacoStore } from "../stores/monaco.js"; import { URI } from "monaco-editor/esm/vs/base/common/uri.js"; const onEditorContainerKeyDown = (event) => { var _a; const el = event.currentTarget; const isFocused = el === document.activeElement; if (isFocused && event.code === "Enter") { event.preventDefault(); (_a = el.querySelector("textarea")) == null ? void 0 : _a.focus(); } }; function getOrCreateModel({ uri: $uri, value }) { const { monaco } = monacoStore.getState(); if (!monaco) { throw new Error("Monaco editor is not initialized"); } const uri = URI.file($uri); const model = monaco.editor.getModel(uri); const language = uri.path.split(".").at(-1); return model ?? monaco.editor.createModel(value, language, uri); } function createEditor(domElement, options) { const { model } = options; if (!model) { throw new Error("options.model is required"); } const language = model.uri.path.split(".").at(-1); const { monaco } = monacoStore.getState(); if (!monaco) { throw new Error("Monaco editor is not initialized"); } return monaco.editor.create(domElement.current, { language, automaticLayout: true, fontSize: 15, minimap: { enabled: false }, // disable the minimap tabSize: 2, renderLineHighlight: "none", // Remove a line selection border stickyScroll: { enabled: false }, // Disable sticky scroll widget overviewRulerLanes: 0, // remove unnecessary error highlight on the scroll scrollbar: { verticalScrollbarSize: 10 }, scrollBeyondLastLine: false, // cleans up unnecessary "padding-bottom" on each editor fontFamily: '"Fira Code"', // Enable font ligatures and fix incorrect caret position on Windows // See: https://github.com/graphql/graphiql/issues/4040 fontLigatures: true, lineNumbersMinChars: 2, // reduce line numbers width on the left size tabIndex: -1, // Do not allow tabbing into the editor, only via by pressing Enter or its container ...options }); } export { createEditor, getOrCreateModel, onEditorContainerKeyDown }; //# sourceMappingURL=create-editor.js.map