This commit is contained in:
熊潇 2025-05-12 14:33:04 +08:00
parent 64bc50f1e8
commit 55b1c5fdca
8 changed files with 39 additions and 53462 deletions

View File

@ -8,13 +8,13 @@ node_modules
dist
# build
/build
build
/logs
logs
.turbo
/pack-dist
pack-dist
# astro
.astro

View File

@ -1,19 +0,0 @@
import { EditorView } from 'codemirror';
declare let editor: EditorView;
type CreateOpts = {
jsx?: boolean;
typescript?: boolean;
};
/**
*
* @param el
* @returns
*/
declare const createEditorInstance: (el?: HTMLDivElement, opts?: CreateOpts) => EditorView;
/**
*
* @param el
* @returns
*/
export declare const createEditor: (el: HTMLDivElement, opts?: CreateOpts) => EditorView;
export { editor, createEditorInstance };

File diff suppressed because one or more lines are too long

View File

@ -1,15 +0,0 @@
import { EditorView } from 'codemirror';
declare let editor: EditorView;
/**
*
* @param el
* @returns
*/
declare const createEditorInstance: (el?: HTMLDivElement) => EditorView;
/**
*
* @param el
* @returns
*/
export declare const createEditor: (el: HTMLDivElement) => EditorView;
export { editor, createEditorInstance };

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@kevisual/codemirror",
"version": "0.0.5",
"version": "0.0.7",
"description": "",
"main": "dist/editor.js",
"private": false,

View File

@ -4,6 +4,7 @@ let editor: EditorView = null;
export type EditorOptions = {
extensions?: any[];
hasBasicSetup?: boolean;
};
/**
*
@ -18,8 +19,12 @@ const createEditorInstance = (el?: HTMLDivElement, opts?: EditorOptions) => {
return editor;
}
const extensions = opts?.extensions || [];
const hasBaseicSetup = opts?.hasBasicSetup ?? true;
if (hasBaseicSetup) {
extensions.unshift(basicSetup);
}
editor = new EditorView({
extensions: [basicSetup, ...extensions],
extensions: extensions,
parent: el || document.body,
});
editor.dom.style.height = '100%';
@ -33,8 +38,12 @@ const createEditorInstance = (el?: HTMLDivElement, opts?: EditorOptions) => {
*/
export const createEditor = (el: HTMLDivElement, opts?: EditorOptions) => {
const extensions = opts?.extensions || [];
const hasBaseicSetup = opts?.hasBasicSetup ?? true;
if (hasBaseicSetup) {
extensions.unshift(basicSetup);
}
const editor = new EditorView({
extensions: [basicSetup, ...extensions],
extensions,
parent: el || document.body,
});
editor.dom.style.height = '100%';

View File

@ -10,6 +10,8 @@ type CreateOpts = {
jsx?: boolean;
typescript?: boolean;
type?: 'javascript' | 'json' | 'html' | 'markdown' | 'css';
hasBasicSetup?: boolean;
extensions?: any[];
};
/**
*
@ -24,27 +26,30 @@ const createEditorInstance = (el?: HTMLDivElement, opts?: CreateOpts) => {
return editor;
}
const { type = 'javascript' } = opts || {};
const plugins = [basicSetup];
const extensions = opts?.extensions || [];
const hasBaseicSetup = opts?.hasBasicSetup ?? true;
if (hasBaseicSetup) {
extensions.unshift(basicSetup);
}
switch (type) {
case 'json':
plugins.push(json());
extensions.push(json());
break;
case 'javascript':
plugins.push(javascript({ jsx: opts?.jsx, typescript: opts?.typescript }));
extensions.push(javascript({ jsx: opts?.jsx, typescript: opts?.typescript }));
break;
case 'css':
plugins.push(css());
extensions.push(css());
break;
case 'html':
plugins.push(html());
extensions.push(html());
break;
case 'markdown':
plugins.push(markdown());
extensions.push(markdown());
break;
}
editor = new EditorView({
extensions: plugins,
extensions: extensions,
parent: el || document.body,
});
editor.dom.style.height = '100%';
@ -58,26 +63,30 @@ const createEditorInstance = (el?: HTMLDivElement, opts?: CreateOpts) => {
*/
export const createEditor = (el: HTMLDivElement, opts?: CreateOpts) => {
const { type = 'javascript' } = opts || {};
const plugins = [basicSetup];
const extensions = opts?.extensions || [];
const hasBaseicSetup = opts?.hasBasicSetup ?? true;
if (hasBaseicSetup) {
extensions.unshift(basicSetup);
}
switch (type) {
case 'json':
plugins.push(json());
extensions.push(json());
break;
case 'javascript':
plugins.push(javascript({ jsx: opts?.jsx, typescript: opts?.typescript }));
extensions.push(javascript({ jsx: opts?.jsx, typescript: opts?.typescript }));
break;
case 'css':
plugins.push(css());
extensions.push(css());
break;
case 'html':
plugins.push(html());
extensions.push(html());
break;
case 'markdown':
plugins.push(markdown());
extensions.push(markdown());
break;
}
const editor = new EditorView({
extensions: plugins,
extensions: extensions,
parent: el || document.body,
});
editor.dom.style.height = '100%';