Feat(CodeEditor): Support add extra libs

This commit is contained in:
2024-10-16 18:14:18 +08:00
parent b353ab07e2
commit 47dac4c9c7
10 changed files with 47 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
interface NativeApi {
/**
* Copy text to clipboard
*
* @param {string} text Text to be copied to clipboard
* @returns {boolean} Result
*/
copyToClipboard: (text: string) => boolean
/**
* Read text from clipboard
*
* @returns {string} Result
*/
readClipboard: () => string
/**
* Save file to download directory
*
* @param {string} dataBase64 Base64 encoded data
* @param {string} fileName File name to be saved
* @returns {boolean} Result
*
* @example
* // From Unit8Array:
* NativeApi.saveToDownloads(btoa(String.fromCharCode(...data)))
* // From string:
* NativeApi.saveToDownloads(btoa(String.fromCharCode(...new TextEncoder().encode(text))))
*/
saveToDownloads: (dataBase64: string, fileName: string) => boolean
}
declare const NativeApi: NativeApi

7
src/util/editorExtraLibs/_index.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
interface Window {
/**
* Initialization tool.\
* This method must be implemented to run the tool.
*/
initOxygenTool: (id: string) => void
}

View File

@@ -0,0 +1,16 @@
import { ExtraLib } from '@/components/Playground/CodeEditor/Editor'
import indexDTS from '@/util/editorExtraLibs/_index.d.ts?raw'
import nativeApiDTS from '@/util/editorExtraLibs/_NativeApi.d.ts?raw'
const editorExtraLibs: ExtraLib[] = [
{
path: 'file:///node_modules/_index.d.ts',
content: indexDTS
},
{
path: 'file:///node_modules/_NativeApi.d.ts',
content: nativeApiDTS
}
]
export default editorExtraLibs