mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-30 00:50:47 +03:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86b1fe2971 | ||
|
|
e3e8e9d4e4 |
No files matched your search
Vendored
+1
-1
@@ -50,7 +50,6 @@ 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']
|
||||
@@ -133,6 +132,7 @@ declare module '@vue/runtime-core' {
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
|
||||
+12
-5
@@ -36,14 +36,21 @@
|
||||
"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",
|
||||
"@regexper/render": "^1.0.0",
|
||||
"@sindresorhus/slugify": "^2.2.1",
|
||||
"@tiptap/pm": "2.1.6",
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@tiptap/extension-color": "^2.7.4",
|
||||
"@tiptap/extension-gapcursor": "^2.7.4",
|
||||
"@tiptap/extension-highlight": "^2.7.4",
|
||||
"@tiptap/extension-table": "^2.7.4",
|
||||
"@tiptap/extension-table-cell": "^2.7.4",
|
||||
"@tiptap/extension-table-header": "^2.7.4",
|
||||
"@tiptap/extension-table-row": "^2.7.4",
|
||||
"@tiptap/extension-text-style": "^2.7.4",
|
||||
"@tiptap/pm": "2.7.4",
|
||||
"@tiptap/starter-kit": "2.7.4",
|
||||
"@tiptap/vue-3": "2.7.4",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -54,7 +61,7 @@
|
||||
"bcryptjs": "^2.4.3",
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
"composerize": "^1.6.12",
|
||||
"composerize-ts": "^0.6.2",
|
||||
"country-code-lookup": "^0.1.0",
|
||||
"cron-validator": "^1.3.1",
|
||||
"cronstrue": "^2.26.0",
|
||||
|
||||
Generated
+434
-469
File diff suppressed because it is too large.
Load diff
@@ -2,9 +2,6 @@ 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 shadow from 'vue-shadow-dom';
|
||||
import { plausible } from './plugins/plausible.plugin';
|
||||
@@ -17,14 +14,10 @@ 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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
declare module 'composerize' {
|
||||
const composerize: (commands: string, existingDockerComposeFile?: string, conversion?: string, indent?: number) => string;
|
||||
const composerize: (arg: string) => string;
|
||||
export default composerize;
|
||||
}
|
||||
+44
-66
@@ -1,94 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import composerize from 'composerize';
|
||||
import { MessageType, composerize } from 'composerize-ts';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
import { textToBase64 } from '@/utils/base64';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const dockerRuns = ref(
|
||||
const dockerRun = ref(
|
||||
'docker run -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --restart always --log-opt max-size=1g nginx',
|
||||
);
|
||||
const indentSize = useStorage('docker-run-to-compose:indent-size', 4);
|
||||
|
||||
const existingDockerComposeFile = ref(
|
||||
'',
|
||||
const conversionResult = computed(() =>
|
||||
withDefaultOnError(() => composerize(dockerRun.value.trim()), { yaml: '', messages: [] }),
|
||||
);
|
||||
const format = useStorage('docker-run-to-compose:format', 'latest');
|
||||
const formatOptions = [
|
||||
{ value: 'v2x', label: 'V2 - 2.x' },
|
||||
{ value: 'v3x', label: 'V2 - 3.x' },
|
||||
{ value: 'latest', label: 'CommonSpec' },
|
||||
];
|
||||
|
||||
const conversionResult = computed(() => {
|
||||
try {
|
||||
return { yaml: composerize(dockerRuns.value.trim(), existingDockerComposeFile.value, format.value, indentSize.value), errors: [] };
|
||||
}
|
||||
catch (e: any) {
|
||||
return { yaml: '#see error messages', errors: e.toString().split('\n') };
|
||||
}
|
||||
});
|
||||
|
||||
const dockerCompose = computed(() => conversionResult.value.yaml);
|
||||
const errors = computed(() => conversionResult.value.errors);
|
||||
|
||||
const notImplemented = computed(() =>
|
||||
conversionResult.value.messages.filter(msg => msg.type === MessageType.notImplemented).map(msg => msg.value),
|
||||
);
|
||||
const notComposable = computed(() =>
|
||||
conversionResult.value.messages.filter(msg => msg.type === MessageType.notTranslatable).map(msg => msg.value),
|
||||
);
|
||||
const errors = computed(() =>
|
||||
conversionResult.value.messages
|
||||
.filter(msg => msg.type === MessageType.errorDuringConversion)
|
||||
.map(msg => msg.value),
|
||||
);
|
||||
const dockerComposeBase64 = computed(() => `data:application/yaml;base64,${textToBase64(dockerCompose.value)}`);
|
||||
const { download } = useDownloadFileFromBase64({ source: dockerComposeBase64, filename: 'docker-compose.yml' });
|
||||
|
||||
const MONACO_EDITOR_OPTIONS = {
|
||||
automaticLayout: true,
|
||||
formatOnType: true,
|
||||
formatOnPaste: true,
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text
|
||||
v-model:value="dockerRuns"
|
||||
label="Your docker run command(s):"
|
||||
v-model:value="dockerRun"
|
||||
label="Your docker run command:"
|
||||
style="font-family: monospace"
|
||||
multiline
|
||||
raw-text
|
||||
monospace
|
||||
placeholder="Your docker run command(s) to convert..."
|
||||
rows="4"
|
||||
placeholder="Your docker run command to convert..."
|
||||
rows="3"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-label label="Eventually, paste your existing Docker Compose:">
|
||||
<div relative w-full>
|
||||
<c-monaco-editor
|
||||
v-model:value="existingDockerComposeFile"
|
||||
theme="vs-dark"
|
||||
language="yaml"
|
||||
height="100px"
|
||||
:options="MONACO_EDITOR_OPTIONS"
|
||||
/>
|
||||
</div>
|
||||
</c-label>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-grid cols="4" x-gap="12" w-full>
|
||||
<n-gi span="2">
|
||||
<c-select
|
||||
v-model:value="format"
|
||||
label-position="top"
|
||||
label="Docker Compose format:"
|
||||
:options="formatOptions"
|
||||
placeholder="Select Docker Compose format"
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi span="2">
|
||||
<n-form-item label="Indent size:" label-placement="top" label-width="100" :show-feedback="false">
|
||||
<n-input-number v-model:value="indentSize" min="0" max="10" w-100px />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<TextareaCopyable :value="dockerCompose" language="yaml" />
|
||||
|
||||
<div mt-5 flex justify-center>
|
||||
@@ -97,6 +51,30 @@ const MONACO_EDITOR_OPTIONS = {
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<div v-if="notComposable.length > 0">
|
||||
<n-alert title="This options are not translatable to docker-compose" type="info" mt-5>
|
||||
<ul>
|
||||
<li v-for="(message, index) of notComposable" :key="index">
|
||||
{{ message }}
|
||||
</li>
|
||||
</ul>
|
||||
</n-alert>
|
||||
</div>
|
||||
|
||||
<div v-if="notImplemented.length > 0">
|
||||
<n-alert
|
||||
title="This options are not yet implemented and therefore haven't been translated to docker-compose"
|
||||
type="warning"
|
||||
mt-5
|
||||
>
|
||||
<ul>
|
||||
<li v-for="(message, index) of notImplemented" :key="index">
|
||||
{{ message }}
|
||||
</li>
|
||||
</ul>
|
||||
</n-alert>
|
||||
</div>
|
||||
|
||||
<div v-if="errors.length > 0">
|
||||
<n-alert title="The following errors occured" type="error" mt-5>
|
||||
<ul>
|
||||
|
||||
@@ -3,6 +3,13 @@ import { tryOnBeforeUnmount, useVModel } from '@vueuse/core';
|
||||
import { Editor, EditorContent } from '@tiptap/vue-3';
|
||||
import StarterKit from '@tiptap/starter-kit';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import { Color } from '@tiptap/extension-color';
|
||||
import TextStyle from '@tiptap/extension-text-style';
|
||||
import Highlight from '@tiptap/extension-highlight';
|
||||
import Table from '@tiptap/extension-table';
|
||||
import TableCell from '@tiptap/extension-table-cell';
|
||||
import TableHeader from '@tiptap/extension-table-header';
|
||||
import TableRow from '@tiptap/extension-table-row';
|
||||
import MenuBar from './menu-bar.vue';
|
||||
|
||||
const props = defineProps<{ html: string }>();
|
||||
@@ -12,7 +19,18 @@ const html = useVModel(props, 'html', emit);
|
||||
|
||||
const editor = new Editor({
|
||||
content: html.value,
|
||||
extensions: [StarterKit],
|
||||
extensions: [
|
||||
StarterKit,
|
||||
TextStyle,
|
||||
Color,
|
||||
Highlight.configure({ multicolor: true }),
|
||||
Table.configure({
|
||||
resizable: true,
|
||||
}),
|
||||
TableRow,
|
||||
TableHeader,
|
||||
TableCell,
|
||||
],
|
||||
});
|
||||
|
||||
editor.on('update', ({ editor }) => emit('update:html', editor.getHTML()));
|
||||
@@ -63,6 +81,63 @@ tryOnBeforeUnmount(() => {
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
/* Table-specific styling */
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
table-layout: fixed;
|
||||
width: 100%;
|
||||
|
||||
td,
|
||||
th {
|
||||
border: 1px solid v-bind('themeVars.borderColor');
|
||||
box-sizing: border-box;
|
||||
min-width: 1em;
|
||||
padding: 6px 8px;
|
||||
position: relative;
|
||||
vertical-align: top;
|
||||
|
||||
> * {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: v-bind('themeVars.tableHeaderColor');
|
||||
font-weight: bold;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.selectedCell:after {
|
||||
content: "";
|
||||
left: 0; right: 0; top: 0; bottom: 0;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.column-resize-handle {
|
||||
background-color: v-bind('themeVars.actionColor');
|
||||
bottom: -2px;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
right: -2px;
|
||||
top: 0;
|
||||
width: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.tableWrapper {
|
||||
margin: 1.5rem 0;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
&.resize-cursor {
|
||||
cursor: ew-resize;
|
||||
cursor: col-resize;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: v-bind('themeVars.codeColor');
|
||||
padding: 2px 4px;
|
||||
@@ -84,10 +159,6 @@ tryOnBeforeUnmount(() => {
|
||||
}
|
||||
}
|
||||
|
||||
mark {
|
||||
background-color: #faf594;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import type { Component } from 'vue';
|
||||
|
||||
const props = defineProps<{ icon: Component; title: string; action: () => void; isActive?: () => boolean }>();
|
||||
const { icon, title, action, isActive } = toRefs(props);
|
||||
const props = defineProps<{ icon: Component; title: string; action: () => void; isActive?: () => boolean; enabled?: () => boolean }>();
|
||||
const { icon, title, action, isActive, enabled } = toRefs(props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-tooltip :tooltip="title">
|
||||
<c-button circle variant="text" :type="isActive?.() ? 'primary' : 'default'" @click="action">
|
||||
<c-button circle variant="text" :disabled="enabled && !enabled()" :type="isActive?.() ? 'primary' : 'default'" @click="action">
|
||||
<n-icon :component="icon" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
@@ -8,15 +8,25 @@ import {
|
||||
ClearFormatting,
|
||||
Code,
|
||||
CodePlus,
|
||||
ColorPicker,
|
||||
ColumnInsertLeft,
|
||||
ColumnInsertRight,
|
||||
Cross,
|
||||
H1,
|
||||
H2,
|
||||
H3,
|
||||
H4,
|
||||
Heading,
|
||||
Italic,
|
||||
LayersIntersect2,
|
||||
LayersUnion,
|
||||
LayoutDistributeHorizontal,
|
||||
LayoutDistributeVertical,
|
||||
List,
|
||||
ListNumbers,
|
||||
Strikethrough,
|
||||
TextWrap,
|
||||
RowInsertBottom,
|
||||
RowInsertTop,
|
||||
SeparatorVertical, Strikethrough, Table, TableOff, TextWrap, Tool,
|
||||
} from '@vicons/tabler';
|
||||
import type { Component } from 'vue';
|
||||
import MenuBarItem from './menu-bar-item.vue';
|
||||
@@ -29,9 +39,18 @@ type MenuItem =
|
||||
icon: Component
|
||||
title: string
|
||||
action: () => void
|
||||
value?: () => string
|
||||
isActive?: () => boolean
|
||||
enabled?: () => boolean
|
||||
type: 'button'
|
||||
}
|
||||
| {
|
||||
icon: Component
|
||||
title: string
|
||||
action: (color: string) => void
|
||||
value: () => string
|
||||
type: 'color'
|
||||
}
|
||||
| { type: 'divider' };
|
||||
|
||||
const items: MenuItem[] = [
|
||||
@@ -141,7 +160,42 @@ const items: MenuItem[] = [
|
||||
title: 'Clear format',
|
||||
action: () => editor.value.chain().focus().clearNodes().unsetAllMarks().run(),
|
||||
},
|
||||
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'color',
|
||||
title: 'Forecolor',
|
||||
icon: ColorPicker,
|
||||
action: color => editor.value.chain().focus().setColor(color).run(),
|
||||
value: () => editor.value.getAttributes('textStyle').color,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: ClearFormatting,
|
||||
title: 'Clear Forecolor',
|
||||
action: () => editor.value.chain().focus().unsetColor().run(),
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'color',
|
||||
title: 'Highlight color',
|
||||
icon: ColorPicker,
|
||||
action: color => editor.value.chain().focus().setHighlight({ color }).run(),
|
||||
value: () => '#FAF594',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: ClearFormatting,
|
||||
title: 'Clear Highlight',
|
||||
action: () => editor.value.chain().focus().unsetHighlight().run(),
|
||||
isActive: () => editor.value.isActive('highlight'),
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
icon: ArrowBack,
|
||||
@@ -154,14 +208,152 @@ const items: MenuItem[] = [
|
||||
title: 'Redo',
|
||||
action: () => editor.value.chain().focus().redo().run(),
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
|
||||
enabled: () => editor.value.can().insertTable(),
|
||||
title: 'Insert table',
|
||||
icon: Table,
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().addColumnBefore().run(),
|
||||
enabled: () => editor.value.can().addColumnBefore(),
|
||||
title: 'Add column before',
|
||||
icon: ColumnInsertLeft,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().addColumnAfter().run(),
|
||||
enabled: () => editor.value.can().addColumnAfter(),
|
||||
title: 'Add column after',
|
||||
icon: ColumnInsertRight,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().deleteColumn().run(),
|
||||
enabled: () => editor.value.can().deleteColumn(),
|
||||
title: 'Delete column',
|
||||
icon: Cross,
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().addRowBefore().run(),
|
||||
enabled: () => editor.value.can().addRowBefore(),
|
||||
title: 'Add row before',
|
||||
icon: RowInsertTop,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().addRowAfter().run(),
|
||||
enabled: () => editor.value.can().addRowAfter(),
|
||||
title: 'Add row after',
|
||||
icon: RowInsertBottom,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().deleteRow().run(),
|
||||
enabled: () => editor.value.can().deleteRow(),
|
||||
title: 'Delete row',
|
||||
icon: Cross,
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().deleteTable().run(),
|
||||
enabled: () => editor.value.can().deleteTable(),
|
||||
title: 'Delete table',
|
||||
icon: TableOff,
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().mergeCells().run(),
|
||||
enabled: () => editor.value.can().mergeCells(),
|
||||
title: 'Merge cells',
|
||||
icon: LayersUnion,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().splitCell().run(),
|
||||
enabled: () => editor.value.can().splitCell(),
|
||||
title: 'Split cell',
|
||||
icon: SeparatorVertical,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().mergeOrSplit().run(),
|
||||
enabled: () => editor.value.can().mergeOrSplit(),
|
||||
title: 'Merge or split',
|
||||
icon: LayersIntersect2,
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().toggleHeaderColumn().run(),
|
||||
enabled: () => editor.value.can().toggleHeaderColumn(),
|
||||
title: 'Toggle header column',
|
||||
icon: LayoutDistributeVertical,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().toggleHeaderRow().run(),
|
||||
enabled: () => editor.value.can().toggleHeaderRow(),
|
||||
title: 'Toggle header row',
|
||||
icon: LayoutDistributeHorizontal,
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().toggleHeaderCell().run(),
|
||||
enabled: () => editor.value.can().toggleHeaderCell(),
|
||||
title: 'Toggle header cell',
|
||||
icon: Heading,
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
type: 'button',
|
||||
action: () => editor.value.chain().focus().fixTables().run(),
|
||||
enabled: () => editor.value.can().fixTables(),
|
||||
title: 'Fix tables',
|
||||
icon: Tool,
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div flex items-center>
|
||||
<div flex flex-wrap items-center>
|
||||
<template v-for="(item, index) in items">
|
||||
<n-divider v-if="item.type === 'divider'" :key="`divider${index}`" vertical />
|
||||
<MenuBarItem v-else-if="item.type === 'button'" :key="index" v-bind="item" />
|
||||
<c-tooltip
|
||||
v-if="item.type === 'color'" :key="`color${index}`"
|
||||
:tooltip="item.title"
|
||||
>
|
||||
<n-color-picker
|
||||
style="width: 120px"
|
||||
:show-alpha="false"
|
||||
:actions="['confirm']"
|
||||
:value="item.value()"
|
||||
@confirm="item.action"
|
||||
/>
|
||||
</c-tooltip>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,124 +0,0 @@
|
||||
<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>
|
||||
Reference in new issue
Block a user