Skip to content

Commit d546908

Browse files
committed
feat(ui): monaco editor
1 parent e670bc8 commit d546908

12 files changed

Lines changed: 511 additions & 534 deletions

File tree

cmdb-ui/config/plugin.config.js

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,90 @@
1+
const webpack = require('webpack')
12
const ThemeColorReplacer = require('webpack-theme-color-replacer')
23
const generate = require('@ant-design/colors/lib/generate').default
4+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
35

4-
const getAntdSerials = (color) => {
6+
const webpackPlugins = [
7+
// Ignore all locale files of moment.js
8+
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
9+
new MonacoWebpackPlugin({
10+
languages: ['python', 'shell', 'powershell', 'json', 'bat']
11+
})
12+
]
13+
14+
function isMonacoAsset(assetName, asset) {
15+
if (!/\.js$/i.test(assetName)) {
16+
return false
17+
}
18+
19+
if (/(^|[\\/])(editor|json|ts)\.worker\.js$/i.test(assetName)) {
20+
return true
21+
}
22+
23+
try {
24+
const source = asset?.source?.()?.toString?.() || ''
25+
return source.includes('MonacoEnvironment') || source.includes('editorSimpleWorker')
26+
} catch (error) {
27+
return false
28+
}
29+
}
30+
31+
function getAntdSerials(color) {
532
// Lighten (similar to less's tint)
633
const lightens = new Array(9).fill().map((t, i) => {
734
return ThemeColorReplacer.varyColor.lighten(color, i / 10)
835
})
936
const colorPalettes = generate(color)
10-
const rgb = ThemeColorReplacer.varyColor.toNum3(color.replace('#', '')).join(',')
11-
return lightens.concat(colorPalettes).concat(rgb)
37+
return lightens.concat(colorPalettes)
1238
}
1339

14-
const themePluginOption = {
15-
fileName: 'css/theme-colors-[contenthash:8].css',
16-
matchColors: getAntdSerials('#2f54eb'), // primary color series
17-
// change style selectors to solve style override issues
18-
changeSelector (selector) {
19-
switch (selector) {
20-
case '.ant-calendar-today .ant-calendar-date':
21-
return ':not(.ant-calendar-selected-date):not(.ant-calendar-selected-day)' + selector
22-
case '.ant-btn:focus,.ant-btn:hover':
23-
return '.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger)'
24-
case '.ant-btn.active,.ant-btn:active':
25-
return '.ant-btn.active:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:active:not(.ant-btn-primary):not(.ant-btn-danger)'
26-
case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
27-
case '.ant-steps-item-process .ant-steps-item-icon>.ant-steps-icon':
28-
return ':not(.ant-steps-item-process)' + selector
29-
case '.ant-menu-horizontal>.ant-menu-item-active,.ant-menu-horizontal>.ant-menu-item-open,.ant-menu-horizontal>.ant-menu-item-selected,.ant-menu-horizontal>.ant-menu-item:hover,.ant-menu-horizontal>.ant-menu-submenu-active,.ant-menu-horizontal>.ant-menu-submenu-open,.ant-menu-horizontal>.ant-menu-submenu-selected,.ant-menu-horizontal>.ant-menu-submenu:hover':
30-
case '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal > .ant-menu-submenu-selected,.ant-menu-horizontal > .ant-menu-submenu:hover':
31-
return '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu:hover'
32-
case '.ant-menu-horizontal > .ant-menu-item-selected > a':
33-
case '.ant-menu-horizontal>.ant-menu-item-selected>a':
34-
return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item-selected > a'
35-
case '.ant-menu-horizontal > .ant-menu-item > a:hover':
36-
case '.ant-menu-horizontal>.ant-menu-item>a:hover':
37-
return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item > a:hover'
38-
default :
39-
return selector
40+
function createThemeColorReplacer() {
41+
// generate theme color replacement styles
42+
const plugin = new ThemeColorReplacer({
43+
fileName: 'css/theme-colors-[contenthash:8].css',
44+
matchColors: getAntdSerials('#2f54eb'), // primary color series
45+
// change style selectors to solve style override issues
46+
changeSelector(selector) {
47+
switch (selector) {
48+
case '.ant-calendar-today .ant-calendar-date':
49+
return ':not(.ant-calendar-selected-date):not(.ant-calendar-selected-day)' + selector
50+
case '.ant-btn:focus,.ant-btn:hover':
51+
return '.ant-btn:focus:not(.ant-btn-primary),.ant-btn:hover:not(.ant-btn-primary)'
52+
case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
53+
return ':not(.ant-steps-item-process)' + selector
54+
case '.ant-btn.active,.ant-btn:active':
55+
return '.ant-btn.active:not(.ant-btn-primary),.ant-btn:active:not(.ant-btn-primary)'
56+
case '.ant-menu-horizontal>.ant-menu-item-active,.ant-menu-horizontal>.ant-menu-item-open,.ant-menu-horizontal>.ant-menu-item-selected,.ant-menu-horizontal>.ant-menu-item:hover,.ant-menu-horizontal>.ant-menu-submenu-active,.ant-menu-horizontal>.ant-menu-submenu-open,.ant-menu-horizontal>.ant-menu-submenu-selected,.ant-menu-horizontal>.ant-menu-submenu:hover':
57+
case '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal > .ant-menu-submenu-selected,.ant-menu-horizontal > .ant-menu-submenu:hover':
58+
return '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu:hover'
59+
case '.ant-menu-horizontal > .ant-menu-item-selected > a':
60+
return ':not(.ant-menu-horizontal)' + selector
61+
case '.ant-menu-horizontal > .ant-menu-item > a:hover':
62+
return ':not(.ant-menu-horizontal)' + selector
63+
default:
64+
return selector
65+
}
66+
},
67+
})
68+
69+
const assetsExtractor = plugin.handler?.assetsExtractor
70+
const originalExtractAsset = assetsExtractor.extractAsset.bind(assetsExtractor)
71+
assetsExtractor.extractAsset = function(assetName, asset) {
72+
// Monaco generates a large runtime/worker bundle; this plugin scans all JavaScript files as potential CSS containers.
73+
// Skip Monaco-related artifacts to avoid stack overflow caused by excessive regular expression/recursive parsing during the build process.
74+
if (isMonacoAsset(assetName, asset)) {
75+
return []
4076
}
77+
78+
return originalExtractAsset(assetName, asset)
4179
}
80+
81+
return plugin
4282
}
4383

44-
const createThemeColorReplacerPlugin = () => new ThemeColorReplacer(themePluginOption)
84+
webpackPlugins.push(
85+
createThemeColorReplacer()
86+
)
4587

46-
module.exports = createThemeColorReplacerPlugin
88+
module.exports = {
89+
webpackPlugins
90+
}

cmdb-ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"axios": "0.18.0",
2424
"babel-eslint": "^8.2.2",
2525
"butterfly-dag": "^4.3.26",
26-
"codemirror": "^5.65.13",
2726
"core-js": "^3.31.0",
2827
"echarts": "^5.3.2",
2928
"element-ui": "^2.15.10",
@@ -38,6 +37,9 @@
3837
"lodash.pick": "^4.4.0",
3938
"md5": "^2.2.1",
4039
"moment": "^2.24.0",
40+
"monaco-editor": "^0.28.1",
41+
"monaco-editor-webpack-plugin": "^4.2.0",
42+
"monaco-vim": "^0.4.4",
4143
"nprogress": "^0.2.0",
4244
"relation-graph": "^2.1.42",
4345
"snabbdom": "^3.5.1",
@@ -47,7 +49,6 @@
4749
"vue": "2.6.11",
4850
"vue-clipboard2": "^0.3.3",
4951
"vue-cli-plugin-style-resources-loader": "^0.1.5",
50-
"vue-codemirror": "^4.0.6",
5152
"vue-cropper": "^0.6.2",
5253
"vue-grid-layout": "2.3.12",
5354
"vue-i18n": "8.28.2",

cmdb-ui/src/components/CustomCodeMirror/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)