@blocklet/editor 2.4.86 → 2.4.87
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.
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { type EditorThemeClasses } from 'lexical';
|
|
2
|
+
export declare const LANGUAGE_ALIAS: Record<string, string>;
|
|
3
|
+
export declare const LANGUAGE_ICON: Record<string, string>;
|
|
4
|
+
export declare const XCODE_TRANSLATIONS: {
|
|
5
|
+
en: {
|
|
6
|
+
seeAllLines: string;
|
|
7
|
+
collapseCode: string;
|
|
8
|
+
};
|
|
9
|
+
zh: {
|
|
10
|
+
seeAllLines: string;
|
|
11
|
+
collapseCode: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
2
14
|
export interface CodeProps {
|
|
3
15
|
editorTheme: EditorThemeClasses;
|
|
4
16
|
language: string;
|
|
5
17
|
title: string;
|
|
6
18
|
body?: string;
|
|
7
|
-
icon?: string;
|
|
8
19
|
foldable?: string;
|
|
9
20
|
foldthreshold?: string;
|
|
10
21
|
}
|
|
11
|
-
export default function Code({ editorTheme, language, title, body,
|
|
22
|
+
export default function Code({ editorTheme, language, title, body, foldable: _foldable, foldthreshold: _foldThreshold, }: CodeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -6,7 +6,310 @@ import { Icon } from '@iconify/react';
|
|
|
6
6
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
7
7
|
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
8
8
|
import { useMemoizedFn } from 'ahooks';
|
|
9
|
-
|
|
9
|
+
// 语言别名映射
|
|
10
|
+
export const LANGUAGE_ALIAS = {
|
|
11
|
+
adoc: 'asciidoc',
|
|
12
|
+
be: 'berry',
|
|
13
|
+
cdc: 'cadence',
|
|
14
|
+
clj: 'clojure',
|
|
15
|
+
ql: 'codeql',
|
|
16
|
+
lisp: 'common-lisp',
|
|
17
|
+
cql: 'cypher',
|
|
18
|
+
f: 'fortran-fixed-form',
|
|
19
|
+
for: 'fortran-fixed-form',
|
|
20
|
+
f77: 'fortran-fixed-form',
|
|
21
|
+
fortran: 'fortran-fixed-form',
|
|
22
|
+
f90: 'fortran-free-form',
|
|
23
|
+
f95: 'fortran-free-form',
|
|
24
|
+
f03: 'fortran-free-form',
|
|
25
|
+
f08: 'fortran-free-form',
|
|
26
|
+
f18: 'fortran-free-form',
|
|
27
|
+
ftl: 'fluent',
|
|
28
|
+
fs: 'fsharp',
|
|
29
|
+
fsl: 'jssm',
|
|
30
|
+
'f#': 'fsharp',
|
|
31
|
+
golang: 'go',
|
|
32
|
+
gis: 'glimmer-js',
|
|
33
|
+
gts: 'glimmer-ts',
|
|
34
|
+
kt: 'kotlin',
|
|
35
|
+
kts: 'kotlin',
|
|
36
|
+
kql: 'kusto',
|
|
37
|
+
hbs: 'handlebars',
|
|
38
|
+
hs: 'haskell',
|
|
39
|
+
make: 'makefile',
|
|
40
|
+
mediawiki: 'wikitext',
|
|
41
|
+
nf: 'nextflow',
|
|
42
|
+
nu: 'nushell',
|
|
43
|
+
objectivec: 'objective-c',
|
|
44
|
+
objc: 'objective-c',
|
|
45
|
+
proto: 'protobuf',
|
|
46
|
+
ps: 'powershell',
|
|
47
|
+
ps1: 'powershell',
|
|
48
|
+
rb: 'ruby',
|
|
49
|
+
rs: 'rust',
|
|
50
|
+
shader: 'shaderlab',
|
|
51
|
+
vbnet: 'vb',
|
|
52
|
+
vy: 'vyper',
|
|
53
|
+
wiki: 'wikitext',
|
|
54
|
+
wl: 'wolfram',
|
|
55
|
+
yml: 'yaml',
|
|
56
|
+
};
|
|
57
|
+
// 语言 icon 映射 - 优先使用 logos 集合,其次使用其他集合
|
|
58
|
+
export const LANGUAGE_ICON = {
|
|
59
|
+
abap: 'logos:sap',
|
|
60
|
+
'actionscript-3': 'material-icon-theme:actionscript',
|
|
61
|
+
ada: '',
|
|
62
|
+
asciidoc: 'vscode-icons:file-type-asciidoc',
|
|
63
|
+
'angular-html': 'logos:angular-icon',
|
|
64
|
+
'angular-ts': 'logos:angular-icon',
|
|
65
|
+
apache: 'logos:apache',
|
|
66
|
+
apex: 'logos:salesforce',
|
|
67
|
+
apl: 'vscode-icons:file-type-apl',
|
|
68
|
+
applescript: 'logos:apple',
|
|
69
|
+
ara: '',
|
|
70
|
+
asm: '',
|
|
71
|
+
astro: 'logos:astro-icon',
|
|
72
|
+
awk: 'vscode-icons:file-type-awk',
|
|
73
|
+
ballerina: 'material-icon-theme:ballerina',
|
|
74
|
+
bash: 'vscode-icons:file-type-shell',
|
|
75
|
+
bat: 'catppuccin:batch',
|
|
76
|
+
batch: 'catppuccin:batch',
|
|
77
|
+
beancount: '',
|
|
78
|
+
berry: '',
|
|
79
|
+
bibtex: 'file-icons:bibtex',
|
|
80
|
+
bicep: 'logos:microsoft',
|
|
81
|
+
blade: 'logos:laravel',
|
|
82
|
+
c: 'logos:c',
|
|
83
|
+
'c#': 'logos:c-sharp',
|
|
84
|
+
'c++': 'logos:c-plusplus',
|
|
85
|
+
cadence: '',
|
|
86
|
+
clarity: '',
|
|
87
|
+
clojure: 'vscode-icons:file-type-clojurescript',
|
|
88
|
+
'closure-templates': '',
|
|
89
|
+
cmake: 'vscode-icons:file-type-cmake',
|
|
90
|
+
cmd: 'catppuccin:batch',
|
|
91
|
+
cobol: 'vscode-icons:file-type-cobol',
|
|
92
|
+
codeowners: 'vscode-icons:file-type-codeowners',
|
|
93
|
+
codeql: 'vscode-icons:file-type-codeql',
|
|
94
|
+
coffee: 'logos:coffeescript',
|
|
95
|
+
coffeescript: 'logos:coffeescript',
|
|
96
|
+
'common-lisp': 'vscode-icons:file-type-lisp',
|
|
97
|
+
console: '',
|
|
98
|
+
coq: 'file-icons:coq',
|
|
99
|
+
cpp: 'logos:c-plusplus',
|
|
100
|
+
crystal: 'logos:crystal',
|
|
101
|
+
cs: 'logos:c-sharp',
|
|
102
|
+
csharp: 'logos:c-sharp',
|
|
103
|
+
css: 'logos:css-3',
|
|
104
|
+
csv: 'material-symbols:csv',
|
|
105
|
+
cue: 'catppuccin:cue',
|
|
106
|
+
cypher: '',
|
|
107
|
+
d: '',
|
|
108
|
+
dart: 'logos:dart',
|
|
109
|
+
dax: 'logos:microsoft-power-bi',
|
|
110
|
+
desktop: '',
|
|
111
|
+
diff: 'vscode-icons:file-type-diff',
|
|
112
|
+
docker: 'logos:docker-icon',
|
|
113
|
+
dockerfile: 'logos:docker-icon',
|
|
114
|
+
dotenv: 'vscode-icons:file-type-dotenv',
|
|
115
|
+
'dream-maker': '',
|
|
116
|
+
edge: 'vscode-icons:file-type-edge',
|
|
117
|
+
elisp: 'logos:emacs',
|
|
118
|
+
elixir: 'vscode-icons:file-type-elixir',
|
|
119
|
+
elm: 'vscode-icons:file-type-elm',
|
|
120
|
+
'emacs-lisp': 'logos:emacs',
|
|
121
|
+
erb: 'logos:ruby',
|
|
122
|
+
erl: 'logos:erlang',
|
|
123
|
+
erlang: 'logos:erlang',
|
|
124
|
+
'fortran-fixed-form': 'vscode-icons:file-type-fortran',
|
|
125
|
+
'fortran-free-form': 'vscode-icons:file-type-fortran',
|
|
126
|
+
fennel: 'l',
|
|
127
|
+
fish: '',
|
|
128
|
+
fluent: '',
|
|
129
|
+
fsharp: 'vscode-icons:file-type-fsharp2',
|
|
130
|
+
gdresource: '',
|
|
131
|
+
gdscript: 'vscode-icons:file-type-gdscript',
|
|
132
|
+
gdshader: '',
|
|
133
|
+
genie: '',
|
|
134
|
+
gherkin: 'logos:cucumber',
|
|
135
|
+
'git-commit': 'logos:git-icon',
|
|
136
|
+
'git-rebase': 'logos:git-icon',
|
|
137
|
+
gjs: 'logos:gnome',
|
|
138
|
+
gleam: 'logos:gleam',
|
|
139
|
+
'glimmer-js': 'vscode-icons:file-type-glimmer',
|
|
140
|
+
'glimmer-ts': 'vscode-icons:file-type-glimmer',
|
|
141
|
+
glsl: 'logos:opengl',
|
|
142
|
+
gnuplot: 'vscode-icons:file-type-gnuplot',
|
|
143
|
+
go: 'vscode-icons:file-type-go',
|
|
144
|
+
gql: 'logos:graphql',
|
|
145
|
+
graphql: 'logos:graphql',
|
|
146
|
+
groovy: 'vscode-icons:file-type-groovy',
|
|
147
|
+
hack: 'logos:hack',
|
|
148
|
+
haml: 'logos:haml',
|
|
149
|
+
handlebars: 'vscode-icons:file-type-handlebars',
|
|
150
|
+
haskell: 'vscode-icons:file-type-haskell',
|
|
151
|
+
haxe: 'logos:haxe',
|
|
152
|
+
hcl: '',
|
|
153
|
+
hjson: 'vscode-icons:file-type-hjson',
|
|
154
|
+
hlsl: 'vscode-icons:file-type-hlsl',
|
|
155
|
+
html: 'logos:html-5',
|
|
156
|
+
'html-derivative': 'logos:html-5',
|
|
157
|
+
http: 'vscode-icons:file-type-http',
|
|
158
|
+
hxml: '',
|
|
159
|
+
hy: 'vscode-icons:file-type-hy',
|
|
160
|
+
imba: 'vscode-icons:file-type-imba',
|
|
161
|
+
ini: 'vscode-icons:file-type-ini',
|
|
162
|
+
jade: 'logos:pug',
|
|
163
|
+
java: 'logos:java',
|
|
164
|
+
javascript: 'logos:javascript',
|
|
165
|
+
jinja: 'vscode-icons:file-type-jinja',
|
|
166
|
+
jison: '',
|
|
167
|
+
jl: 'logos:julia',
|
|
168
|
+
js: 'logos:javascript',
|
|
169
|
+
json: 'vscode-icons:file-type-json',
|
|
170
|
+
json5: 'vscode-icons:file-type-json5',
|
|
171
|
+
jsonc: 'vscode-icons:file-type-json',
|
|
172
|
+
jsonl: 'vscode-icons:file-type-json',
|
|
173
|
+
jsonnet: 'vscode-icons:file-type-jsonnet',
|
|
174
|
+
jssm: '',
|
|
175
|
+
jsx: 'logos:react',
|
|
176
|
+
julia: 'logos:julia',
|
|
177
|
+
kotlin: 'vscode-icons:file-type-kotlin',
|
|
178
|
+
kusto: 'vscode-icons:file-type-kusto',
|
|
179
|
+
latex: '',
|
|
180
|
+
lean: 'vscode-icons:file-type-lean',
|
|
181
|
+
lean4: 'vscode-icons:file-type-lean',
|
|
182
|
+
less: 'logos:less',
|
|
183
|
+
liquid: 'logos:shopify',
|
|
184
|
+
lit: 'logos:lit',
|
|
185
|
+
log: 'vscode-icons:file-type-shell',
|
|
186
|
+
logo: '',
|
|
187
|
+
lua: 'logos:lua',
|
|
188
|
+
luau: 'vscode-icons:file-type-luau',
|
|
189
|
+
makefile: 'vscode-icons:file-type-makefile',
|
|
190
|
+
markdown: 'logos:markdown',
|
|
191
|
+
marko: 'logos:marko',
|
|
192
|
+
matlab: 'vscode-icons:file-type-matlab',
|
|
193
|
+
md: 'logos:markdown',
|
|
194
|
+
mdc: 'logos:markdown',
|
|
195
|
+
mdx: 'logos:mdx',
|
|
196
|
+
mermaid: '',
|
|
197
|
+
mojo: 'vscode-icons:file-type-mojo',
|
|
198
|
+
move: '',
|
|
199
|
+
nar: '',
|
|
200
|
+
narrat: '',
|
|
201
|
+
nextflow: 'vscode-icons:file-type-nextflow',
|
|
202
|
+
nginx: 'logos:nginx',
|
|
203
|
+
nim: 'vscode-icons:file-type-nim',
|
|
204
|
+
nix: 'vscode-icons:file-type-nix',
|
|
205
|
+
nushell: '',
|
|
206
|
+
'objective-c': 'vscode-icons:file-type-objectivec',
|
|
207
|
+
'objective-cpp': 'vscode-icons:file-type-objectivecpp',
|
|
208
|
+
ocaml: 'vscode-icons:file-type-ocaml',
|
|
209
|
+
pascal: '',
|
|
210
|
+
perl: 'logos:perl',
|
|
211
|
+
perl6: '',
|
|
212
|
+
php: 'logos:php',
|
|
213
|
+
plsql: 'vscode-icons:file-type-plsql',
|
|
214
|
+
po: '',
|
|
215
|
+
postcss: 'logos:postcss',
|
|
216
|
+
pot: '',
|
|
217
|
+
potx: '',
|
|
218
|
+
powerquery: '',
|
|
219
|
+
powershell: 'vscode-icons:file-type-powershell',
|
|
220
|
+
prisma: 'logos:prisma',
|
|
221
|
+
prolog: 'vscode-icons:file-type-prolog',
|
|
222
|
+
properties: '',
|
|
223
|
+
protobuf: 'vscode-icons:file-type-protobuf',
|
|
224
|
+
pug: 'logos:pug',
|
|
225
|
+
puppet: 'logos:puppet',
|
|
226
|
+
purescript: 'logos:purescript',
|
|
227
|
+
py: 'logos:python',
|
|
228
|
+
python: 'logos:python',
|
|
229
|
+
qml: 'logos:qt',
|
|
230
|
+
qmldir: 'logos:qt',
|
|
231
|
+
qss: 'logos:qt',
|
|
232
|
+
r: 'vscode-icons:file-type-r',
|
|
233
|
+
racket: 'vscode-icons:file-type-racket',
|
|
234
|
+
raku: 'vscode-icons:file-type-raku',
|
|
235
|
+
razor: 'vscode-icons:file-type-razor',
|
|
236
|
+
reg: 'vscode-icons:file-type-registry',
|
|
237
|
+
regex: '',
|
|
238
|
+
regexp: '',
|
|
239
|
+
rel: '',
|
|
240
|
+
riscv: '',
|
|
241
|
+
rst: '',
|
|
242
|
+
ruby: 'logos:ruby',
|
|
243
|
+
rust: 'logos:rust',
|
|
244
|
+
sas: 'vscode-icons:file-type-sas',
|
|
245
|
+
sass: 'logos:sass',
|
|
246
|
+
scala: 'logos:scala',
|
|
247
|
+
scheme: '',
|
|
248
|
+
scss: 'logos:sass',
|
|
249
|
+
sh: 'vscode-icons:file-type-shell',
|
|
250
|
+
shaderlab: 'vscode-icons:file-type-shaderlab',
|
|
251
|
+
shell: 'vscode-icons:file-type-shell',
|
|
252
|
+
shellscript: 'vscode-icons:file-type-shell',
|
|
253
|
+
shellsession: 'vscode-icons:file-type-shell',
|
|
254
|
+
smalltalk: '',
|
|
255
|
+
solidity: 'logos:solidity',
|
|
256
|
+
soy: '',
|
|
257
|
+
sparql: 'vscode-icons:file-type-sparql',
|
|
258
|
+
spl: '',
|
|
259
|
+
splunk: '',
|
|
260
|
+
sql: 'vscode-icons:file-type-sql',
|
|
261
|
+
'ssh-config': '',
|
|
262
|
+
stata: 'vscode-icons:file-type-stata',
|
|
263
|
+
styl: 'logos:stylus',
|
|
264
|
+
stylus: 'logos:stylus',
|
|
265
|
+
svelte: 'logos:svelte-icon',
|
|
266
|
+
swift: 'logos:swift',
|
|
267
|
+
'system-verilog': 'vscode-icons:file-type-systemverilog',
|
|
268
|
+
systemd: 'vscode-icons:file-type-systemd',
|
|
269
|
+
tasl: '',
|
|
270
|
+
tcl: 'vscode-icons:file-type-tcl',
|
|
271
|
+
templ: '',
|
|
272
|
+
terraform: 'logos:terraform',
|
|
273
|
+
tex: 'vscode-icons:file-type-light-tex',
|
|
274
|
+
tf: 'logos:terraform',
|
|
275
|
+
tfvars: 'logos:terraform',
|
|
276
|
+
toml: 'logos:toml',
|
|
277
|
+
ts: 'vscode-icons:file-type-typescript-official',
|
|
278
|
+
'ts-tags': 'vscode-icons:file-type-typescript-official',
|
|
279
|
+
tsp: 'vscode-icons:file-type-typescript-official',
|
|
280
|
+
tsv: '',
|
|
281
|
+
tsx: 'logos:react',
|
|
282
|
+
turtle: '',
|
|
283
|
+
twig: 'vscode-icons:file-type-twig',
|
|
284
|
+
typ: '',
|
|
285
|
+
typescript: 'vscode-icons:file-type-typescript-official',
|
|
286
|
+
typespec: 'vscode-icons:file-type-typescript-official',
|
|
287
|
+
typst: '',
|
|
288
|
+
v: '',
|
|
289
|
+
vala: 'vscode-icons:file-type-vala',
|
|
290
|
+
vb: 'vscode-icons:file-type-vb',
|
|
291
|
+
verilog: 'vscode-icons:file-type-systemverilog',
|
|
292
|
+
vhdl: 'vscode-icons:file-type-vhdl',
|
|
293
|
+
vim: 'logos:vim',
|
|
294
|
+
viml: 'logos:vim',
|
|
295
|
+
vimscript: 'logos:vim',
|
|
296
|
+
vue: 'logos:vue',
|
|
297
|
+
'vue-html': 'logos:vue',
|
|
298
|
+
vyper: 'vscode-icons:file-type-vyper',
|
|
299
|
+
wasm: 'logos:webassembly',
|
|
300
|
+
wenyan: '',
|
|
301
|
+
wgsl: 'vscode-icons:file-type-wgsl',
|
|
302
|
+
wikitext: 'vscode-icons:file-type-wikitext',
|
|
303
|
+
wolfram: 'vscode-icons:file-type-wolfram',
|
|
304
|
+
xml: 'vscode-icons:file-type-xml',
|
|
305
|
+
xsl: 'vscode-icons:file-type-xsl',
|
|
306
|
+
yaml: 'vscode-icons:file-type-yaml',
|
|
307
|
+
zenscript: '',
|
|
308
|
+
zig: 'vscode-icons:file-type-zig',
|
|
309
|
+
zsh: 'logos:zsh',
|
|
310
|
+
};
|
|
311
|
+
// 多语言翻译
|
|
312
|
+
export const XCODE_TRANSLATIONS = {
|
|
10
313
|
en: {
|
|
11
314
|
seeAllLines: 'See all {lines} lines',
|
|
12
315
|
collapseCode: 'Collapse code',
|
|
@@ -16,25 +319,6 @@ const translations = {
|
|
|
16
319
|
collapseCode: '折叠代码',
|
|
17
320
|
},
|
|
18
321
|
};
|
|
19
|
-
const XCode = styled('div')(({ theme }) => ({
|
|
20
|
-
position: 'relative',
|
|
21
|
-
borderRadius: theme.shape.borderRadius,
|
|
22
|
-
border: '1px solid',
|
|
23
|
-
borderColor: theme.palette.divider,
|
|
24
|
-
overflow: 'hidden',
|
|
25
|
-
pre: {
|
|
26
|
-
margin: 0,
|
|
27
|
-
borderRadius: 0,
|
|
28
|
-
code: {
|
|
29
|
-
margin: 0,
|
|
30
|
-
border: 0,
|
|
31
|
-
borderRadius: 0,
|
|
32
|
-
background: 'transparent',
|
|
33
|
-
color: 'inherit',
|
|
34
|
-
overflow: 'hidden',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}));
|
|
38
322
|
/** Header 组件 */
|
|
39
323
|
function CodeHeader({ title, icon, actions }) {
|
|
40
324
|
if (!title && !icon)
|
|
@@ -48,7 +332,7 @@ function CodeHeader({ title, icon, actions }) {
|
|
|
48
332
|
borderColor: 'divider',
|
|
49
333
|
bgcolor: 'background.paper',
|
|
50
334
|
borderRadius: '8px 8px 0 0',
|
|
51
|
-
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, flex: 1 }, children: [icon && _jsx(Box, { component: Icon, icon: icon, sx: { fontSize: '
|
|
335
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, flex: 1 }, children: [icon && (_jsx(Box, { component: Icon, icon: icon, sx: { fontSize: '22px', height: '22px', lineHeight: '22px', color: 'text.secondary' } })), title && (_jsx(Typography, { variant: "body2", sx: { color: 'text.secondary', fontWeight: 500 }, children: title }))] }), actions && _jsx(Box, { sx: { display: 'flex', alignItems: 'center', gap: 0.5 }, children: actions })] }));
|
|
52
336
|
}
|
|
53
337
|
/** 通用操作按钮 */
|
|
54
338
|
function ActionButton({ className, icon, onClick, sx = {}, }) {
|
|
@@ -89,7 +373,7 @@ function FoldButton({ isCollapsed, onToggle, sx = {} }) {
|
|
|
89
373
|
/** 折叠 Footer */
|
|
90
374
|
function FoldFooter({ remainingLines, isCollapsed, onToggle, }) {
|
|
91
375
|
const { locale = 'en' } = useLocaleContext();
|
|
92
|
-
const t = useMemoizedFn((key, data = {}) => translate(
|
|
376
|
+
const t = useMemoizedFn((key, data = {}) => translate(XCODE_TRANSLATIONS, key, locale, 'en', data));
|
|
93
377
|
return (_jsx(Box, { sx: {
|
|
94
378
|
display: 'flex',
|
|
95
379
|
alignItems: 'center',
|
|
@@ -105,7 +389,26 @@ function FoldFooter({ remainingLines, isCollapsed, onToggle, }) {
|
|
|
105
389
|
},
|
|
106
390
|
}, onClick: onToggle, children: _jsxs(Typography, { variant: "body2", sx: { color: 'text.secondary', fontWeight: 500, display: 'flex', alignItems: 'center' }, children: [_jsx(Box, { component: Icon, icon: "tabler:dots", sx: { fontSize: '1em', mr: 1 } }), isCollapsed ? t('seeAllLines', { lines: remainingLines }) : t('collapseCode', { lines: remainingLines })] }) }));
|
|
107
391
|
}
|
|
108
|
-
|
|
392
|
+
const XCode = styled('div')(({ theme }) => ({
|
|
393
|
+
position: 'relative',
|
|
394
|
+
borderRadius: theme.shape.borderRadius,
|
|
395
|
+
border: '1px solid',
|
|
396
|
+
borderColor: theme.palette.divider,
|
|
397
|
+
overflow: 'hidden',
|
|
398
|
+
pre: {
|
|
399
|
+
margin: 0,
|
|
400
|
+
borderRadius: 0,
|
|
401
|
+
code: {
|
|
402
|
+
margin: 0,
|
|
403
|
+
border: 0,
|
|
404
|
+
borderRadius: 0,
|
|
405
|
+
background: 'transparent',
|
|
406
|
+
color: 'inherit',
|
|
407
|
+
overflow: 'hidden',
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
}));
|
|
411
|
+
export default function Code({ editorTheme, language, title, body = '', foldable: _foldable = 'true', foldthreshold: _foldThreshold = '25', // ps: dataset 会强制将 key 小写
|
|
109
412
|
}) {
|
|
110
413
|
const [highlightedCode, setHighlightedCode] = useState('');
|
|
111
414
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -116,6 +419,8 @@ export default function Code({ editorTheme, language, title, body = '', icon = '
|
|
|
116
419
|
if (Number.isNaN(foldThreshold)) {
|
|
117
420
|
foldThreshold = 25;
|
|
118
421
|
}
|
|
422
|
+
const _lang = LANGUAGE_ALIAS[language] || language;
|
|
423
|
+
const languageIcon = LANGUAGE_ICON[_lang] || 'heroicons:code-bracket-solid';
|
|
119
424
|
const lineCount = body ? body.split('\n').length : 0;
|
|
120
425
|
const showFoldButton = foldable && lineCount > foldThreshold;
|
|
121
426
|
// 初始折叠状态:启用折叠且超过阈值就折叠
|
|
@@ -143,26 +448,39 @@ export default function Code({ editorTheme, language, title, body = '', icon = '
|
|
|
143
448
|
return;
|
|
144
449
|
}
|
|
145
450
|
setIsLoading(true);
|
|
146
|
-
|
|
451
|
+
const processCodeHtml = async (lang) => {
|
|
147
452
|
const html = await codeToHtml(contentToHighlight, {
|
|
148
|
-
lang
|
|
453
|
+
lang,
|
|
149
454
|
theme: shikiTheme,
|
|
150
455
|
});
|
|
151
|
-
|
|
456
|
+
return html.replace(/<code([^>]*)>/g, `<code$1 class="${editorTheme.code}" data-gutter="${gutter}" data-language="${lang}">`);
|
|
457
|
+
};
|
|
458
|
+
try {
|
|
459
|
+
let processedHtml = '';
|
|
460
|
+
// 受支持的语言
|
|
461
|
+
if (Object.prototype.hasOwnProperty.call(LANGUAGE_ICON, _lang)) {
|
|
462
|
+
processedHtml = await processCodeHtml(_lang);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
processedHtml = await processCodeHtml('plain');
|
|
466
|
+
}
|
|
467
|
+
setHighlightedCode(processedHtml);
|
|
152
468
|
}
|
|
153
469
|
catch (error) {
|
|
154
|
-
console.
|
|
155
|
-
|
|
470
|
+
console.warn('Code highlighting failed:', error);
|
|
471
|
+
// fallback to plain text
|
|
472
|
+
const processedPlainText = await processCodeHtml('plain');
|
|
473
|
+
setHighlightedCode(processedPlainText);
|
|
156
474
|
}
|
|
157
475
|
finally {
|
|
158
476
|
setIsLoading(false);
|
|
159
477
|
}
|
|
160
478
|
};
|
|
161
479
|
highlightCode();
|
|
162
|
-
}, [body,
|
|
163
|
-
const shouldShowHeader = title ||
|
|
480
|
+
}, [body, _lang, shikiTheme, isCollapsed, foldThreshold, gutter]);
|
|
481
|
+
const shouldShowHeader = title || languageIcon;
|
|
164
482
|
const actions = (_jsxs(_Fragment, { children: [showFoldButton && _jsx(FoldButton, { isCollapsed: isCollapsed, onToggle: () => setIsCollapsed(!isCollapsed) }), _jsx(CopyButton, { content: body })] }));
|
|
165
|
-
return (_jsxs(XCode, { className: "x-code", children: [shouldShowHeader && (_jsx(CodeHeader, { title: title, icon:
|
|
483
|
+
return (_jsxs(XCode, { className: "x-code", children: [shouldShowHeader && (_jsx(CodeHeader, { title: title, icon: languageIcon, actions: _jsx(Stack, { alignItems: "center", direction: "row", spacing: 0.5, children: actions }) })), !isLoading && highlightedCode ? (_jsxs(_Fragment, { children: [_jsx("div", { dangerouslySetInnerHTML: { __html: highlightedCode } }), !shouldShowHeader && (_jsx(Stack, { alignItems: "center", direction: "row", spacing: 0.5, sx: { position: 'absolute', right: '12px', top: '12px' }, children: actions }))] })) : (_jsx("pre", { children: _jsx("code", { className: editorTheme.code, "data-gutter": gutter, "data-language": language, style: {
|
|
166
484
|
opacity: 0.15,
|
|
167
485
|
filter: 'blur(0.5px)',
|
|
168
486
|
pointerEvents: 'none',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.87",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"ufo": "^1.5.4",
|
|
72
72
|
"url-join": "^4.0.1",
|
|
73
73
|
"zustand": "^4.5.5",
|
|
74
|
-
"@blocklet/pdf": "2.4.
|
|
74
|
+
"@blocklet/pdf": "2.4.87"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@babel/core": "^7.25.2",
|