feat: CodeMirror 6 editor with in-editor search/replace
- bundle CodeMirror 6 (+ langs/search) via scripts/build-editor.mjs into a generated TS module (inlined into the WebView; no remote code, no asset pipeline) - CodeEditor now renders CodeMirror 6 with line numbers, language modes and a search/replace panel exposed from a toolbar button - npm run build:editor; language mapping by file extension
This commit is contained in:
1 parent
a104d65978
commit
883440b8be
8 files changed
+1164
-110
No files matched your search
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Bundles the CodeMirror 6 entry (`scripts/codemirror-entry.mjs`) into a single
|
||||
* IIFE string inside `src/components/git/codemirror-bundle.ts`.
|
||||
*
|
||||
* Run with `npm run build:editor`. The generated module is committed so the app
|
||||
* builds without a JS bundling step at runtime.
|
||||
*/
|
||||
|
||||
import { writeFileSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { build } from 'esbuild';
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const entry = resolve(root, 'scripts/codemirror-entry.mjs');
|
||||
const output = resolve(root, 'src/components/git/codemirror-bundle.ts');
|
||||
|
||||
const result = await build({
|
||||
entryPoints: [entry],
|
||||
bundle: true,
|
||||
format: 'iife',
|
||||
minify: true,
|
||||
write: false,
|
||||
platform: 'browser',
|
||||
target: 'es2020',
|
||||
legalComments: 'none',
|
||||
});
|
||||
|
||||
const code = result.outputFiles[0].text;
|
||||
const safe = code.replace(/<\/script/gi, '<\\/script');
|
||||
|
||||
const module = `/**
|
||||
* AUTO-GENERATED by scripts/build-editor.mjs — do not edit by hand.
|
||||
* Bundled CodeMirror 6 editor (see scripts/codemirror-entry.mjs).
|
||||
*/
|
||||
export const CODE_MIRROR_BUNDLE = ${JSON.stringify(safe)};
|
||||
`;
|
||||
|
||||
writeFileSync(output, module);
|
||||
console.log(`Wrote ${output} (${code.length} bytes)`);
|
||||
Reference in new issue
Block a user