This commit is contained in:
2025-04-03 19:29:57 +08:00
parent 521255c1af
commit 9add82dc7e
28 changed files with 749 additions and 267 deletions

View File

@@ -20,6 +20,7 @@ type BaseEditorOpts = {
open?: boolean;
overrideList?: Completion[];
};
onChange?: (value: string) => void;
};
export class BaseEditor {
editor?: EditorView;
@@ -32,7 +33,7 @@ export class BaseEditor {
open?: boolean;
overrideList?: Completion[];
};
onChange?: (value: string) => void;
constructor(opts?: BaseEditorOpts) {
this.filename = opts?.filename || '';
this.language = opts?.language || 'typescript';
@@ -43,6 +44,7 @@ export class BaseEditor {
}
this.autoComplete = opts?.autoComplete || { open: true, overrideList: [] };
this.onChangeCompartment = new Compartment(); // 创建一个用于 onChange 的独立扩展
this.onChange = opts?.onChange;
}
onEditorChange(view: EditorView) {
console.log('onChange', view);
@@ -54,6 +56,7 @@ export class BaseEditor {
this.el = el;
const onChangeCompartment = this.onChangeCompartment!;
const language = this.language;
const onChange = this.onChange;
const extensions: Extension[] = [
vscodeLight,
formatKeymap,
@@ -91,7 +94,15 @@ export class BaseEditor {
parent: el,
extensions: [
...extensions, //
onChangeCompartment.of([]),
onChangeCompartment.of([
[
EditorView.updateListener.of((update) => {
if (update.changes.length > 0) {
onChange?.(update.state.doc.toString());
}
}),
],
]),
],
});
}

View File

@@ -3,7 +3,7 @@ export { PermissionManager } from './pages/file/modules/PermissionManager.tsx';
export { PermissionModal, usePermissionModal } from './pages/file/modules/PermissionModal.tsx';
export { iText } from './i-text/index.ts';
export { uploadFiles, uploadFileChunked, getDirectoryAndName, toFile, createDirectory } from './pages/upload/app';
export { uploadFiles, uploadFileChunked, getDirectoryAndName, createDirectory } from './pages/upload/app';
export { DialogDirectory, DialogDeleteDirectory } from './pages/upload/DialogDirectory';
export { uploadChunkV2 } from './pages/upload/v2/upload-chunk';
export { uploadChunkV2, toFile } from './pages/upload/v2/upload-chunk';

View File

@@ -4,7 +4,7 @@ import { Id, toast } from 'react-toastify';
import { nanoid } from 'nanoid';
import { toastLogin } from '@kevisual/resources/pages/message/ToastLogin';
import { uploadFileChunked, UploadProgress } from '@kevisual/query-upload/query-upload';
import { toFile } from '@kevisual/query-upload/query-upload';
export type ConvertOpts = {
appKey?: string;
version?: string;
@@ -12,6 +12,10 @@ export type ConvertOpts = {
directory?: string;
isPublic?: boolean;
filename?: string;
/**
* 是否不检查应用文件, 默认 true默认不检测
*/
noCheckAppFiles?: boolean;
};
export const uploadChunkV2 = async (file: File, opts: ConvertOpts) => {
@@ -53,3 +57,4 @@ export const uploadChunkV2 = async (file: File, opts: ConvertOpts) => {
});
return result;
};
export { toFile };