dnhyxc-ui-vue 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.json +22 -0
- package/docs/.vitepress/config.mts +55 -0
- package/docs/.vitepress/theme/index.ts +30 -0
- package/docs/.vitepress/theme/style.css +130 -0
- package/docs/api-examples.md +49 -0
- package/docs/auto-imports.d.ts +10 -0
- package/docs/components/icon.md +75 -0
- package/docs/components.d.ts +13 -0
- package/docs/guide/installation.md +1 -0
- package/docs/guide/quick-start.md +1 -0
- package/docs/index.md +24 -0
- package/docs/markdown-examples.md +85 -0
- package/docs/package.json +30 -0
- package/docs/vite.config.ts +20 -0
- package/eslint.config.mjs +90 -0
- package/package.json +78 -0
- package/packages/components/button/index.ts +13 -0
- package/packages/components/button/src/button.ts +20 -0
- package/packages/components/button/src/button.vue +39 -0
- package/packages/components/button/src/index.scss +3 -0
- package/packages/components/icon/index.ts +14 -0
- package/packages/components/icon/src/icon.ts +16 -0
- package/packages/components/icon/src/icon.vue +35 -0
- package/packages/components/icon2/index.ts +14 -0
- package/packages/components/icon2/src/icon2.ts +16 -0
- package/packages/components/icon2/src/icon2.vue +35 -0
- package/packages/components/index.ts +5 -0
- package/packages/components/input/index.ts +13 -0
- package/packages/components/input/src/index.scss +3 -0
- package/packages/components/input/src/input.ts +22 -0
- package/packages/components/input/src/input.vue +50 -0
- package/packages/components/monaco/index.ts +8 -0
- package/packages/components/monaco/src/custom.ts +124 -0
- package/packages/components/monaco/src/index.scss +235 -0
- package/packages/components/monaco/src/monaco.ts +46 -0
- package/packages/components/monaco/src/monaco.vue +472 -0
- package/packages/components/package.json +29 -0
- package/packages/components/tsconfig.json +34 -0
- package/packages/components/tsconfig.tsbuildinfo +1 -0
- package/packages/script/build/build.ts +90 -0
- package/packages/script/build/buildfull.ts +77 -0
- package/packages/script/build/external.ts +21 -0
- package/packages/script/build/index.ts +22 -0
- package/packages/script/utils/delPath.ts +30 -0
- package/packages/script/utils/paths.ts +7 -0
- package/packages/theme/gulpfile.js +41 -0
- package/packages/theme/package.json +16 -0
- package/packages/theme/src/icon.scss +8 -0
- package/packages/theme/src/icon2.scss +8 -0
- package/packages/theme/src/index.scss +2 -0
- package/packages/theme/src/mixins/config.scss +4 -0
- package/packages/theme/src/mixins/mixins.scss +80 -0
- package/packages/utils/bem.ts +60 -0
- package/packages/utils/index.ts +2 -0
- package/packages/utils/package.json +16 -0
- package/packages/utils/vite.config.ts +61 -0
- package/packages/utils/with-install.ts +12 -0
- package/play/.vscode/extensions.json +3 -0
- package/play/README.md +5 -0
- package/play/auto-imports.d.ts +10 -0
- package/play/components.d.ts +14 -0
- package/play/index.html +13 -0
- package/play/package.json +30 -0
- package/play/public/vite.svg +1 -0
- package/play/src/App.vue +32 -0
- package/play/src/assets/vue.svg +1 -0
- package/play/src/components/MyInput.vue +25 -0
- package/play/src/main.ts +12 -0
- package/play/src/vite-env.d.ts +7 -0
- package/play/tsconfig.app.json +14 -0
- package/play/tsconfig.json +7 -0
- package/play/tsconfig.node.json +24 -0
- package/play/vite.config.ts +20 -0
- package/pnpm-workspace.yaml +5 -0
- package/tsconfig.json +35 -0
@@ -0,0 +1,472 @@
|
|
1
|
+
<!--
|
2
|
+
* Icon - 图标组件
|
3
|
+
* @author: dnhyxc
|
4
|
+
* @since: 2025-07-02
|
5
|
+
* index.vue
|
6
|
+
-->
|
7
|
+
<template>
|
8
|
+
<div :class="bem.b()" v-bind="$attrs">
|
9
|
+
<div :class="`${theme !== 'vs' && 'dark-toolbar'} toolbar`">
|
10
|
+
<div class="left">
|
11
|
+
<div v-if="!readonly" class="code-action">
|
12
|
+
<!-- <el-dropdown
|
13
|
+
v-if="languages.length > 1"
|
14
|
+
class="menu-list"
|
15
|
+
max-height="200px"
|
16
|
+
popper-class="custom-dropdown-styles"
|
17
|
+
placement="bottom-start"
|
18
|
+
>
|
19
|
+
<span class="action iconfont icon-yuyan" title="切换语言" />
|
20
|
+
<template #dropdown>
|
21
|
+
<el-dropdown-menu>
|
22
|
+
<el-dropdown-item
|
23
|
+
v-for="item in languages"
|
24
|
+
:key="item"
|
25
|
+
class="dropdown-text"
|
26
|
+
@click="onChangeLanguage(item)"
|
27
|
+
>
|
28
|
+
{{ item }}
|
29
|
+
</el-dropdown-item>
|
30
|
+
</el-dropdown-menu>
|
31
|
+
</template>
|
32
|
+
</el-dropdown> -->
|
33
|
+
<!-- <el-dropdown class="menu-list" popper-class="custom-dropdown-styles">
|
34
|
+
<span class="action iconfont icon-sketchpad-theme" title="切换主题" />
|
35
|
+
<template #dropdown>
|
36
|
+
<el-dropdown-menu>
|
37
|
+
<el-dropdown-item
|
38
|
+
v-for="item in EDIT_THEMES"
|
39
|
+
:key="item.theme"
|
40
|
+
class="dropdown-text"
|
41
|
+
@click="onSelectTheme(item.theme)"
|
42
|
+
>
|
43
|
+
{{ item.name }}
|
44
|
+
</el-dropdown-item>
|
45
|
+
</el-dropdown-menu>
|
46
|
+
</template>
|
47
|
+
</el-dropdown> -->
|
48
|
+
<el-tooltip effect="light" content="快捷键说明" placement="top" popper-class="custom-dropdown-styles">
|
49
|
+
<span class="action iconfont icon-tishi" @click="onShowInfo" />
|
50
|
+
</el-tooltip>
|
51
|
+
<slot name="leftAction" :data="{ content, editor }"></slot>
|
52
|
+
<slot name="changeMode" :data="{ content, editor }"></slot>
|
53
|
+
<el-tooltip
|
54
|
+
v-if="!isCodeEdit"
|
55
|
+
effect="light"
|
56
|
+
content="切换编辑器"
|
57
|
+
placement="top"
|
58
|
+
popper-class="custom-dropdown-styles"
|
59
|
+
>
|
60
|
+
<span class="action iconfont icon-bianjiqi" @click="onChangeEditor" />
|
61
|
+
</el-tooltip>
|
62
|
+
</div>
|
63
|
+
<div v-if="!isCodeEdit" class="create-action">
|
64
|
+
<div v-if="showDot" class="action un-save" @click="onDiffValue">未保存</div>
|
65
|
+
<div v-if="showDot" class="action" @click="onDiffValue">
|
66
|
+
{{ showDiff ? '关闭对比' : '对比变更' }}
|
67
|
+
</div>
|
68
|
+
<!-- <el-button
|
69
|
+
class="action clear"
|
70
|
+
type="warning"
|
71
|
+
link
|
72
|
+
title="清空内容"
|
73
|
+
:disabled="!createStore.createInfo.content?.trim()"
|
74
|
+
@click="onClear"
|
75
|
+
>
|
76
|
+
清
|
77
|
+
</el-button> -->
|
78
|
+
<span class="action" title="草稿列表" @click="onShowDraft">稿</span>
|
79
|
+
<!-- <span v-if="createStore.draftArticleId" class="action" title="预览草稿" @click="onPreviewDraft">览</span> -->
|
80
|
+
<span class="action save-draft" title="保存草稿" @click="onSaveDraft">
|
81
|
+
存
|
82
|
+
<el-icon v-if="saveLoading" class="is-loading">
|
83
|
+
<i class="iconfont icon-a-huayuanCopy loading-icon" />
|
84
|
+
</el-icon>
|
85
|
+
</span>
|
86
|
+
<span class="action" title="发布文章" @click="onPublish">发</span>
|
87
|
+
</div>
|
88
|
+
<div v-if="isCodeEdit" class="create-action prev-action">
|
89
|
+
<slot name="save" :data="{ content, editor, onChangeLanguage }"></slot>
|
90
|
+
</div>
|
91
|
+
</div>
|
92
|
+
<div class="right">
|
93
|
+
<slot v-if="!readonly" name="curLanguage">
|
94
|
+
<div class="language-text">当前语言:{{ language }}</div>
|
95
|
+
</slot>
|
96
|
+
<slot v-else name="resLanguage">
|
97
|
+
<span class="language-text result-text">{{ language }} 运行结果</span>
|
98
|
+
</slot>
|
99
|
+
</div>
|
100
|
+
</div>
|
101
|
+
<div
|
102
|
+
v-show="!showDiff"
|
103
|
+
ref="editorRef"
|
104
|
+
:class="`${theme !== 'vs' && 'dark-monaco-editor-wrap'} monaco-editor-wrap`"
|
105
|
+
/>
|
106
|
+
<!-- <DiffMonacoEditor
|
107
|
+
v-show="showDiff"
|
108
|
+
:value="createStore.createInfo.content || ''"
|
109
|
+
:old-value="prevContent || ''"
|
110
|
+
language="markdown"
|
111
|
+
:height="checkOS() === 'mac' ? 'calc(100vh - 138px)' : 'calc(100vh - 125px)'"
|
112
|
+
/> -->
|
113
|
+
<!-- <ElModel v-model:visible="visible" title="vscode 快捷键说明" :footer="false" :width="'86vw'" :draggable="false">
|
114
|
+
<template #content>
|
115
|
+
<div class="model-content">
|
116
|
+
<el-scrollbar>
|
117
|
+
<div v-for="item in SHORTCUT_KEYS" :key="item.name" class="shortcuts">
|
118
|
+
<span class="key-name">{{ item.name }}</span>
|
119
|
+
<span class="key-desc">{{ item.desc }}</span>
|
120
|
+
</div>
|
121
|
+
</el-scrollbar>
|
122
|
+
</div>
|
123
|
+
</template>
|
124
|
+
</ElModel> -->
|
125
|
+
</div>
|
126
|
+
</template>
|
127
|
+
|
128
|
+
<script setup lang="ts">
|
129
|
+
// import type { CSSProperties } from 'vue';
|
130
|
+
import { ref, onMounted, nextTick, onDeactivated, computed, watchEffect, watch, onUnmounted } from 'vue';
|
131
|
+
import { createNamespace } from '@dnhyxc-ui/utils';
|
132
|
+
import { ElTooltip } from 'element-plus';
|
133
|
+
import { monacoProps } from './monaco';
|
134
|
+
import * as monaco from 'monaco-editor';
|
135
|
+
// import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
|
136
|
+
// @ts-ignore
|
137
|
+
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
138
|
+
// @ts-ignore
|
139
|
+
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
|
140
|
+
// @ts-ignore
|
141
|
+
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
|
142
|
+
// @ts-ignore
|
143
|
+
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
144
|
+
// @ts-ignore
|
145
|
+
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
146
|
+
import './index.scss';
|
147
|
+
// import {
|
148
|
+
// MONACO_EDITOR_LANGUAGES,
|
149
|
+
// CODE_RUN_LANGUAGES,
|
150
|
+
// VS_CODE_SHORTCUT_KEYS,
|
151
|
+
// CODERUN_BG,
|
152
|
+
// EDIT_THEMES
|
153
|
+
// } from '@/constant';
|
154
|
+
// import { checkOS, message } from '@/utils';
|
155
|
+
// import { createStore } from '@/store';
|
156
|
+
// import DiffMonacoEditor from '@/components/MonacoDiffEditor/index.vue';
|
157
|
+
import { registerDocumentFormatInfo } from './custom';
|
158
|
+
|
159
|
+
const bem = createNamespace('monaco');
|
160
|
+
|
161
|
+
const emit = defineEmits(['update:theme']);
|
162
|
+
|
163
|
+
const props = defineProps(monacoProps);
|
164
|
+
|
165
|
+
defineOptions({
|
166
|
+
name: 'NMonaco',
|
167
|
+
inheritAttrs: false // 禁用继承父组件的属性
|
168
|
+
});
|
169
|
+
|
170
|
+
// 编辑器ref
|
171
|
+
const editorRef = ref<HTMLDivElement | null>(null);
|
172
|
+
// 当前语言
|
173
|
+
const language = ref<string>(props.isCodeEdit ? props.language || 'javascript' : 'markdown');
|
174
|
+
// 编辑代码模式时的默认值
|
175
|
+
const content = ref<string | undefined>('');
|
176
|
+
// 是否显示快捷键提示弹窗
|
177
|
+
const visible = ref<boolean>(false);
|
178
|
+
// 控制是否显示对比内容
|
179
|
+
const showDiff = ref<boolean>(false);
|
180
|
+
|
181
|
+
let editor: monaco.editor.IStandaloneCodeEditor | null = null;
|
182
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
183
|
+
let initTimer: ReturnType<typeof setTimeout> | null = null;
|
184
|
+
|
185
|
+
const theme = computed({
|
186
|
+
get() {
|
187
|
+
return props.theme as string;
|
188
|
+
},
|
189
|
+
set(value: string) {
|
190
|
+
emit('update:theme', value);
|
191
|
+
}
|
192
|
+
});
|
193
|
+
|
194
|
+
// const SHORTCUT_KEYS = computed(() => {
|
195
|
+
// if (props.shortcutKeys && props.shortcutKeys.length) {
|
196
|
+
// const keysCopy = [...VS_CODE_SHORTCUT_KEYS];
|
197
|
+
// keysCopy.splice(props.shortcutPos || 0, 0, ...props.shortcutKeys);
|
198
|
+
// return keysCopy;
|
199
|
+
// }
|
200
|
+
// return VS_CODE_SHORTCUT_KEYS;
|
201
|
+
// });
|
202
|
+
|
203
|
+
// const background = computed(() => {
|
204
|
+
// return (CODERUN_BG as Record<string, string>)[theme.value] || props?.editorBgColor || 'transparent';
|
205
|
+
// });
|
206
|
+
|
207
|
+
self.MonacoEnvironment = {
|
208
|
+
getWorker(_: string, label: string) {
|
209
|
+
switch (label) {
|
210
|
+
case 'json':
|
211
|
+
return new jsonWorker();
|
212
|
+
case 'css':
|
213
|
+
case 'scss':
|
214
|
+
case 'less':
|
215
|
+
return new cssWorker();
|
216
|
+
case 'html':
|
217
|
+
case 'handlebars':
|
218
|
+
case 'razor':
|
219
|
+
return new htmlWorker();
|
220
|
+
case 'typescript':
|
221
|
+
case 'javascript':
|
222
|
+
case 'c':
|
223
|
+
case 'python':
|
224
|
+
return new tsWorker();
|
225
|
+
default:
|
226
|
+
return new EditorWorker();
|
227
|
+
}
|
228
|
+
}
|
229
|
+
};
|
230
|
+
|
231
|
+
onMounted(() => {
|
232
|
+
nextTick(() => {
|
233
|
+
const editor = initEditor();
|
234
|
+
props?.getMonacoEditor?.(editor, onChangeLanguage, setTheme);
|
235
|
+
});
|
236
|
+
});
|
237
|
+
|
238
|
+
onUnmounted(() => {
|
239
|
+
timer = null;
|
240
|
+
initTimer = null;
|
241
|
+
});
|
242
|
+
|
243
|
+
watch(
|
244
|
+
() => props.showDot,
|
245
|
+
(newVal) => {
|
246
|
+
if (!newVal) {
|
247
|
+
showDiff.value = false;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
);
|
251
|
+
|
252
|
+
watchEffect(() => {
|
253
|
+
// 设置编辑内容
|
254
|
+
initTimer && clearTimeout(initTimer);
|
255
|
+
initTimer = setTimeout(() => {
|
256
|
+
if (props.code && editor) {
|
257
|
+
editor.getModel()?.setValue(props.code);
|
258
|
+
}
|
259
|
+
if (props.code === '' && editor) {
|
260
|
+
editor.getModel()?.setValue('');
|
261
|
+
}
|
262
|
+
// 切换语言
|
263
|
+
if (props.language && editor) {
|
264
|
+
onChangeLanguage(props.language);
|
265
|
+
}
|
266
|
+
});
|
267
|
+
});
|
268
|
+
|
269
|
+
// const languages = computed(() =>
|
270
|
+
// props?.isCodeEdit ? props?.languages || CODE_RUN_LANGUAGES : MONACO_EDITOR_LANGUAGES
|
271
|
+
// );
|
272
|
+
|
273
|
+
// 组件弃用时,显示mackdown编辑器
|
274
|
+
onDeactivated(() => {
|
275
|
+
props?.onChangeEditor?.();
|
276
|
+
});
|
277
|
+
|
278
|
+
// 初始化编辑器
|
279
|
+
const initEditor = () => {
|
280
|
+
// 设置 JavaScript 的诊断选项
|
281
|
+
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
|
282
|
+
noSemanticValidation: true, // 禁用语义验证
|
283
|
+
noSyntaxValidation: false // 启用语法验证
|
284
|
+
});
|
285
|
+
|
286
|
+
// 设置 JavaScript 的编译器选项
|
287
|
+
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
|
288
|
+
target: monaco.languages.typescript.ScriptTarget.ES2016, // 设置目标 ECMAScript 版本为 ES2016
|
289
|
+
allowNonTsExtensions: true // 允许非 TypeScript 扩展名
|
290
|
+
});
|
291
|
+
|
292
|
+
// 设置 TypeScript 的模型同步
|
293
|
+
monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true); // 启用即时模型同步
|
294
|
+
|
295
|
+
// 设置 TypeScript 的诊断选项
|
296
|
+
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
297
|
+
noSemanticValidation: true, // 禁用语义验证
|
298
|
+
noSyntaxValidation: true // 禁用语法验证
|
299
|
+
});
|
300
|
+
|
301
|
+
if (!editor) {
|
302
|
+
// 创建 Monaco 编辑器实例
|
303
|
+
editor = monaco?.editor?.create?.(editorRef?.value! as any, {
|
304
|
+
// 根据编辑模式和只读状态设置初始值
|
305
|
+
value: props.code, // 编辑器初始显示文字
|
306
|
+
language: 'javascript', // 语言
|
307
|
+
theme: props.theme || 'vs-dark', // 官方自带三种主题vs, hc-black, or vs-dark
|
308
|
+
fontFamily: 'Fira Code', // 字体
|
309
|
+
fontLigatures: true, // 启用字体连字
|
310
|
+
automaticLayout: true, // 自适应布局
|
311
|
+
// 代码折叠策略,使用缩进方式
|
312
|
+
foldingStrategy: 'indentation',
|
313
|
+
// 根据只读状态设置行高亮显示
|
314
|
+
renderLineHighlight: props.readonly ? 'none' : 'all', // 行亮 all line none
|
315
|
+
selectOnLineNumbers: true, // 显示行号
|
316
|
+
// 根据只读状态决定是否显示行号
|
317
|
+
lineNumbers: props.readonly ? 'off' : 'on', // 是否显示行号
|
318
|
+
minimap: {
|
319
|
+
enabled: false // 是否启用预览图
|
320
|
+
},
|
321
|
+
scrollbar: {
|
322
|
+
// 滚动条设置
|
323
|
+
verticalScrollbarSize: 6, // 垂直滚动条宽度
|
324
|
+
horizontalScrollbarSize: 6, // 水平滚动条高度
|
325
|
+
arrowSize: 10, // 箭头大小
|
326
|
+
alwaysConsumeMouseWheel: false // 是否始终消费鼠标滚轮事件
|
327
|
+
},
|
328
|
+
readOnly: props.readonly, // 只读
|
329
|
+
fontSize: 16, // 字体大小
|
330
|
+
scrollBeyondLastLine: true, // 取消代码后面一大段空白
|
331
|
+
overviewRulerBorder: false, // 不要滚动条的边框
|
332
|
+
tabSize: 2, // 缩进大小
|
333
|
+
colorDecorators: true, // 呈现内联色彩装饰器和颜色选择器
|
334
|
+
wordWrap: 'on', // 超出一屏自动换行
|
335
|
+
links: false, // 禁止链接检测,避免鼠标点击开启子窗口
|
336
|
+
folding: true, // 是否启用代码折叠
|
337
|
+
foldingHighlight: true // 折叠时是否高亮
|
338
|
+
});
|
339
|
+
}
|
340
|
+
|
341
|
+
// // 注册自定义主题
|
342
|
+
// monaco?.editor?.defineTheme('beauty', beauty(props?.editorBgColor) as any);
|
343
|
+
|
344
|
+
// // 注册自定义格式化规则
|
345
|
+
registerDocumentFormatInfo(monaco);
|
346
|
+
|
347
|
+
// 监听值的变化
|
348
|
+
editor.onDidChangeModelContent(() => {
|
349
|
+
if (props.isCodeEdit) {
|
350
|
+
content.value = editor?.getValue() || '';
|
351
|
+
} else {
|
352
|
+
console.log('监听值变化', editor?.getValue());
|
353
|
+
// createStore.createInfo.content = editor?.getValue();
|
354
|
+
}
|
355
|
+
props?.getCodeContent?.(editor?.getValue() as string);
|
356
|
+
});
|
357
|
+
|
358
|
+
// 监听鼠标点击事件,在默认浏览器中打开链接
|
359
|
+
editor.onMouseDown((e) => {
|
360
|
+
const isCommandClick = e.event.metaKey || e.event.ctrlKey;
|
361
|
+
if (e.target.type === monaco.editor.MouseTargetType.CONTENT_TEXT && isCommandClick) {
|
362
|
+
const model = editor?.getModel();
|
363
|
+
const position = e.target.position;
|
364
|
+
// 使用Monaco内置的链接检测
|
365
|
+
const lineContent = model?.getLineContent(position.lineNumber);
|
366
|
+
// 使用正则表达式检测URL
|
367
|
+
const urlRegex = /https?:\/\/[^\s]+/g;
|
368
|
+
const urls = lineContent?.match(urlRegex);
|
369
|
+
if (urls) {
|
370
|
+
// 检查点击位置是否在URL上
|
371
|
+
const startIndex = lineContent?.indexOf(urls[0]) as number;
|
372
|
+
const endIndex = startIndex + urls[0].length;
|
373
|
+
// if (position.column - 1 >= startIndex && position.column - 1 <= endIndex) {
|
374
|
+
// }
|
375
|
+
}
|
376
|
+
}
|
377
|
+
});
|
378
|
+
|
379
|
+
// 监听编辑器回车事件
|
380
|
+
editor?.onKeyDown((e) => {
|
381
|
+
if (e.keyCode === monaco.KeyCode.Enter) {
|
382
|
+
const position = editor?.getPosition();
|
383
|
+
const maxColumn = editor?.getModel()?.getLineMaxColumn(position!.lineNumber);
|
384
|
+
const target = e.target as HTMLInputElement;
|
385
|
+
if (position!.column === maxColumn && e.keyCode === monaco.KeyCode.Enter) {
|
386
|
+
timer && clearTimeout(timer);
|
387
|
+
timer = setTimeout(() => {
|
388
|
+
props?.onEnter?.(editor?.getValue() || target.value);
|
389
|
+
}, 500);
|
390
|
+
}
|
391
|
+
}
|
392
|
+
});
|
393
|
+
|
394
|
+
return editor;
|
395
|
+
};
|
396
|
+
|
397
|
+
// 设置主题颜色
|
398
|
+
const setTheme = (type: string) => {
|
399
|
+
emit('update:theme', type);
|
400
|
+
// 定义一个主题
|
401
|
+
monaco.editor.setTheme(type);
|
402
|
+
};
|
403
|
+
|
404
|
+
// 切换语言
|
405
|
+
const onChangeLanguage = (value: string) => {
|
406
|
+
language.value = value;
|
407
|
+
monaco.editor.setModelLanguage(editor?.getModel()!, value);
|
408
|
+
props?.getLanguage?.(value);
|
409
|
+
};
|
410
|
+
|
411
|
+
// 切换主题
|
412
|
+
const onSelectTheme = (type: string) => {
|
413
|
+
setTheme(type);
|
414
|
+
};
|
415
|
+
|
416
|
+
// 切换编辑器类型
|
417
|
+
const onChangeEditor = () => {
|
418
|
+
editor?.getModel()?.setValue('');
|
419
|
+
// editor?.getModel()?.setValue(createStore.createInfo.content || '');
|
420
|
+
props?.onChangeEditor?.();
|
421
|
+
};
|
422
|
+
|
423
|
+
// 清空编辑
|
424
|
+
const onClear = () => {
|
425
|
+
props.onClear?.();
|
426
|
+
editor?.getModel()?.setValue('');
|
427
|
+
};
|
428
|
+
|
429
|
+
// 保存
|
430
|
+
const onPublish = () => {
|
431
|
+
if (!props.code?.trim()) {
|
432
|
+
// if (!createStore?.createInfo?.content?.trim()) {
|
433
|
+
// message({
|
434
|
+
// title: '嘿!一个字都没写休想发布',
|
435
|
+
// message: '请先编写文章内容后再尝试发布!',
|
436
|
+
// type: 'warning'
|
437
|
+
// });
|
438
|
+
return;
|
439
|
+
}
|
440
|
+
props.onPublish?.();
|
441
|
+
};
|
442
|
+
|
443
|
+
// 保存草稿
|
444
|
+
const onSaveDraft = () => {
|
445
|
+
if (!props.code?.trim()) {
|
446
|
+
// if (!createStore?.createInfo?.content?.trim()) {
|
447
|
+
// message({
|
448
|
+
// title: '嘿!一个字都没写休想发布',
|
449
|
+
// message: '请先编写文章内容后再尝试发布!',
|
450
|
+
// type: 'warning'
|
451
|
+
// });
|
452
|
+
return;
|
453
|
+
}
|
454
|
+
props.onSaveDraft?.(editor as any);
|
455
|
+
};
|
456
|
+
|
457
|
+
// 预览
|
458
|
+
// const onPreviewDraft = () => {
|
459
|
+
// if (!createStore?.draftArticleId) return;
|
460
|
+
// props?.toPreview?.(createStore?.draftArticleId);
|
461
|
+
// };
|
462
|
+
|
463
|
+
// 显示快捷键提示弹窗
|
464
|
+
const onShowInfo = () => {
|
465
|
+
visible.value = true;
|
466
|
+
};
|
467
|
+
|
468
|
+
// 显示变更内容
|
469
|
+
const onDiffValue = () => {
|
470
|
+
showDiff.value = !showDiff.value;
|
471
|
+
};
|
472
|
+
</script>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"name": "dnhyxc-ui-plus",
|
3
|
+
"version": "0.0.1-beta.0",
|
4
|
+
"scripts": {
|
5
|
+
"build": "rimraf lib es dist && vite build --config ../script/build/build.ts",
|
6
|
+
"build:full": "vite build --config ../script/build/buildfull.ts"
|
7
|
+
},
|
8
|
+
"main": "./lib/index.js",
|
9
|
+
"module": "./es/index.js",
|
10
|
+
"types": "./es/index.d.ts",
|
11
|
+
"keywords": [],
|
12
|
+
"files": [
|
13
|
+
"es",
|
14
|
+
"lib",
|
15
|
+
"package.json"
|
16
|
+
],
|
17
|
+
"author": "",
|
18
|
+
"license": "ISC",
|
19
|
+
"description": "",
|
20
|
+
"dependencies": {
|
21
|
+
"@dnhyxc-ui/utils": "workspace:^",
|
22
|
+
"monaco-editor": "^0.52.2",
|
23
|
+
"prettier": "^2.8.3"
|
24
|
+
},
|
25
|
+
"peerDependencies": {
|
26
|
+
"monaco-editor": "^0.52.2",
|
27
|
+
"prettier": "^2.8.3"
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"baseUrl": ".",
|
4
|
+
"declaration": false, // 不生成声明文件
|
5
|
+
"target": "ES2021",
|
6
|
+
"lib": ["DOM", "ES2021"],
|
7
|
+
"module": "ESNext",
|
8
|
+
"jsx": "preserve", // 不转 jsx
|
9
|
+
"allowSyntheticDefaultImports": true, // 允许使用默认导入
|
10
|
+
"experimentalDecorators": true, // 启用装饰器
|
11
|
+
"noEmit": true,
|
12
|
+
"strict": true,
|
13
|
+
"skipLibCheck": true, // 跳过类库检查
|
14
|
+
"isolatedModules": true, // 每个文件都是模块
|
15
|
+
"resolveJsonModule": true, // 解析json文件
|
16
|
+
"removeComments": true, // 移除注释
|
17
|
+
// moduleResolution 用于指定 TypeScript 如何解析模块
|
18
|
+
// "bundler" 表示使用与打包工具(如 Webpack、Vite 等)兼容的模块解析策略
|
19
|
+
// 它支持 package.json 的 "exports" 字段,并遵循现代打包工具的模块解析规则
|
20
|
+
"moduleResolution": "bundler",
|
21
|
+
"esModuleInterop": true, // 支持 es6 commonjs 模块
|
22
|
+
"useDefineForClassFields": true, // 使用defineClassFields
|
23
|
+
"allowImportingTsExtensions": true, // 允许导入ts文件
|
24
|
+
"noImplicitAny": true, // 不允许隐式any
|
25
|
+
"noLib": false, // 不处理类库
|
26
|
+
"forceConsistentCasingInFileNames": true, // 强制区分文件名大小写
|
27
|
+
"typeRoots": ["./node_modules/@types", "../typings"] // 添加这行
|
28
|
+
// "paths": {
|
29
|
+
// "@/*": ["../components/*"]
|
30
|
+
// }
|
31
|
+
},
|
32
|
+
"include": ["../components/**/*", "../script/build/build.ts"],
|
33
|
+
"exclude": ["node_modules", "dist/**"]
|
34
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"root":["./components.d.ts","./index.ts","./vite.config.ts","./button/index.ts","./button/src/button.ts","./button/src/button.vue","./icon/index.ts","./icon/src/icon.ts","./icon/src/icon.vue","./icon2/index.ts","./icon2/src/icon2.ts","./icon2/src/icon2.vue","./input/index.ts","./input/src/input.ts","./input/src/input.vue"],"version":"5.8.2"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { defineConfig } from 'vite';
|
2
|
+
// import { rmSync } from 'fs';
|
3
|
+
import vue from '@vitejs/plugin-vue';
|
4
|
+
// import AutoImport from 'unplugin-auto-import/vite';
|
5
|
+
// import Components from 'unplugin-vue-components/vite';
|
6
|
+
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
7
|
+
// import path from 'path';
|
8
|
+
import dts from 'vite-plugin-dts';
|
9
|
+
import { external } from './external';
|
10
|
+
|
11
|
+
// 打包前先删除 dist 目录
|
12
|
+
// rmSync('dist', { recursive: true, force: true });
|
13
|
+
|
14
|
+
// 组件库打包配置
|
15
|
+
export default defineConfig({
|
16
|
+
build: {
|
17
|
+
// 打包输出目录
|
18
|
+
outDir: 'es',
|
19
|
+
// 构建库模式
|
20
|
+
lib: {
|
21
|
+
// 组件库入口文件
|
22
|
+
entry: './index.ts',
|
23
|
+
// name: 'dnhyxc-ui',
|
24
|
+
// // 根据不同格式输出到不同目录
|
25
|
+
// fileName: (format, entryName) => {
|
26
|
+
// if (format === 'es') {
|
27
|
+
// return `${entryName}.mjs`;
|
28
|
+
// }
|
29
|
+
// return `${entryName}.js`;
|
30
|
+
// },
|
31
|
+
// 输出格式
|
32
|
+
formats: ['es', 'umd']
|
33
|
+
},
|
34
|
+
rollupOptions: {
|
35
|
+
// 外部化处理依赖
|
36
|
+
external,
|
37
|
+
input: ['./index.ts'],
|
38
|
+
output: [
|
39
|
+
{
|
40
|
+
// 输出文件名格式
|
41
|
+
entryFileNames: '[name].js',
|
42
|
+
// 输出格式为 ES Module
|
43
|
+
format: 'es',
|
44
|
+
// ES Module 格式文件的输出目录
|
45
|
+
dir: './es',
|
46
|
+
// 保持目录结构
|
47
|
+
preserveModules: true,
|
48
|
+
// 指定输出文件的根目录,将所有模块放在 components 目录下,这样可以保持更清晰的目录结构
|
49
|
+
preserveModulesRoot: 'src',
|
50
|
+
assetFileNames: 'index.[ext]'
|
51
|
+
},
|
52
|
+
{
|
53
|
+
entryFileNames: '[name].js',
|
54
|
+
format: 'cjs',
|
55
|
+
name: 'dnhyxc-ui-plus',
|
56
|
+
// 输出文件夹
|
57
|
+
dir: './lib',
|
58
|
+
// 保持目录结构
|
59
|
+
preserveModules: true,
|
60
|
+
// 输出目录
|
61
|
+
preserveModulesRoot: 'src',
|
62
|
+
assetFileNames: 'index.[ext]'
|
63
|
+
// UMD格式下需要指定全局变量名, 这样在浏览器中通过 <script> 标签引入时,就会从 window.Vue 获取 Vue 依赖
|
64
|
+
// globals: {
|
65
|
+
// vue: 'Vue'
|
66
|
+
// }
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
},
|
71
|
+
plugins: [
|
72
|
+
vue(),
|
73
|
+
// AutoImport({
|
74
|
+
// resolvers: [ElementPlusResolver()]
|
75
|
+
// }),
|
76
|
+
// Components({
|
77
|
+
// resolvers: [ElementPlusResolver()]
|
78
|
+
// }),
|
79
|
+
// 生成组件的类型声明文件
|
80
|
+
dts({
|
81
|
+
include: ['./**/*'],
|
82
|
+
outDir: ['./es', './lib']
|
83
|
+
})
|
84
|
+
]
|
85
|
+
// resolve: {
|
86
|
+
// alias: {
|
87
|
+
// '@': path.resolve(__dirname, '.')
|
88
|
+
// }
|
89
|
+
// }
|
90
|
+
});
|