@fc-components/monaco-editor 0.1.12 → 0.1.14
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/dist/index.d.ts +2 -0
- package/dist/monaco-editor.cjs.development.js +923 -1
- package/dist/monaco-editor.cjs.development.js.map +1 -1
- package/dist/monaco-editor.cjs.production.min.js +1 -1
- package/dist/monaco-editor.cjs.production.min.js.map +1 -1
- package/dist/monaco-editor.esm.js +923 -2
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/yaml/completion/getCompletionProvider.d.ts +4 -0
- package/dist/yaml/index.d.ts +19 -0
- package/dist/yaml/types.d.ts +39 -0
- package/dist/yaml/validation.d.ts +3 -0
- package/dist/yaml/yaml.d.ts +56 -0
- package/package.json +1 -1
- package/src/index.tsx +2 -0
- package/src/promql/index.tsx +4 -0
- package/src/yaml/completion/getCompletionProvider.ts +431 -0
- package/src/yaml/index.tsx +385 -0
- package/src/yaml/types.ts +44 -0
- package/src/yaml/validation.ts +127 -0
- package/src/yaml/yaml.ts +150 -0
|
@@ -2241,7 +2241,11 @@ function PromQLEditor(props) {
|
|
|
2241
2241
|
},
|
|
2242
2242
|
scrollBeyondLastLine: false,
|
|
2243
2243
|
suggest: {
|
|
2244
|
-
showWords: false
|
|
2244
|
+
showWords: false,
|
|
2245
|
+
// 防止补全层自动关闭的关键配置
|
|
2246
|
+
filterGraceful: false,
|
|
2247
|
+
snippetsPreventQuickSuggestions: false,
|
|
2248
|
+
shareSuggestSelections: false
|
|
2245
2249
|
},
|
|
2246
2250
|
suggestFontSize: 12,
|
|
2247
2251
|
wordWrap: 'on',
|
|
@@ -2251,5 +2255,922 @@ function PromQLEditor(props) {
|
|
|
2251
2255
|
})));
|
|
2252
2256
|
}
|
|
2253
2257
|
|
|
2254
|
-
|
|
2258
|
+
var languageConfiguration$1 = {
|
|
2259
|
+
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
|
2260
|
+
comments: {
|
|
2261
|
+
lineComment: '#'
|
|
2262
|
+
},
|
|
2263
|
+
brackets: [['{', '}'], ['[', ']']],
|
|
2264
|
+
autoClosingPairs: [{
|
|
2265
|
+
open: '{',
|
|
2266
|
+
close: '}'
|
|
2267
|
+
}, {
|
|
2268
|
+
open: '[',
|
|
2269
|
+
close: ']'
|
|
2270
|
+
}, {
|
|
2271
|
+
open: '"',
|
|
2272
|
+
close: '"'
|
|
2273
|
+
}, {
|
|
2274
|
+
open: "'",
|
|
2275
|
+
close: "'"
|
|
2276
|
+
}],
|
|
2277
|
+
surroundingPairs: [{
|
|
2278
|
+
open: '{',
|
|
2279
|
+
close: '}'
|
|
2280
|
+
}, {
|
|
2281
|
+
open: '[',
|
|
2282
|
+
close: ']'
|
|
2283
|
+
}, {
|
|
2284
|
+
open: '"',
|
|
2285
|
+
close: '"'
|
|
2286
|
+
}, {
|
|
2287
|
+
open: "'",
|
|
2288
|
+
close: "'"
|
|
2289
|
+
}],
|
|
2290
|
+
folding: {
|
|
2291
|
+
offSide: true
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
// YAML keywords
|
|
2295
|
+
var keywords$1 = ['true', 'false', 'null', 'True', 'False', 'Null', 'TRUE', 'FALSE', 'NULL', 'yes', 'no', 'Yes', 'No', 'YES', 'NO', 'on', 'off', 'On', 'Off', 'ON', 'OFF'];
|
|
2296
|
+
// YAML operators and special characters (for future use)
|
|
2297
|
+
// const operators = [':', '-', '|', '>', '&', '*', '!', '%', '@'];
|
|
2298
|
+
var language$1 = {
|
|
2299
|
+
tokenPostfix: '.yaml',
|
|
2300
|
+
brackets: [{
|
|
2301
|
+
token: 'delimiter.bracket',
|
|
2302
|
+
open: '{',
|
|
2303
|
+
close: '}'
|
|
2304
|
+
}, {
|
|
2305
|
+
token: 'delimiter.square',
|
|
2306
|
+
open: '[',
|
|
2307
|
+
close: ']'
|
|
2308
|
+
}],
|
|
2309
|
+
keywords: keywords$1,
|
|
2310
|
+
numberInteger: /(?:0|[+-]?[0-9]+)/,
|
|
2311
|
+
numberFloat: /(?:0|[+-]?[0-9]+)(?:\.[0-9]+)?(?:e[-+][1-9][0-9]*)?/,
|
|
2312
|
+
numberOctal: /0o[0-7]+/,
|
|
2313
|
+
numberHex: /0x[0-9a-fA-F]+/,
|
|
2314
|
+
numberInfinity: /[+-]?\.(?:inf|Inf|INF)/,
|
|
2315
|
+
numberNaN: /\.(?:nan|Nan|NAN)/,
|
|
2316
|
+
numberDate: /\d{4}-\d{2}-\d{2}(?:[Tt ]\d{1,2}:\d{2}:\d{2}(?:\.\d*)?(?:[ \t]*(?:Z|[-+]\d{1,2}(?::\d{2})?))?)?/,
|
|
2317
|
+
escapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,
|
|
2318
|
+
tokenizer: {
|
|
2319
|
+
root: [{
|
|
2320
|
+
include: '@whitespace'
|
|
2321
|
+
}, {
|
|
2322
|
+
include: '@comment'
|
|
2323
|
+
},
|
|
2324
|
+
// Document markers
|
|
2325
|
+
[/^---/, 'meta.document'], [/^\.{3}/, 'meta.document'],
|
|
2326
|
+
// Keys (property names)
|
|
2327
|
+
[/^(\s*)([^:\s]+)(\s*)(:)/, ['white', 'key', 'white', 'delimiter']], [/(\s*)([^:\s]+)(\s*)(:)/, ['white', 'key', 'white', 'delimiter']],
|
|
2328
|
+
// Flow collections
|
|
2329
|
+
[/\{/, '@brackets', '@flowMap'], [/\[/, '@brackets', '@flowSequence'],
|
|
2330
|
+
// Block scalars
|
|
2331
|
+
[/[|>][-+]?(\d+)?/, 'string.block', '@blockScalar'],
|
|
2332
|
+
// Numbers
|
|
2333
|
+
[/@numberInfinity/, 'number.infinity'], [/@numberNaN/, 'number.nan'], [/@numberDate/, 'number.date'], [/@numberHex/, 'number.hex'], [/@numberOctal/, 'number.octal'], [/@numberFloat/, 'number.float'], [/@numberInteger/, 'number'],
|
|
2334
|
+
// Strings
|
|
2335
|
+
[/"([^"\\]|\\.)*$/, 'string.invalid'], [/'([^'\\]|\\.)*$/, 'string.invalid'], [/"/, 'string', '@doubleQuotedString'], [/'/, 'string', '@singleQuotedString'],
|
|
2336
|
+
// Anchors and aliases
|
|
2337
|
+
[/&\w+/, 'tag.anchor'], [/\*\w+/, 'tag.alias'],
|
|
2338
|
+
// Tags
|
|
2339
|
+
[/![\w\-\/]+/, 'tag'],
|
|
2340
|
+
// Keywords
|
|
2341
|
+
[/[^\s\[\{\,]+/, {
|
|
2342
|
+
cases: {
|
|
2343
|
+
'@keywords': 'keyword',
|
|
2344
|
+
'@default': 'string.unquoted'
|
|
2345
|
+
}
|
|
2346
|
+
}],
|
|
2347
|
+
// List items
|
|
2348
|
+
[/^(\s*)(-\s)/, ['white', 'delimiter']], [/(\s*)(-\s)/, ['white', 'delimiter']]],
|
|
2349
|
+
whitespace: [[/[ \t\r\n]+/, 'white']],
|
|
2350
|
+
comment: [[/#.*$/, 'comment']],
|
|
2351
|
+
doubleQuotedString: [[/[^\\"]+/, 'string'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/"/, 'string', '@pop']],
|
|
2352
|
+
singleQuotedString: [[/[^\\']+/, 'string'], [/''/, 'string.escape'], [/'/, 'string', '@pop']],
|
|
2353
|
+
blockScalar: [[/^(\s*).+$/, 'string.block'], [/^(?!\s)/, '', '@pop']],
|
|
2354
|
+
flowMap: [{
|
|
2355
|
+
include: '@whitespace'
|
|
2356
|
+
}, {
|
|
2357
|
+
include: '@comment'
|
|
2358
|
+
}, [/\}/, '@brackets', '@pop'], [/,/, 'delimiter'], [/:/, 'delimiter'], [/"/, 'string', '@doubleQuotedString'], [/'/, 'string', '@singleQuotedString'], [/[^\s\,\}\:]+/, 'string.unquoted']],
|
|
2359
|
+
flowSequence: [{
|
|
2360
|
+
include: '@whitespace'
|
|
2361
|
+
}, {
|
|
2362
|
+
include: '@comment'
|
|
2363
|
+
}, [/\]/, '@brackets', '@pop'], [/,/, 'delimiter'], [/"/, 'string', '@doubleQuotedString'], [/'/, 'string', '@singleQuotedString'], [/[^\s\,\]]+/, 'string.unquoted']]
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
|
|
2367
|
+
function getMonacoCompletionItemKind$1(type, monaco) {
|
|
2368
|
+
switch (type) {
|
|
2369
|
+
case 'KEYWORD':
|
|
2370
|
+
return monaco.languages.CompletionItemKind.Keyword;
|
|
2371
|
+
case 'VALUE':
|
|
2372
|
+
return monaco.languages.CompletionItemKind.Value;
|
|
2373
|
+
case 'KEY':
|
|
2374
|
+
return monaco.languages.CompletionItemKind.Property;
|
|
2375
|
+
case 'BOOLEAN':
|
|
2376
|
+
return monaco.languages.CompletionItemKind.Constant;
|
|
2377
|
+
case 'NUMBER':
|
|
2378
|
+
return monaco.languages.CompletionItemKind.Value;
|
|
2379
|
+
case 'STRING':
|
|
2380
|
+
return monaco.languages.CompletionItemKind.Text;
|
|
2381
|
+
default:
|
|
2382
|
+
return monaco.languages.CompletionItemKind.Text;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
function getYamlCompletionProvider(monaco, schemas) {
|
|
2386
|
+
if (schemas === void 0) {
|
|
2387
|
+
schemas = [];
|
|
2388
|
+
}
|
|
2389
|
+
// 更准确的位置分析
|
|
2390
|
+
var analyzePosition = function analyzePosition(model, position) {
|
|
2391
|
+
var line = model.getLineContent(position.lineNumber);
|
|
2392
|
+
var column = position.column;
|
|
2393
|
+
var beforeCursor = line.substring(0, column - 1);
|
|
2394
|
+
var trimmedLine = line.trim();
|
|
2395
|
+
// 检查是否在值位置
|
|
2396
|
+
var colonIndex = beforeCursor.indexOf(':');
|
|
2397
|
+
var isAfterColon = colonIndex !== -1;
|
|
2398
|
+
// 如果在冒号后面,检查是否是值位置
|
|
2399
|
+
var isInValuePosition = false;
|
|
2400
|
+
var currentKey = null;
|
|
2401
|
+
if (isAfterColon) {
|
|
2402
|
+
var keyPart = beforeCursor.substring(0, colonIndex).trim();
|
|
2403
|
+
// 如果键名以 - 开头(数组项),去掉 - 和后面的空格
|
|
2404
|
+
if (keyPart.startsWith('- ')) {
|
|
2405
|
+
keyPart = keyPart.substring(2).trim();
|
|
2406
|
+
} else if (keyPart === '-') {
|
|
2407
|
+
// 如果只有一个 -,说明键名在下一个词
|
|
2408
|
+
keyPart = '';
|
|
2409
|
+
}
|
|
2410
|
+
currentKey = keyPart;
|
|
2411
|
+
// 检查冒号后面是否有空格或者光标紧跟在冒号后面
|
|
2412
|
+
var afterColon = beforeCursor.substring(colonIndex + 1);
|
|
2413
|
+
isInValuePosition = afterColon.length === 0 || /^\s+$/.test(afterColon);
|
|
2414
|
+
}
|
|
2415
|
+
// 检查是否已经有完整的值
|
|
2416
|
+
var hasCompleteValue = trimmedLine.includes(':') && !trimmedLine.endsWith(':') && trimmedLine.split(':')[1].trim().length > 0;
|
|
2417
|
+
return {
|
|
2418
|
+
isInKeyPosition: !isAfterColon || trimmedLine.endsWith(':'),
|
|
2419
|
+
isInValuePosition: isInValuePosition && !hasCompleteValue,
|
|
2420
|
+
isAtEndOfCompletedValue: hasCompleteValue,
|
|
2421
|
+
currentKey: currentKey,
|
|
2422
|
+
line: trimmedLine,
|
|
2423
|
+
beforeCursor: beforeCursor,
|
|
2424
|
+
afterCursor: line.substring(column - 1)
|
|
2425
|
+
};
|
|
2426
|
+
}; // 从 schemas 中提取某个键的枚举值
|
|
2427
|
+
var getEnumValuesFromSchemas = function getEnumValuesFromSchemas(keyName, path) {
|
|
2428
|
+
if (path === void 0) {
|
|
2429
|
+
path = [];
|
|
2430
|
+
}
|
|
2431
|
+
var completions = [];
|
|
2432
|
+
for (var _iterator = _createForOfIteratorHelperLoose(schemas), _step; !(_step = _iterator()).done;) {
|
|
2433
|
+
var schemaItem = _step.value;
|
|
2434
|
+
var enumValues = extractEnumValues(schemaItem.schema, keyName, path);
|
|
2435
|
+
completions.push.apply(completions, enumValues);
|
|
2436
|
+
}
|
|
2437
|
+
return completions;
|
|
2438
|
+
};
|
|
2439
|
+
// 递归提取 schema 中的枚举值
|
|
2440
|
+
var extractEnumValues = function extractEnumValues(schema, targetKey, currentPath) {
|
|
2441
|
+
if (currentPath === void 0) {
|
|
2442
|
+
currentPath = [];
|
|
2443
|
+
}
|
|
2444
|
+
var completions = [];
|
|
2445
|
+
if (!schema || !schema.properties) {
|
|
2446
|
+
return completions;
|
|
2447
|
+
}
|
|
2448
|
+
// 如果路径为空,直接在当前层级查找
|
|
2449
|
+
if (currentPath.length === 0) {
|
|
2450
|
+
var prop = schema.properties[targetKey];
|
|
2451
|
+
if (prop && prop["enum"]) {
|
|
2452
|
+
return createEnumCompletions(prop);
|
|
2453
|
+
}
|
|
2454
|
+
return completions;
|
|
2455
|
+
}
|
|
2456
|
+
// 按路径导航到目标位置
|
|
2457
|
+
var currentSchema = schema;
|
|
2458
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(currentPath), _step2; !(_step2 = _iterator2()).done;) {
|
|
2459
|
+
var pathSegment = _step2.value;
|
|
2460
|
+
if (currentSchema.properties && currentSchema.properties[pathSegment]) {
|
|
2461
|
+
currentSchema = currentSchema.properties[pathSegment];
|
|
2462
|
+
// 如果是数组类型,使用 items 的 schema
|
|
2463
|
+
if (currentSchema.type === 'array' && currentSchema.items) {
|
|
2464
|
+
currentSchema = currentSchema.items;
|
|
2465
|
+
}
|
|
2466
|
+
} else {
|
|
2467
|
+
// 路径不存在,返回空
|
|
2468
|
+
return completions;
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
// 在目标位置查找枚举值
|
|
2472
|
+
if (currentSchema.properties && currentSchema.properties[targetKey]) {
|
|
2473
|
+
var _prop = currentSchema.properties[targetKey];
|
|
2474
|
+
if (_prop["enum"]) {
|
|
2475
|
+
return createEnumCompletions(_prop);
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
return completions;
|
|
2479
|
+
};
|
|
2480
|
+
// 创建枚举值补全项,支持 enumDescriptions 描述
|
|
2481
|
+
var createEnumCompletions = function createEnumCompletions(prop) {
|
|
2482
|
+
var completions = [];
|
|
2483
|
+
if (!prop["enum"]) {
|
|
2484
|
+
return completions;
|
|
2485
|
+
}
|
|
2486
|
+
prop["enum"].forEach(function (enumValue, index) {
|
|
2487
|
+
var description = prop.description || "Enum value: " + enumValue;
|
|
2488
|
+
// 如果有 enumDescriptions 数组,使用对应索引的描述
|
|
2489
|
+
if (prop.enumDescriptions && prop.enumDescriptions[index]) {
|
|
2490
|
+
description = prop.enumDescriptions[index];
|
|
2491
|
+
}
|
|
2492
|
+
completions.push({
|
|
2493
|
+
label: enumValue,
|
|
2494
|
+
insertText: enumValue,
|
|
2495
|
+
detail: description,
|
|
2496
|
+
documentation: description,
|
|
2497
|
+
type: 'VALUE'
|
|
2498
|
+
});
|
|
2499
|
+
});
|
|
2500
|
+
return completions;
|
|
2501
|
+
};
|
|
2502
|
+
// 从 schemas 中提取可用的键名
|
|
2503
|
+
var getKeyCompletionsFromSchemas = function getKeyCompletionsFromSchemas(path) {
|
|
2504
|
+
if (path === void 0) {
|
|
2505
|
+
path = [];
|
|
2506
|
+
}
|
|
2507
|
+
var completions = [];
|
|
2508
|
+
var addedKeys = new Set(); // 避免重复
|
|
2509
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(schemas), _step3; !(_step3 = _iterator3()).done;) {
|
|
2510
|
+
var schemaItem = _step3.value;
|
|
2511
|
+
var keyCompletions = extractKeyCompletions(schemaItem.schema, path);
|
|
2512
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(keyCompletions), _step4; !(_step4 = _iterator4()).done;) {
|
|
2513
|
+
var completion = _step4.value;
|
|
2514
|
+
if (!addedKeys.has(completion.label)) {
|
|
2515
|
+
addedKeys.add(completion.label);
|
|
2516
|
+
completions.push(completion);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
return completions;
|
|
2521
|
+
};
|
|
2522
|
+
// 递归提取 schema 中的键名
|
|
2523
|
+
var extractKeyCompletions = function extractKeyCompletions(schema, targetPath) {
|
|
2524
|
+
if (targetPath === void 0) {
|
|
2525
|
+
targetPath = [];
|
|
2526
|
+
}
|
|
2527
|
+
var completions = [];
|
|
2528
|
+
var currentSchema = schema;
|
|
2529
|
+
// 导航到目标路径
|
|
2530
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(targetPath), _step5; !(_step5 = _iterator5()).done;) {
|
|
2531
|
+
var pathSegment = _step5.value;
|
|
2532
|
+
if (currentSchema.properties && currentSchema.properties[pathSegment]) {
|
|
2533
|
+
currentSchema = currentSchema.properties[pathSegment];
|
|
2534
|
+
if (currentSchema.type === 'array' && currentSchema.items) {
|
|
2535
|
+
currentSchema = currentSchema.items;
|
|
2536
|
+
}
|
|
2537
|
+
} else {
|
|
2538
|
+
return completions; // 路径不存在
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
// 获取当前层级的属性
|
|
2542
|
+
if (currentSchema.properties) {
|
|
2543
|
+
for (var _i = 0, _Object$entries = Object.entries(currentSchema.properties); _i < _Object$entries.length; _i++) {
|
|
2544
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
2545
|
+
key = _Object$entries$_i[0],
|
|
2546
|
+
property = _Object$entries$_i[1];
|
|
2547
|
+
var prop = property;
|
|
2548
|
+
var insertText = key + ": ";
|
|
2549
|
+
var shouldTriggerOnInsert = false;
|
|
2550
|
+
// 根据属性类型调整插入文本和是否触发补全
|
|
2551
|
+
if (prop.type === 'object') {
|
|
2552
|
+
insertText = key + ":\n ";
|
|
2553
|
+
shouldTriggerOnInsert = true; // 对象类型需要触发键补全
|
|
2554
|
+
} else if (prop.type === 'array') {
|
|
2555
|
+
insertText = key + ":\n - ";
|
|
2556
|
+
shouldTriggerOnInsert = true; // 数组类型需要触发补全
|
|
2557
|
+
} else if (prop["enum"] && prop["enum"].length > 0) {
|
|
2558
|
+
// 有枚举值的字段需要触发值补全
|
|
2559
|
+
shouldTriggerOnInsert = true;
|
|
2560
|
+
} else if (prop.type === 'boolean') {
|
|
2561
|
+
// 布尔类型需要触发 true/false 补全
|
|
2562
|
+
shouldTriggerOnInsert = true;
|
|
2563
|
+
} else if (prop.type === 'number') {
|
|
2564
|
+
// 数字类型需要触发数字补全
|
|
2565
|
+
shouldTriggerOnInsert = true;
|
|
2566
|
+
}
|
|
2567
|
+
// 对于普通字符串字段,不触发补全
|
|
2568
|
+
completions.push({
|
|
2569
|
+
label: key,
|
|
2570
|
+
insertText: insertText,
|
|
2571
|
+
detail: prop.description || "Property: " + key,
|
|
2572
|
+
documentation: prop.description,
|
|
2573
|
+
type: 'KEY',
|
|
2574
|
+
triggerOnInsert: shouldTriggerOnInsert
|
|
2575
|
+
});
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
return completions;
|
|
2579
|
+
};
|
|
2580
|
+
var getFieldType = function getFieldType(keyName, path) {
|
|
2581
|
+
if (path === void 0) {
|
|
2582
|
+
path = [];
|
|
2583
|
+
}
|
|
2584
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(schemas), _step6; !(_step6 = _iterator6()).done;) {
|
|
2585
|
+
var schemaItem = _step6.value;
|
|
2586
|
+
var fieldType = extractFieldType(schemaItem.schema, keyName, path);
|
|
2587
|
+
if (fieldType) {
|
|
2588
|
+
return fieldType;
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
return null;
|
|
2592
|
+
};
|
|
2593
|
+
var extractFieldType = function extractFieldType(schema, targetKey, currentPath) {
|
|
2594
|
+
if (currentPath === void 0) {
|
|
2595
|
+
currentPath = [];
|
|
2596
|
+
}
|
|
2597
|
+
if (!schema || !schema.properties) {
|
|
2598
|
+
return null;
|
|
2599
|
+
}
|
|
2600
|
+
// 如果路径为空,直接在当前层级查找
|
|
2601
|
+
if (currentPath.length === 0) {
|
|
2602
|
+
var prop = schema.properties[targetKey];
|
|
2603
|
+
return prop ? prop.type : null;
|
|
2604
|
+
}
|
|
2605
|
+
// 按路径导航到目标位置
|
|
2606
|
+
var currentSchema = schema;
|
|
2607
|
+
for (var _iterator7 = _createForOfIteratorHelperLoose(currentPath), _step7; !(_step7 = _iterator7()).done;) {
|
|
2608
|
+
var pathSegment = _step7.value;
|
|
2609
|
+
if (currentSchema.properties && currentSchema.properties[pathSegment]) {
|
|
2610
|
+
currentSchema = currentSchema.properties[pathSegment];
|
|
2611
|
+
// 如果是数组类型,使用 items 的 schema
|
|
2612
|
+
if (currentSchema.type === 'array' && currentSchema.items) {
|
|
2613
|
+
currentSchema = currentSchema.items;
|
|
2614
|
+
}
|
|
2615
|
+
} else {
|
|
2616
|
+
// 路径不存在,返回空
|
|
2617
|
+
return null;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
// 在目标位置查找字段类型
|
|
2621
|
+
if (currentSchema.properties && currentSchema.properties[targetKey]) {
|
|
2622
|
+
var _prop2 = currentSchema.properties[targetKey];
|
|
2623
|
+
return _prop2.type;
|
|
2624
|
+
}
|
|
2625
|
+
return null;
|
|
2626
|
+
};
|
|
2627
|
+
var getCompletions = function getCompletions(model, position) {
|
|
2628
|
+
var wordInfo = model.getWordAtPosition(position);
|
|
2629
|
+
var word = wordInfo ? wordInfo.word : '';
|
|
2630
|
+
// 使用新的位置分析
|
|
2631
|
+
var positionInfo = analyzePosition(model, position);
|
|
2632
|
+
var currentPath = getCurrentPath(model, position);
|
|
2633
|
+
var completions = [];
|
|
2634
|
+
// 如果已经有完整的值,不提供任何补全
|
|
2635
|
+
if (positionInfo.isAtEndOfCompletedValue) {
|
|
2636
|
+
return [];
|
|
2637
|
+
}
|
|
2638
|
+
// 如果在值位置,提供值的补全
|
|
2639
|
+
if (positionInfo.isInValuePosition && positionInfo.currentKey) {
|
|
2640
|
+
// 查找枚举值补全
|
|
2641
|
+
var enumCompletions = getEnumValuesFromSchemas(positionInfo.currentKey, currentPath);
|
|
2642
|
+
if (enumCompletions.length > 0) {
|
|
2643
|
+
// 如果有枚举值,只返回枚举值
|
|
2644
|
+
completions.push.apply(completions, enumCompletions);
|
|
2645
|
+
} else {
|
|
2646
|
+
// 如果没有枚举值,检查字段类型
|
|
2647
|
+
var fieldType = getFieldType(positionInfo.currentKey, currentPath);
|
|
2648
|
+
if (fieldType === 'boolean') {
|
|
2649
|
+
// 只为布尔类型提供 true/false
|
|
2650
|
+
completions.push({
|
|
2651
|
+
label: 'true',
|
|
2652
|
+
insertText: 'true',
|
|
2653
|
+
detail: 'Boolean true value',
|
|
2654
|
+
type: 'BOOLEAN'
|
|
2655
|
+
}, {
|
|
2656
|
+
label: 'false',
|
|
2657
|
+
insertText: 'false',
|
|
2658
|
+
detail: 'Boolean false value',
|
|
2659
|
+
type: 'BOOLEAN'
|
|
2660
|
+
});
|
|
2661
|
+
} else if (fieldType === 'number') {
|
|
2662
|
+
// 为数字类型提供基本示例
|
|
2663
|
+
completions.push({
|
|
2664
|
+
label: '0',
|
|
2665
|
+
insertText: '0',
|
|
2666
|
+
detail: 'Number value',
|
|
2667
|
+
type: 'NUMBER'
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
// 对于 string 类型或其他类型,不提供任何补全
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
// 如果在键位置且不在值位置,提供键的补全
|
|
2674
|
+
else if (positionInfo.isInKeyPosition && !positionInfo.isInValuePosition) {
|
|
2675
|
+
// 从 schemas 中获取键补全
|
|
2676
|
+
var schemaKeyCompletions = getKeyCompletionsFromSchemas(currentPath);
|
|
2677
|
+
completions.push.apply(completions, schemaKeyCompletions);
|
|
2678
|
+
}
|
|
2679
|
+
// 过滤匹配的项目
|
|
2680
|
+
var filtered = completions.filter(function (item) {
|
|
2681
|
+
return !word || item.label.toLowerCase().includes(word.toLowerCase());
|
|
2682
|
+
});
|
|
2683
|
+
return filtered;
|
|
2684
|
+
};
|
|
2685
|
+
var getCurrentPath = function getCurrentPath(model, position) {
|
|
2686
|
+
var path = [];
|
|
2687
|
+
var lines = model.getLinesContent();
|
|
2688
|
+
var currentLineNumber = position.lineNumber - 1; // Monaco uses 1-based line numbers
|
|
2689
|
+
if (currentLineNumber >= lines.length) {
|
|
2690
|
+
return path;
|
|
2691
|
+
}
|
|
2692
|
+
var currentLine = lines[currentLineNumber];
|
|
2693
|
+
var currentIndent = getIndentLevel(currentLine);
|
|
2694
|
+
// 从当前行开始向上查找父级键
|
|
2695
|
+
var targetIndent = currentIndent;
|
|
2696
|
+
for (var i = currentLineNumber; i >= 0; i--) {
|
|
2697
|
+
var line = lines[i];
|
|
2698
|
+
var lineIndent = getIndentLevel(line);
|
|
2699
|
+
var trimmed = line.trim();
|
|
2700
|
+
// 跳过空行和注释
|
|
2701
|
+
if (!trimmed || trimmed.startsWith('#')) {
|
|
2702
|
+
continue;
|
|
2703
|
+
}
|
|
2704
|
+
// 如果缩进小于目标缩进
|
|
2705
|
+
if (lineIndent < targetIndent) {
|
|
2706
|
+
// 检查是否是数组项(以 - 开头)
|
|
2707
|
+
if (trimmed.startsWith('-')) {
|
|
2708
|
+
// 数组项不添加到路径中,只更新缩进继续查找
|
|
2709
|
+
targetIndent = lineIndent;
|
|
2710
|
+
continue;
|
|
2711
|
+
}
|
|
2712
|
+
// 如果包含冒号,这是一个父级键
|
|
2713
|
+
if (trimmed.includes(':')) {
|
|
2714
|
+
var key = trimmed.split(':')[0].trim();
|
|
2715
|
+
if (key) {
|
|
2716
|
+
path.unshift(key);
|
|
2717
|
+
targetIndent = lineIndent; // 更新目标缩进,继续向上查找
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
return path;
|
|
2723
|
+
};
|
|
2724
|
+
var getIndentLevel = function getIndentLevel(line) {
|
|
2725
|
+
return line.length - line.trimLeft().length;
|
|
2726
|
+
};
|
|
2727
|
+
var provideCompletionItems = function provideCompletionItems(model, position) {
|
|
2728
|
+
var word = model.getWordAtPosition(position);
|
|
2729
|
+
var range = word != null ? monaco.Range.lift({
|
|
2730
|
+
startLineNumber: position.lineNumber,
|
|
2731
|
+
endLineNumber: position.lineNumber,
|
|
2732
|
+
startColumn: word.startColumn,
|
|
2733
|
+
endColumn: word.endColumn
|
|
2734
|
+
}) : monaco.Range.fromPositions(position);
|
|
2735
|
+
var items = getCompletions(model, position);
|
|
2736
|
+
var suggestions = items.map(function (item, index) {
|
|
2737
|
+
return {
|
|
2738
|
+
kind: getMonacoCompletionItemKind$1(item.type, monaco),
|
|
2739
|
+
label: item.label,
|
|
2740
|
+
insertText: item.insertText,
|
|
2741
|
+
detail: item.detail,
|
|
2742
|
+
documentation: item.documentation,
|
|
2743
|
+
sortText: index.toString().padStart(3, '0'),
|
|
2744
|
+
range: range,
|
|
2745
|
+
command: item.triggerOnInsert ? {
|
|
2746
|
+
id: 'editor.action.triggerSuggest',
|
|
2747
|
+
title: ''
|
|
2748
|
+
} : undefined
|
|
2749
|
+
};
|
|
2750
|
+
});
|
|
2751
|
+
return {
|
|
2752
|
+
suggestions: suggestions
|
|
2753
|
+
};
|
|
2754
|
+
};
|
|
2755
|
+
return {
|
|
2756
|
+
triggerCharacters: [':', ' ', '-', '\n', '\t'],
|
|
2757
|
+
provideCompletionItems: provideCompletionItems
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
function validateYaml(content, schemas) {
|
|
2762
|
+
if (schemas === void 0) {
|
|
2763
|
+
schemas = [];
|
|
2764
|
+
}
|
|
2765
|
+
var errors = [];
|
|
2766
|
+
if (!content.trim()) {
|
|
2767
|
+
return errors;
|
|
2768
|
+
}
|
|
2769
|
+
try {
|
|
2770
|
+
// 基础 YAML 语法验证
|
|
2771
|
+
var lines = content.split('\n');
|
|
2772
|
+
for (var i = 0; i < lines.length; i++) {
|
|
2773
|
+
var line = lines[i];
|
|
2774
|
+
var lineNumber = i + 1;
|
|
2775
|
+
// 检查缩进一致性
|
|
2776
|
+
if (line.trim() && !isValidIndentation(line)) {
|
|
2777
|
+
errors.push({
|
|
2778
|
+
message: 'Invalid indentation. YAML requires consistent indentation.',
|
|
2779
|
+
startLineNumber: lineNumber,
|
|
2780
|
+
endLineNumber: lineNumber,
|
|
2781
|
+
startColumn: 1,
|
|
2782
|
+
endColumn: line.length + 1,
|
|
2783
|
+
severity: 'error'
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
// 检查冒号后是否有空格
|
|
2787
|
+
var colonMatch = line.match(/^(\s*)([^:\s]+)(:)(\S)/);
|
|
2788
|
+
if (colonMatch) {
|
|
2789
|
+
var startColumn = colonMatch[1].length + colonMatch[2].length + 2;
|
|
2790
|
+
errors.push({
|
|
2791
|
+
message: 'Missing space after colon. Use ": " instead of ":"',
|
|
2792
|
+
startLineNumber: lineNumber,
|
|
2793
|
+
endLineNumber: lineNumber,
|
|
2794
|
+
startColumn: startColumn,
|
|
2795
|
+
endColumn: startColumn + 1,
|
|
2796
|
+
severity: 'error'
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
// 检查列表项格式
|
|
2800
|
+
var listMatch = line.match(/^(\s*)-(\S)/);
|
|
2801
|
+
if (listMatch) {
|
|
2802
|
+
var _startColumn = listMatch[1].length + 2;
|
|
2803
|
+
errors.push({
|
|
2804
|
+
message: 'Missing space after dash. Use "- " instead of "-"',
|
|
2805
|
+
startLineNumber: lineNumber,
|
|
2806
|
+
endLineNumber: lineNumber,
|
|
2807
|
+
startColumn: _startColumn,
|
|
2808
|
+
endColumn: _startColumn + 1,
|
|
2809
|
+
severity: 'error'
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
// Schema 验证
|
|
2814
|
+
if (schemas.length > 0) {
|
|
2815
|
+
var schemaErrors = validateAgainstSchemas(content, schemas);
|
|
2816
|
+
errors.push.apply(errors, schemaErrors);
|
|
2817
|
+
}
|
|
2818
|
+
} catch (error) {
|
|
2819
|
+
errors.push({
|
|
2820
|
+
message: "YAML parsing error: " + error,
|
|
2821
|
+
startLineNumber: 1,
|
|
2822
|
+
endLineNumber: 1,
|
|
2823
|
+
startColumn: 1,
|
|
2824
|
+
endColumn: 1,
|
|
2825
|
+
severity: 'error'
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2828
|
+
return errors;
|
|
2829
|
+
}
|
|
2830
|
+
function isValidIndentation(line) {
|
|
2831
|
+
var trimmed = line.trim();
|
|
2832
|
+
if (!trimmed) return true;
|
|
2833
|
+
var leadingSpaces = line.length - line.trimLeft().length;
|
|
2834
|
+
// YAML 通常使用 2 或 4 个空格缩进
|
|
2835
|
+
return leadingSpaces % 2 === 0;
|
|
2836
|
+
}
|
|
2837
|
+
function validateAgainstSchemas(_content, _schemas) {
|
|
2838
|
+
var errors = [];
|
|
2839
|
+
// TODO: 实现更复杂的 schema 验证逻辑
|
|
2840
|
+
// 目前提供基础的结构验证
|
|
2841
|
+
// 可以在这里添加对 content 和 schemas 的具体验证
|
|
2842
|
+
return errors;
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
var _templateObject$1, _templateObject2$1;
|
|
2846
|
+
var YAML_LANG_ID = 'yaml';
|
|
2847
|
+
var SIZE_MAP$1 = {
|
|
2848
|
+
small: {
|
|
2849
|
+
className: 'ant-input-sm',
|
|
2850
|
+
top: 1,
|
|
2851
|
+
bottom: 1
|
|
2852
|
+
},
|
|
2853
|
+
middle: {
|
|
2854
|
+
className: 'ant-input-md',
|
|
2855
|
+
top: 1,
|
|
2856
|
+
bottom: 1
|
|
2857
|
+
},
|
|
2858
|
+
large: {
|
|
2859
|
+
className: 'ant-input-lg',
|
|
2860
|
+
top: 3,
|
|
2861
|
+
bottom: 2
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
var themeMap$1 = {
|
|
2865
|
+
light: 'yaml-light',
|
|
2866
|
+
dark: 'yaml-dark'
|
|
2867
|
+
};
|
|
2868
|
+
var containerDisabledClassName$1 = /*#__PURE__*/css(_templateObject$1 || (_templateObject$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
|
|
2869
|
+
var containerReadOnlyClassName$1 = /*#__PURE__*/css(_templateObject2$1 || (_templateObject2$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
|
|
2870
|
+
var getStyles$1 = function getStyles(placeholder) {
|
|
2871
|
+
return {
|
|
2872
|
+
placeholder: css({
|
|
2873
|
+
'::after': {
|
|
2874
|
+
content: "'" + placeholder + "'",
|
|
2875
|
+
opacity: 0.6
|
|
2876
|
+
}
|
|
2877
|
+
})
|
|
2878
|
+
};
|
|
2879
|
+
};
|
|
2880
|
+
function YamlEditor(props) {
|
|
2881
|
+
var id = v4();
|
|
2882
|
+
var _props$size = props.size,
|
|
2883
|
+
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
2884
|
+
_props$theme = props.theme,
|
|
2885
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
2886
|
+
value = props.value,
|
|
2887
|
+
placeholder = props.placeholder,
|
|
2888
|
+
_props$enableAutocomp = props.enableAutocomplete,
|
|
2889
|
+
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
2890
|
+
_props$readOnly = props.readOnly,
|
|
2891
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
2892
|
+
_props$disabled = props.disabled,
|
|
2893
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
2894
|
+
_props$schemas = props.schemas,
|
|
2895
|
+
schemas = _props$schemas === void 0 ? [] : _props$schemas,
|
|
2896
|
+
onChange = props.onChange,
|
|
2897
|
+
onEnter = props.onEnter,
|
|
2898
|
+
onBlur = props.onBlur,
|
|
2899
|
+
editorDidMount = props.editorDidMount;
|
|
2900
|
+
var autocompleteDisposeFun = useRef(null);
|
|
2901
|
+
var containerRef = useRef(null);
|
|
2902
|
+
var editorRef = useRef(null);
|
|
2903
|
+
var styles = getStyles$1(placeholder);
|
|
2904
|
+
var handleEditorDidMount = function handleEditorDidMount(editor$1) {
|
|
2905
|
+
editorRef.current = editor$1;
|
|
2906
|
+
// 定义主题
|
|
2907
|
+
editor.defineTheme('yaml-light', {
|
|
2908
|
+
base: 'vs',
|
|
2909
|
+
inherit: true,
|
|
2910
|
+
rules: [{
|
|
2911
|
+
token: 'key',
|
|
2912
|
+
foreground: '0000FF'
|
|
2913
|
+
}, {
|
|
2914
|
+
token: 'string',
|
|
2915
|
+
foreground: '008000'
|
|
2916
|
+
}, {
|
|
2917
|
+
token: 'number',
|
|
2918
|
+
foreground: '098658'
|
|
2919
|
+
}, {
|
|
2920
|
+
token: 'comment',
|
|
2921
|
+
foreground: '008000',
|
|
2922
|
+
fontStyle: 'italic'
|
|
2923
|
+
}, {
|
|
2924
|
+
token: 'delimiter',
|
|
2925
|
+
foreground: '000000'
|
|
2926
|
+
}, {
|
|
2927
|
+
token: 'tag',
|
|
2928
|
+
foreground: '800080'
|
|
2929
|
+
}, {
|
|
2930
|
+
token: 'keyword',
|
|
2931
|
+
foreground: '0000FF',
|
|
2932
|
+
fontStyle: 'bold'
|
|
2933
|
+
}],
|
|
2934
|
+
colors: {
|
|
2935
|
+
'editor.background': '#00000000',
|
|
2936
|
+
focusBorder: '#00000000'
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2939
|
+
editor.defineTheme('yaml-dark', {
|
|
2940
|
+
base: 'vs-dark',
|
|
2941
|
+
inherit: true,
|
|
2942
|
+
rules: [{
|
|
2943
|
+
token: 'key',
|
|
2944
|
+
foreground: '9CDCFE'
|
|
2945
|
+
}, {
|
|
2946
|
+
token: 'string',
|
|
2947
|
+
foreground: 'CE9178'
|
|
2948
|
+
}, {
|
|
2949
|
+
token: 'number',
|
|
2950
|
+
foreground: 'B5CEA8'
|
|
2951
|
+
}, {
|
|
2952
|
+
token: 'comment',
|
|
2953
|
+
foreground: '6A9955',
|
|
2954
|
+
fontStyle: 'italic'
|
|
2955
|
+
}, {
|
|
2956
|
+
token: 'delimiter',
|
|
2957
|
+
foreground: 'D4D4D4'
|
|
2958
|
+
}, {
|
|
2959
|
+
token: 'tag',
|
|
2960
|
+
foreground: 'C586C0'
|
|
2961
|
+
}, {
|
|
2962
|
+
token: 'keyword',
|
|
2963
|
+
foreground: '569CD6',
|
|
2964
|
+
fontStyle: 'bold'
|
|
2965
|
+
}],
|
|
2966
|
+
colors: {
|
|
2967
|
+
'editor.background': '#00000000',
|
|
2968
|
+
focusBorder: '#00000000'
|
|
2969
|
+
}
|
|
2970
|
+
});
|
|
2971
|
+
var isEditorFocused = editor$1.createContextKey('isEditorFocused' + id, false);
|
|
2972
|
+
// 设置焦点状态
|
|
2973
|
+
editor$1.onDidBlurEditorWidget(function () {
|
|
2974
|
+
isEditorFocused.set(false);
|
|
2975
|
+
onBlur == null || onBlur(editor$1.getValue());
|
|
2976
|
+
var position = editor$1.getPosition();
|
|
2977
|
+
if (position) {
|
|
2978
|
+
var newSelection = new Selection(position.lineNumber, position.column, position.lineNumber, position.column);
|
|
2979
|
+
editor$1.setSelection(newSelection);
|
|
2980
|
+
}
|
|
2981
|
+
});
|
|
2982
|
+
editor$1.onDidFocusEditorText(function () {
|
|
2983
|
+
isEditorFocused.set(true);
|
|
2984
|
+
});
|
|
2985
|
+
// 设置编辑器高度自适应
|
|
2986
|
+
var updateElementHeight = function updateElementHeight() {
|
|
2987
|
+
var containerDiv = containerRef.current;
|
|
2988
|
+
if (containerDiv !== null) {
|
|
2989
|
+
var pixelHeight = Math.max(editor$1.getContentHeight(), 20);
|
|
2990
|
+
containerDiv.style.height = pixelHeight + "px";
|
|
2991
|
+
containerDiv.style.width = '100%';
|
|
2992
|
+
var pixelWidth = containerDiv.clientWidth;
|
|
2993
|
+
editor$1.layout({
|
|
2994
|
+
width: pixelWidth,
|
|
2995
|
+
height: pixelHeight
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
editor$1.onDidContentSizeChange(updateElementHeight);
|
|
3000
|
+
updateElementHeight();
|
|
3001
|
+
// 禁用默认的搜索快捷键
|
|
3002
|
+
editor.addKeybindingRule({
|
|
3003
|
+
keybinding: KeyMod.CtrlCmd | KeyCode.KeyF,
|
|
3004
|
+
command: null
|
|
3005
|
+
});
|
|
3006
|
+
// Shift + Enter 换行
|
|
3007
|
+
editor$1.addCommand(KeyMod.Shift | KeyCode.Enter, function () {
|
|
3008
|
+
var position = editor$1.getPosition();
|
|
3009
|
+
if (position) {
|
|
3010
|
+
editor$1.executeEdits('shift-enter', [{
|
|
3011
|
+
range: new Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
|
3012
|
+
text: '\n'
|
|
3013
|
+
}]);
|
|
3014
|
+
editor$1.setPosition({
|
|
3015
|
+
lineNumber: position.lineNumber + 1,
|
|
3016
|
+
column: 1
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
}, 'isEditorFocused' + id);
|
|
3020
|
+
// Enter 键处理 - 移除阻止默认行为的规则,允许正常换行
|
|
3021
|
+
// 只有当提供了 onEnter 回调且没有建议窗口时才触发回调
|
|
3022
|
+
if (onEnter) {
|
|
3023
|
+
editor$1.addCommand(KeyCode.Enter, function () {
|
|
3024
|
+
onEnter(editor$1.getValue());
|
|
3025
|
+
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
3026
|
+
}
|
|
3027
|
+
// 内容变化时进行验证
|
|
3028
|
+
editor$1.onDidChangeModelContent(function () {
|
|
3029
|
+
var model = editor$1.getModel();
|
|
3030
|
+
if (model) {
|
|
3031
|
+
var content = model.getValue();
|
|
3032
|
+
var errors = validateYaml(content, schemas);
|
|
3033
|
+
var markers = errors.map(function (error) {
|
|
3034
|
+
return {
|
|
3035
|
+
message: error.message,
|
|
3036
|
+
severity: error.severity === 'error' ? MarkerSeverity.Error : error.severity === 'warning' ? MarkerSeverity.Warning : MarkerSeverity.Info,
|
|
3037
|
+
startLineNumber: error.startLineNumber,
|
|
3038
|
+
endLineNumber: error.endLineNumber,
|
|
3039
|
+
startColumn: error.startColumn,
|
|
3040
|
+
endColumn: error.endColumn
|
|
3041
|
+
};
|
|
3042
|
+
});
|
|
3043
|
+
editor.setModelMarkers(model, 'yaml', markers);
|
|
3044
|
+
}
|
|
3045
|
+
});
|
|
3046
|
+
editorDidMount == null || editorDidMount(editor$1);
|
|
3047
|
+
};
|
|
3048
|
+
useEffect(function () {
|
|
3049
|
+
// 注册 YAML 语言
|
|
3050
|
+
languages.register({
|
|
3051
|
+
id: YAML_LANG_ID,
|
|
3052
|
+
aliases: ['YAML', 'yaml'],
|
|
3053
|
+
extensions: ['.yaml', '.yml'],
|
|
3054
|
+
mimetypes: ['application/x-yaml', 'text/x-yaml']
|
|
3055
|
+
});
|
|
3056
|
+
// 设置语法高亮
|
|
3057
|
+
languages.setMonarchTokensProvider(YAML_LANG_ID, language$1);
|
|
3058
|
+
// 设置语言配置
|
|
3059
|
+
languages.setLanguageConfiguration(YAML_LANG_ID, languageConfiguration$1);
|
|
3060
|
+
return function () {
|
|
3061
|
+
autocompleteDisposeFun.current == null || autocompleteDisposeFun.current();
|
|
3062
|
+
};
|
|
3063
|
+
}, []);
|
|
3064
|
+
useEffect(function () {
|
|
3065
|
+
var editor = editorRef.current;
|
|
3066
|
+
if (!editor) return;
|
|
3067
|
+
// 清理之前的自动补全提供器
|
|
3068
|
+
if (autocompleteDisposeFun.current) {
|
|
3069
|
+
autocompleteDisposeFun.current();
|
|
3070
|
+
autocompleteDisposeFun.current = null;
|
|
3071
|
+
}
|
|
3072
|
+
// 如果启用自动补全,设置新的补全提供器
|
|
3073
|
+
if (enableAutocomplete) {
|
|
3074
|
+
var completionProvider = getYamlCompletionProvider(monaco, schemas);
|
|
3075
|
+
var filteringCompletionProvider = _extends({}, completionProvider, {
|
|
3076
|
+
provideCompletionItems: function provideCompletionItems(model, position, context, token) {
|
|
3077
|
+
var _editor$getModel;
|
|
3078
|
+
if (((_editor$getModel = editor.getModel()) == null ? void 0 : _editor$getModel.id) !== model.id) {
|
|
3079
|
+
return {
|
|
3080
|
+
suggestions: []
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
return completionProvider.provideCompletionItems(model, position, context, token);
|
|
3084
|
+
}
|
|
3085
|
+
});
|
|
3086
|
+
var _monaco$languages$reg = languages.registerCompletionItemProvider(YAML_LANG_ID, filteringCompletionProvider),
|
|
3087
|
+
dispose = _monaco$languages$reg.dispose;
|
|
3088
|
+
autocompleteDisposeFun.current = dispose;
|
|
3089
|
+
}
|
|
3090
|
+
// 处理占位符
|
|
3091
|
+
var model = editor.getModel();
|
|
3092
|
+
if (model) {
|
|
3093
|
+
model.deltaDecorations(model.getAllDecorations().map(function (d) {
|
|
3094
|
+
return d.id;
|
|
3095
|
+
}), []);
|
|
3096
|
+
}
|
|
3097
|
+
if (placeholder) {
|
|
3098
|
+
var placeholderDecorators = [{
|
|
3099
|
+
range: new Range(1, 1, 1, 1),
|
|
3100
|
+
options: {
|
|
3101
|
+
className: styles.placeholder,
|
|
3102
|
+
isWholeLine: true
|
|
3103
|
+
}
|
|
3104
|
+
}];
|
|
3105
|
+
var decorators = [];
|
|
3106
|
+
var checkDecorators = function checkDecorators() {
|
|
3107
|
+
var model = editor.getModel();
|
|
3108
|
+
if (!model) return;
|
|
3109
|
+
var newDecorators = model.getValueLength() === 0 ? placeholderDecorators : [];
|
|
3110
|
+
decorators = model.deltaDecorations(decorators, newDecorators);
|
|
3111
|
+
};
|
|
3112
|
+
checkDecorators();
|
|
3113
|
+
editor.onDidChangeModelContent(checkDecorators);
|
|
3114
|
+
}
|
|
3115
|
+
}, [enableAutocomplete, JSON.stringify(schemas), placeholder]);
|
|
3116
|
+
return React.createElement("div", {
|
|
3117
|
+
className: 'ant-input' + (size ? " " + SIZE_MAP$1[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$1 : '') + (readOnly ? " " + containerReadOnlyClassName$1 : '')
|
|
3118
|
+
}, React.createElement("div", {
|
|
3119
|
+
ref: containerRef
|
|
3120
|
+
}, React.createElement(MonacoEditor, {
|
|
3121
|
+
width: '100%',
|
|
3122
|
+
height: '100%',
|
|
3123
|
+
language: YAML_LANG_ID,
|
|
3124
|
+
theme: themeMap$1[theme],
|
|
3125
|
+
value: value,
|
|
3126
|
+
onChange: onChange,
|
|
3127
|
+
editorDidMount: handleEditorDidMount,
|
|
3128
|
+
options: {
|
|
3129
|
+
readOnly: readOnly,
|
|
3130
|
+
codeLens: false,
|
|
3131
|
+
contextmenu: false,
|
|
3132
|
+
fixedOverflowWidgets: true,
|
|
3133
|
+
folding: true,
|
|
3134
|
+
fontSize: 12,
|
|
3135
|
+
lineDecorationsWidth: 0,
|
|
3136
|
+
lineNumbers: 'on',
|
|
3137
|
+
minimap: {
|
|
3138
|
+
enabled: false
|
|
3139
|
+
},
|
|
3140
|
+
overviewRulerBorder: false,
|
|
3141
|
+
overviewRulerLanes: 0,
|
|
3142
|
+
padding: {
|
|
3143
|
+
top: SIZE_MAP$1[size].top,
|
|
3144
|
+
bottom: SIZE_MAP$1[size].bottom
|
|
3145
|
+
},
|
|
3146
|
+
renderLineHighlight: 'line',
|
|
3147
|
+
scrollbar: {
|
|
3148
|
+
vertical: 'auto',
|
|
3149
|
+
verticalScrollbarSize: 8,
|
|
3150
|
+
horizontal: 'auto',
|
|
3151
|
+
horizontalScrollbarSize: 8,
|
|
3152
|
+
alwaysConsumeMouseWheel: false
|
|
3153
|
+
},
|
|
3154
|
+
scrollBeyondLastLine: false,
|
|
3155
|
+
suggest: {
|
|
3156
|
+
showWords: true,
|
|
3157
|
+
filterGraceful: true,
|
|
3158
|
+
snippetsPreventQuickSuggestions: false,
|
|
3159
|
+
shareSuggestSelections: false
|
|
3160
|
+
},
|
|
3161
|
+
quickSuggestions: {
|
|
3162
|
+
other: true,
|
|
3163
|
+
comments: false,
|
|
3164
|
+
strings: true
|
|
3165
|
+
},
|
|
3166
|
+
quickSuggestionsDelay: 0,
|
|
3167
|
+
suggestFontSize: 12,
|
|
3168
|
+
wordWrap: 'on',
|
|
3169
|
+
automaticLayout: true,
|
|
3170
|
+
occurrencesHighlight: 'off'
|
|
3171
|
+
}
|
|
3172
|
+
})));
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
export { PromQLEditor as PromQLMonacoEditor, YamlEditor as YamlMonacoEditor };
|
|
2255
3176
|
//# sourceMappingURL=monaco-editor.esm.js.map
|