Connect, collaborate, and grow with a community of TypeScript developers
fixed the monaco-vim loading (#297)
ggrandi476c96be1f00
diff --git a/package.json b/package.jsonindex e9ca2a89..53f0b484 100644--- a/package.json+++ b/package.json@@ -111,7 +111,8 @@"pnpm": {"patchedDependencies": {"[email protected]": "patches/[email protected]",- "@monaco-editor/[email protected]": "patches/@[email protected]"+ "@monaco-editor/[email protected]": "patches/@[email protected]",+ "[email protected]": "patches/[email protected]"}},"lint-staged": {diff --git a/patches/[email protected] b/patches/[email protected]new file mode 100644index 00000000..f883ca01--- /dev/null+++ b/patches/[email protected]@@ -0,0 +1,65 @@+diff --git a/package.json b/package.json+index 632ffb9d6507c634c3ab7aabb147d51c346df29c..7703a7c3e107f0d99550c9053dd3927329610639 100644+--- a/package.json++++ b/package.json+@@ -2,7 +2,7 @@+ "name": "monaco-vim",+ "version": "0.4.0",+ "description": "Vim keybindings for monaco-editor",+- "main": "./lib/index.js",++ "main": "./src/index.mjs",+ "scripts": {+ "test": "echo \"No test in this repo\"",+ "start": "webpack-dev-server --mode development --host=0.0.0.0 --port=8080",+diff --git a/src/cm/keymap_vim.js b/src/cm/keymap_vim.mjs+similarity index 100%+rename from src/cm/keymap_vim.js+rename to src/cm/keymap_vim.mjs+diff --git a/src/cm_adapter.js b/src/cm_adapter.mjs+similarity index 98%+rename from src/cm_adapter.js+rename to src/cm_adapter.mjs+index d4c81a13d4d355496062dd462a7faa8690e816cd..37b8d7b1bc69bca841eb92f90e9a83093b21bdb4 100644+--- a/src/cm_adapter.js++++ b/src/cm_adapter.mjs+@@ -1,15 +1,24 @@+ /**+ * An adapter to make CodeMirror's vim bindings work with monaco+ */+-import {++const {+ KeyCode,+ Range,+ Position,+ Selection,+ SelectionDirection,+- editor as monacoEditor,+-} from "monaco-editor/esm/vs/editor/editor.api";+-import { ShiftCommand } from "monaco-editor/esm/vs/editor/common/commands/shiftCommand";++ editor: monacoEditor,++} = globalThis.monaco;++const { ShiftCommand } = await new Promise((resolve) => {++ // check if monaco has loaded++ if ('require' in globalThis) {++ return require(['vs/editor/common/commands/shiftCommand'], resolve);++ }++++ // fallback++ console.warn("couldn't load the monaco plugin, ignore on the server");++ resolve({ ShiftCommand() {} });++});+ const VerticalRevealType = {+ Bottom: 4,+ };+diff --git a/src/demo.js b/src/demo.mjs+similarity index 100%+rename from src/demo.js+rename to src/demo.mjs+diff --git a/src/index.js b/src/index.mjs+similarity index 100%+rename from src/index.js+rename to src/index.mjs+diff --git a/src/statusbar.js b/src/statusbar.mjs+similarity index 100%+rename from src/statusbar.js+rename to src/statusbar.mjsdiff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 20109331..c5e555a4 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -8,6 +8,9 @@ patchedDependencies:'@monaco-editor/[email protected]':hash: xep4qb27qzc6gvlhv2fxe3r2kapath: patches/@[email protected]+ hash: j3oqxjoadtct3pc6tokddngzsm+ path: patches/[email protected]hash: mr6pbhgbmy4dt4xo4hxm5k4ym4path: patches/[email protected]@@ -111,7 +114,7 @@ dependencies:version: 0.40.0monaco-vim:specifier: ^0.4.0- version: 0.4.0([email protected])+ version: 0.4.0(patch_hash=j3oqxjoadtct3pc6tokddngzsm)([email protected])next:specifier: ^13.4.10version: 13.4.10([email protected])([email protected])@@ -5270,13 +5273,14 @@ packages:resolution: {integrity: sha512-1wymccLEuFSMBvCk/jT1YDW/GuxMLYwnFwF9CDyYCxoTw2Pt379J3FUhwy9c43j51JdcxVPjwk0jm0EVDsBS2g==}dev: false+ /[email protected](patch_hash=j3oqxjoadtct3pc6tokddngzsm)([email protected]):resolution: {integrity: sha512-+CsW0+Mvx2+eitkXS7OpUXIu57qXlqAL8oVkYhkPCEZ/c6+6gOp/IcG7w+Lb33YiZuTyvJ891+czkeJRPIEwVA==}peerDependencies:monaco-editor: '*'dependencies:monaco-editor: 0.40.0dev: false+ patched: trueresolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==}diff --git a/scripts/dl-monaco.ts b/scripts/dl-monaco.tsindex 4692a96b..ebbebcb8 100644--- a/scripts/dl-monaco.ts+++ b/scripts/dl-monaco.ts@@ -70,6 +70,10 @@ const files = ['/min/vs/base/common/worker/simpleWorker.nls.js','./public/vs/base/common/worker/simpleWorker.nls.js',],+ [+ './vs/base/browser/ui/codicons/codicon/codicon.ttf',+ './public/vs/base/browser/ui/codicons/codicon/codicon.ttf'+ ],] as const;async function isTSversionCorrect(path: string) {@@ -91,12 +95,12 @@ const force = process.argv.includes('--force');// get the path to the root monaco-editor.d.ts fileconst dTSPath = url.fileURLToPath(path.join(import.meta.url, '../../', files[0][1]));-// is the version exciting && correct+// is the version existing && correctconst isCorrectVersionInstalled = await isTSversionCorrect(dTSPath);if (force || !isCorrectVersionInstalled) {if (force) {- console.log(`π¨ Using force ovrwrites public/vs and monaco-editor.d.ts`);+ console.log(`π¨ Using force overwrites public/vs and monaco-editor.d.ts`);}console.log(`π Downloading monaco-editor with typescript: ${TYPESCRIPT_VERSION}`);await Promise.all(files.map(downloadAndSaveFile));diff --git a/src/components/challenge/code-panel/editor-types.ts b/src/components/challenge/code-panel/editor-types.tsindex 11c3ac11..0ee01100 100644--- a/src/components/challenge/code-panel/editor-types.ts+++ b/src/components/challenge/code-panel/editor-types.ts@@ -4,33 +4,92 @@* based on: https://github.com/type-challenges/type-challenges/blob/main/utils/index.d.ts*/export const libSource = `-type Expect<T extends true> = T-type ExpectTrue<T extends true> = T-type ExpectFalse<T extends false> = T-type IsTrue<T extends true> = T-type IsFalse<T extends false> = T--type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true-type Equal<X, Y> =- (<T>() => T extends X ? 1 : 2) extends- (<T>() => T extends Y ? 1 : 2) ? true : false--// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360-type IsAny<T> = 0 extends (1 & T) ? true : false-type NotAny<T> = true extends IsAny<T> ? false : true--type Debug<T> = { [K in keyof T]: T[K] }-type MergeInsertions<T> =- T extends object- ? { [K in keyof T]: MergeInsertions<T[K]> }- : T--type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>--type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false-type ExpectValidArgs<FUNC extends (...args: any[]) => any, ARGS extends any[]> = ARGS extends Parameters<FUNC>+type Expect<T extends true> = T;+type ExpectTrue<T extends true> = T;+type ExpectFalse<T extends false> = T;+type IsTrue<T extends true> = T;+type IsFalse<T extends false> = T;++type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;+type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y+ ? 1+ : 2? true- : false+ : false;++type IsAny<T> = 0 extends 1 & T ? true : false;+type NotAny<T> = true extends IsAny<T> ? false : true;++type Debug<T> = { [K in keyof T]: T[K] };+type MergeInsertions<T> = T extends object+ ? { [K in keyof T]: MergeInsertions<T[K]> }+ : T;++type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;++type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false;+type ExpectValidArgs<+ FUNC extends (...args: any[]) => any,+ ARGS extends any[]+> = ARGS extends Parameters<FUNC> ? true : false;++type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (+ k: infer I+) => void+ ? I+ : never;++type NoInfer<T> = [T][T extends any ? 0 : never];++type IsUnion<T, U = T> = [T] extends [never]+ ? false+ : T extends unknown+ ? [U] extends [T]+ ? false+ : true+ : false;++declare function id<T>(): T;-type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never+/**+ * Helper function to test your code.+ *+ * Checks if two types have all the same properties and modifiers+ *+ * To check what it is failing, you can hover over \`Equal\` and see what the types failing are+ */+declare function Equal<A, B>(+ ...args: [+ ...([a: A, b: B] | []),+ ...(Alike<A, B> extends true ? [] : [msg: "not equal"])+ ]+): void;++/**+ * Helper function to test your code.+ *+ * Checks that two types aren't the same+ *+ * To check what it is failing, you can hover over \`NotEqual\` and see what the types failing are+ */+declare function NotEqual<A, B>(+ ...args: [+ ...([a: A, b: B] | []),+ ...(Alike<A, B> extends true ? [msg: "equal"] : [])+ ]+): void;++/**+ * Helper function to test your code.+ *+ * Checks if type \`A\` extends \`B\`+ *+ * To check what it is failing, you can hover over \`Extends\` and see what the types failing are+ */+declare function Extends<A, B>(+ ...args: [+ ...([a: A, b: B] | []),+ ...(A extends B ? [] : [msg: [A, "doesn't extend", B]])+ ]+): void;`;diff --git a/src/components/challenge/code-panel/index.tsx b/src/components/challenge/code-panel/index.tsxindex b0d11097..1dd37d9d 100644--- a/src/components/challenge/code-panel/index.tsx+++ b/src/components/challenge/code-panel/index.tsx@@ -4,7 +4,6 @@ import { loader } from '@monaco-editor/react';import clsx from 'clsx';import { Loader2, Settings } from 'lucide-react';import type * as monaco from 'monaco-editor';-import { initVimMode } from 'monaco-vim';import { useSession } from 'next-auth/react';import dynamic from 'next/dynamic';import { useRouter } from 'next/navigation';@@ -205,7 +204,7 @@ export const CodePanel = (props: Props) => {'sticky bottom-0 flex items-center justify-end p-2 dark:bg-[#1e1e1e]',)}>- {editorState && <VimStatusBar editor={editorState} initVimMode={initVimMode} />}+ {editorState && <VimStatusBar editor={editorState} />}<div className="flex items-center justify-center gap-4"><Tooltip><TooltipTrigger asChild>diff --git a/src/components/challenge/code-panel/vimMode.tsx b/src/components/challenge/code-panel/vimMode.tsxindex f812c4d5..a1a345d1 100644--- a/src/components/challenge/code-panel/vimMode.tsx+++ b/src/components/challenge/code-panel/vimMode.tsx@@ -1,15 +1,14 @@'use client';import type * as monaco from 'monaco-editor';-import { type initVimMode, type VimMode } from 'monaco-vim';import { useEffect, useRef } from 'react';import { useEditorSettingsStore } from '../settings-store';+import { type VimMode, initVimMode } from 'monaco-vim';interface VimStatusBarProps {editor: monaco.editor.IStandaloneCodeEditor;- initVimMode: typeof initVimMode;}-export const VimStatusBar = ({ editor, initVimMode }: VimStatusBarProps) => {+export const VimStatusBar = ({ editor }: VimStatusBarProps) => {const statusBarRef = useRef<HTMLDivElement | null>(null);const vimModeRef = useRef<VimMode>();const { settings } = useEditorSettingsStore();@@ -26,7 +25,7 @@ export const VimStatusBar = ({ editor, initVimMode }: VimStatusBarProps) => {statusBarRef.current.textContent = '';}}- }, [editor, initVimMode, settings.bindings]);+ }, [editor, settings.bindings]);return (<div className="flex w-full">diff --git a/tsconfig.json b/tsconfig.jsonindex 086bf983..f323b5f8 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -3,7 +3,7 @@"target": "es2017","lib": ["dom", "dom.iterable", "esnext"],"allowJs": true,- "checkJs": true,+ "checkJs": false,"skipLibCheck": true,"strict": true,"forceConsistentCasingInFileNames": true,