mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
feat(ui): add c-monaco-editor to ui lib
This commit is contained in:
parent
9390435366
commit
e10beda5b0
5 changed files with 165 additions and 0 deletions
1
components.d.ts
vendored
1
components.d.ts
vendored
|
@ -50,6 +50,7 @@ declare module '@vue/runtime-core' {
|
|||
'CModal.demo': typeof import('./src/ui/c-modal/c-modal.demo.vue')['default']
|
||||
CModalValue: typeof import('./src/ui/c-modal-value/c-modal-value.vue')['default']
|
||||
'CModalValue.demo': typeof import('./src/ui/c-modal-value/c-modal-value.demo.vue')['default']
|
||||
CMonacoEditor: typeof import('./src/ui/c-monaco-editor/c-monaco-editor.vue')['default']
|
||||
CollapsibleToolMenu: typeof import('./src/components/CollapsibleToolMenu.vue')['default']
|
||||
ColorConverter: typeof import('./src/tools/color-converter/color-converter.vue')['default']
|
||||
ColoredCard: typeof import('./src/components/ColoredCard.vue')['default']
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
"release": "node ./scripts/release.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@guolao/vue-monaco-editor": "^1.4.1",
|
||||
"@it-tools/bip39": "^0.0.4",
|
||||
"@it-tools/oggen": "^1.3.0",
|
||||
"@sindresorhus/slugify": "^2.2.1",
|
||||
|
|
32
pnpm-lock.yaml
generated
32
pnpm-lock.yaml
generated
|
@ -5,6 +5,9 @@ settings:
|
|||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
'@guolao/vue-monaco-editor':
|
||||
specifier: ^1.4.1
|
||||
version: 1.5.1(monaco-editor@0.43.0)(vue@3.3.4)
|
||||
'@it-tools/bip39':
|
||||
specifier: ^0.0.4
|
||||
version: 0.0.4
|
||||
|
@ -2153,6 +2156,22 @@ packages:
|
|||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
dev: true
|
||||
|
||||
/@guolao/vue-monaco-editor@1.5.1(monaco-editor@0.43.0)(vue@3.3.4):
|
||||
resolution: {integrity: sha512-nhbQHDAwsxrdH/yitcrBgAkN8Cae0IEiYe/M3LWK8bSJRfapkbMyfTHE6Gcxsxa/6efSUZAPDo8dJWBDx5GZyA==}
|
||||
peerDependencies:
|
||||
'@vue/composition-api': ^1.7.1
|
||||
monaco-editor: '>=0.43.0'
|
||||
vue: ^2.6.14 || >=3.0.0
|
||||
peerDependenciesMeta:
|
||||
'@vue/composition-api':
|
||||
optional: true
|
||||
dependencies:
|
||||
'@monaco-editor/loader': 1.4.0(monaco-editor@0.43.0)
|
||||
monaco-editor: 0.43.0
|
||||
vue: 3.3.4
|
||||
vue-demi: 0.14.7(vue@3.3.4)
|
||||
dev: false
|
||||
|
||||
/@humanwhocodes/config-array@0.11.10:
|
||||
resolution: {integrity: sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==}
|
||||
engines: {node: '>=10.10.0'}
|
||||
|
@ -2420,6 +2439,15 @@ packages:
|
|||
resolution: {integrity: sha512-mrC4y8n88BYvgcgzq9bvTlDgFyi2zuvzmPilRvRc3Uz1iIvq8mDhxJ0rHKFUNzPEScpDvJdIujqiDrulMqiudA==}
|
||||
dev: true
|
||||
|
||||
/@monaco-editor/loader@1.4.0(monaco-editor@0.43.0):
|
||||
resolution: {integrity: sha512-00ioBig0x642hytVspPl7DbQyaSWRaolYie/UFNjoTdvoKPzo6xrXLhTk9ixgIKcLH5b5vDOjVNiGyY+uDCUlg==}
|
||||
peerDependencies:
|
||||
monaco-editor: '>= 0.21.0 < 1'
|
||||
dependencies:
|
||||
monaco-editor: 0.43.0
|
||||
state-local: 1.0.7
|
||||
dev: false
|
||||
|
||||
/@nodelib/fs.scandir@2.1.5:
|
||||
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
||||
engines: {node: '>= 8'}
|
||||
|
@ -8213,6 +8241,10 @@ packages:
|
|||
resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==}
|
||||
dev: true
|
||||
|
||||
/state-local@1.0.7:
|
||||
resolution: {integrity: sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w==}
|
||||
dev: false
|
||||
|
||||
/std-env@3.3.3:
|
||||
resolution: {integrity: sha512-Rz6yejtVyWnVjC1RFvNmYL10kgjC49EOghxWn0RFqlCHGFpQx+Xe7yW3I4ceK1SGrWIGMjD5Kbue8W/udkbMJg==}
|
||||
dev: true
|
||||
|
|
|
@ -2,6 +2,9 @@ import { createApp } from 'vue';
|
|||
import { createPinia } from 'pinia';
|
||||
import { createHead } from '@vueuse/head';
|
||||
|
||||
import { install as VueMonacoEditorPlugin, loader } from '@guolao/vue-monaco-editor';
|
||||
import * as monaco from 'monaco-editor';
|
||||
|
||||
import { registerSW } from 'virtual:pwa-register';
|
||||
import { plausible } from './plugins/plausible.plugin';
|
||||
|
||||
|
@ -13,10 +16,14 @@ import App from './App.vue';
|
|||
import router from './router';
|
||||
import { i18nPlugin } from './plugins/i18n.plugin';
|
||||
|
||||
// loaded monaco-editor from `node_modules`
|
||||
loader.config({ monaco });
|
||||
|
||||
registerSW();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(VueMonacoEditorPlugin);
|
||||
app.use(createPinia());
|
||||
app.use(createHead());
|
||||
app.use(i18nPlugin);
|
||||
|
|
124
src/ui/c-monaco-editor/c-monaco-editor.vue
Normal file
124
src/ui/c-monaco-editor/c-monaco-editor.vue
Normal file
|
@ -0,0 +1,124 @@
|
|||
<script setup lang="ts">
|
||||
import * as monacoEditor from 'monaco-editor';
|
||||
import type { MonacoEditor } from '@guolao/vue-monaco-editor';
|
||||
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
||||
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
||||
import CssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
|
||||
import HtmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
|
||||
import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
const props = withDefaults(defineProps<EditorProps>(), {
|
||||
theme: 'vs',
|
||||
options: () => ({}),
|
||||
overrideServices: () => ({}),
|
||||
saveViewState: true,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
});
|
||||
|
||||
const emits = defineEmits<{
|
||||
(e: 'update:value', value: string | undefined): void
|
||||
(e: 'beforeMount', monaco: MonacoEditor): void
|
||||
(e: 'mount', editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: MonacoEditor): void
|
||||
(e: 'change', value: string | undefined, event: monacoEditor.editor.IModelContentChangedEvent): void
|
||||
(e: 'validate', markers: monacoEditor.editor.IMarker[]): void
|
||||
}>();
|
||||
|
||||
interface MonacoEnvironment {
|
||||
getWorker(_: any, label: string): Worker
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
declare module globalThis {
|
||||
let MonacoEnvironment: MonacoEnvironment;
|
||||
}
|
||||
|
||||
const value = useVModel(props, 'value', emits);
|
||||
|
||||
globalThis.MonacoEnvironment = {
|
||||
getWorker(_: any, label: string) {
|
||||
if (label === 'json') {
|
||||
return new JsonWorker();
|
||||
}
|
||||
if (label === 'css' || label === 'scss' || label === 'less') {
|
||||
return new CssWorker();
|
||||
}
|
||||
if (label === 'html' || label === 'handlebars' || label === 'razor') {
|
||||
return new HtmlWorker();
|
||||
}
|
||||
if (label === 'typescript' || label === 'javascript') {
|
||||
return new TsWorker();
|
||||
}
|
||||
return new EditorWorker();
|
||||
},
|
||||
};
|
||||
|
||||
export interface EditorProps {
|
||||
defaultValue?: string
|
||||
defaultPath?: string
|
||||
defaultLanguage?: string
|
||||
value?: string
|
||||
language?: string
|
||||
path?: string
|
||||
|
||||
/* === */
|
||||
|
||||
theme: 'vs' | string
|
||||
line?: number
|
||||
options?: monacoEditor.editor.IStandaloneEditorConstructionOptions
|
||||
overrideServices?: monacoEditor.editor.IEditorOverrideServices
|
||||
saveViewState?: boolean
|
||||
|
||||
/* === */
|
||||
|
||||
width?: number | string
|
||||
height?: number | string
|
||||
className?: string
|
||||
}
|
||||
|
||||
monacoEditor.editor.defineTheme('it-tools-dark', {
|
||||
base: 'vs-dark',
|
||||
inherit: true,
|
||||
rules: [],
|
||||
colors: {
|
||||
'editor.background': '#00000000',
|
||||
},
|
||||
});
|
||||
|
||||
monacoEditor.editor.defineTheme('it-tools-light', {
|
||||
base: 'vs',
|
||||
inherit: true,
|
||||
rules: [],
|
||||
colors: {
|
||||
'editor.background': '#00000000',
|
||||
},
|
||||
});
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
watch(
|
||||
() => styleStore.isDarkTheme,
|
||||
isDarkTheme => monacoEditor.editor.setTheme(isDarkTheme ? 'it-tools-dark' : 'it-tools-light'),
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
const inheritedAttrs = { ...attrs, ...props };
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
inheritAttrs: false,
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<vue-monaco-editor
|
||||
v-bind="inheritedAttrs"
|
||||
v-model:value="value"
|
||||
@before-mount="(monaco: MonacoEditor) => emits('beforeMount', monaco)"
|
||||
@mount="(editor: monacoEditor.editor.IStandaloneCodeEditor, monaco: MonacoEditor) => emits('mount', editor, monaco)"
|
||||
@change="(value: string | undefined, event: monacoEditor.editor.IModelContentChangedEvent) => emits('change', value, event)"
|
||||
@validate="(markers: monacoEditor.editor.IMarker[]) => emits('validate', markers)"
|
||||
/>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue