@fc-components/monaco-editor 0.1.27 → 0.3.1
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/expr/__tests__/__mocks__/monaco-editor.d.ts +28 -0
- package/dist/expr/completion/getCompletionProvider.d.ts +4 -0
- package/dist/expr/expr.d.ts +83 -0
- package/dist/expr/index.d.ts +3 -0
- package/dist/expr/parser/index.d.ts +3 -0
- package/dist/expr/parser/lexer.d.ts +27 -0
- package/dist/expr/parser/parser.d.ts +66 -0
- package/dist/expr/parser/types.d.ts +32 -0
- package/dist/expr/types.d.ts +17 -0
- package/dist/expr/validation.d.ts +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/monaco-editor.cjs.development.js +1986 -3
- 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 +1989 -7
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/situation.d.ts +2 -0
- package/package.json +6 -2
- package/src/expr/__tests__/__mocks__/monaco-editor.ts +34 -0
- package/src/expr/__tests__/expr.test.tsx +339 -0
- package/src/expr/completion/getCompletionProvider.ts +133 -0
- package/src/expr/expr.ts +229 -0
- package/src/expr/index.tsx +322 -0
- package/src/expr/parser/index.ts +3 -0
- package/src/expr/parser/lexer.ts +377 -0
- package/src/expr/parser/parser.ts +581 -0
- package/src/expr/parser/types.ts +77 -0
- package/src/expr/types.ts +17 -0
- package/src/expr/validation.ts +209 -0
- package/src/index.tsx +2 -0
- package/src/promql/__tests__/completions.test.ts +72 -0
- package/src/promql/__tests__/situation.test.ts +85 -0
- package/src/promql/completion/completions.ts +11 -2
- package/src/promql/completion/situation.ts +65 -1
- package/src/promql/promql.ts +3 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const MarkerSeverity: {
|
|
2
|
+
Warning: number;
|
|
3
|
+
Error: number;
|
|
4
|
+
Info: number;
|
|
5
|
+
Hint: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const editor: {
|
|
8
|
+
setModelMarkers: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const languages: {
|
|
11
|
+
CompletionItemKind: {
|
|
12
|
+
Keyword: number;
|
|
13
|
+
Function: number;
|
|
14
|
+
};
|
|
15
|
+
CompletionItemInsertTextRule: {
|
|
16
|
+
InsertAsSnippet: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const KeyMod: {
|
|
20
|
+
Shift: number;
|
|
21
|
+
CtrlCmd: number;
|
|
22
|
+
};
|
|
23
|
+
export declare const KeyCode: {
|
|
24
|
+
Enter: number;
|
|
25
|
+
KeyF: number;
|
|
26
|
+
};
|
|
27
|
+
export declare const Selection: () => void;
|
|
28
|
+
export declare const Range: () => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as monaco from 'monaco-editor';
|
|
2
|
+
export declare const getExprCompletionProvider: () => {
|
|
3
|
+
provideCompletionItems(model: monaco.editor.ITextModel, position: monaco.Position, _context: monaco.languages.CompletionContext, _token: monaco.CancellationToken): monaco.languages.ProviderResult<monaco.languages.CompletionList>;
|
|
4
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export declare const languageConfiguration: {
|
|
2
|
+
wordPattern: RegExp;
|
|
3
|
+
comments: {
|
|
4
|
+
lineComment: string;
|
|
5
|
+
blockComment: [string, string];
|
|
6
|
+
};
|
|
7
|
+
brackets: any;
|
|
8
|
+
autoClosingPairs: any;
|
|
9
|
+
surroundingPairs: any;
|
|
10
|
+
folding: {
|
|
11
|
+
offSide: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const language: {
|
|
15
|
+
defaultToken: string;
|
|
16
|
+
tokenPostfix: string;
|
|
17
|
+
brackets: {
|
|
18
|
+
open: string;
|
|
19
|
+
close: string;
|
|
20
|
+
token: string;
|
|
21
|
+
}[];
|
|
22
|
+
keywords: string[];
|
|
23
|
+
builtinFunctions: string[];
|
|
24
|
+
operators: string[];
|
|
25
|
+
escapes: RegExp;
|
|
26
|
+
digits: RegExp;
|
|
27
|
+
hexdigits: RegExp;
|
|
28
|
+
octdigits: RegExp;
|
|
29
|
+
bindigits: RegExp;
|
|
30
|
+
tokenizer: {
|
|
31
|
+
root: ((string | RegExp)[] | {
|
|
32
|
+
include: string;
|
|
33
|
+
} | (RegExp | {
|
|
34
|
+
cases: {
|
|
35
|
+
'@builtinFunctions': string;
|
|
36
|
+
'@default': string;
|
|
37
|
+
};
|
|
38
|
+
})[] | (RegExp | {
|
|
39
|
+
cases: {
|
|
40
|
+
'@keywords': string;
|
|
41
|
+
'@default': string;
|
|
42
|
+
};
|
|
43
|
+
})[])[];
|
|
44
|
+
whitespace: (string | RegExp)[][];
|
|
45
|
+
comments: ((string | RegExp)[] | (RegExp | {
|
|
46
|
+
token: string;
|
|
47
|
+
next: string;
|
|
48
|
+
})[])[];
|
|
49
|
+
comment: ((string | RegExp)[] | (RegExp | {
|
|
50
|
+
token: string;
|
|
51
|
+
next: string;
|
|
52
|
+
})[])[];
|
|
53
|
+
numbers: (string | RegExp)[][];
|
|
54
|
+
strings: (RegExp | {
|
|
55
|
+
token: string;
|
|
56
|
+
next: string;
|
|
57
|
+
})[][];
|
|
58
|
+
string_double: ((string | RegExp)[] | (RegExp | {
|
|
59
|
+
token: string;
|
|
60
|
+
next: string;
|
|
61
|
+
})[])[];
|
|
62
|
+
string_single: ((string | RegExp)[] | (RegExp | {
|
|
63
|
+
token: string;
|
|
64
|
+
next: string;
|
|
65
|
+
})[])[];
|
|
66
|
+
string_backtick: ((string | RegExp)[] | (RegExp | {
|
|
67
|
+
token: string;
|
|
68
|
+
next: string;
|
|
69
|
+
})[])[];
|
|
70
|
+
bytes: (RegExp | {
|
|
71
|
+
token: string;
|
|
72
|
+
next: string;
|
|
73
|
+
})[][];
|
|
74
|
+
bytes_double: ((string | RegExp)[] | (RegExp | {
|
|
75
|
+
token: string;
|
|
76
|
+
next: string;
|
|
77
|
+
})[])[];
|
|
78
|
+
bytes_single: ((string | RegExp)[] | (RegExp | {
|
|
79
|
+
token: string;
|
|
80
|
+
next: string;
|
|
81
|
+
})[])[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expr-lang lexer/tokenizer
|
|
3
|
+
* Handles: identifiers, numbers, strings, bytes literals, operators, comments
|
|
4
|
+
*/
|
|
5
|
+
import { Token } from './types';
|
|
6
|
+
export declare class Lexer {
|
|
7
|
+
private input;
|
|
8
|
+
private pos;
|
|
9
|
+
private line;
|
|
10
|
+
private column;
|
|
11
|
+
private startLine;
|
|
12
|
+
private startColumn;
|
|
13
|
+
reset(input: string): void;
|
|
14
|
+
next(): Token;
|
|
15
|
+
private skipWhitespace;
|
|
16
|
+
private skipComments;
|
|
17
|
+
private readString;
|
|
18
|
+
private readBacktickString;
|
|
19
|
+
private readByteLiteral;
|
|
20
|
+
private readNumber;
|
|
21
|
+
private readIdentOrKeyword;
|
|
22
|
+
private readOperatorOrBracket;
|
|
23
|
+
private isDigit;
|
|
24
|
+
private isIdentStart;
|
|
25
|
+
private isIdentPart;
|
|
26
|
+
private makeToken;
|
|
27
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expr-lang recursive descent parser
|
|
3
|
+
* Ported from Go's expr-lang parser with precedence climbing algorithm
|
|
4
|
+
*/
|
|
5
|
+
import { ParseError } from './types';
|
|
6
|
+
export declare class ExprParser {
|
|
7
|
+
private lexer;
|
|
8
|
+
private current;
|
|
9
|
+
private errors;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Parse an expr-lang expression and return any syntax errors.
|
|
13
|
+
* Returns empty array if the expression is valid.
|
|
14
|
+
*/
|
|
15
|
+
parse(input: string): ParseError[];
|
|
16
|
+
private advance;
|
|
17
|
+
private curKind;
|
|
18
|
+
private curVal;
|
|
19
|
+
private expect;
|
|
20
|
+
private error;
|
|
21
|
+
private errorAt;
|
|
22
|
+
/**
|
|
23
|
+
* parseSequenceExpression parses multiple expressions separated by semicolons.
|
|
24
|
+
*/
|
|
25
|
+
private parseSequenceExpression;
|
|
26
|
+
/**
|
|
27
|
+
* parseExpression uses precedence climbing to parse binary expressions.
|
|
28
|
+
*/
|
|
29
|
+
private parseExpression;
|
|
30
|
+
/**
|
|
31
|
+
* parsePrimary handles unary operators, parentheses, and the #/. pointer prefix.
|
|
32
|
+
*/
|
|
33
|
+
private parsePrimary;
|
|
34
|
+
/**
|
|
35
|
+
* parseSecondary handles identifiers, literals, arrays, and maps.
|
|
36
|
+
*/
|
|
37
|
+
private parseSecondary;
|
|
38
|
+
/**
|
|
39
|
+
* parsePostfixExpression handles .member, ?.member, [index], [from:to], and calls after the primary.
|
|
40
|
+
*/
|
|
41
|
+
private parsePostfixExpression;
|
|
42
|
+
/**
|
|
43
|
+
* parseVariableDeclaration parses "let name = value; rest"
|
|
44
|
+
*/
|
|
45
|
+
private parseVariableDeclaration;
|
|
46
|
+
/**
|
|
47
|
+
* parseConditionalIf parses "if expr { expr1 } else { expr2 }" or "if expr { expr1 } else if ..."
|
|
48
|
+
*/
|
|
49
|
+
private parseConditionalIf;
|
|
50
|
+
/**
|
|
51
|
+
* parseConditional parses "expr ? expr1 : expr2" or "expr ?: expr2"
|
|
52
|
+
*/
|
|
53
|
+
private parseConditional;
|
|
54
|
+
/**
|
|
55
|
+
* parseArguments parses function call arguments: (arg1, arg2, ...)
|
|
56
|
+
*/
|
|
57
|
+
private parseArguments;
|
|
58
|
+
/**
|
|
59
|
+
* parseArrayExpression parses "[elem1, elem2, ...]"
|
|
60
|
+
*/
|
|
61
|
+
private parseArrayExpression;
|
|
62
|
+
/**
|
|
63
|
+
* parseMapExpression parses "{key: value, ...}"
|
|
64
|
+
*/
|
|
65
|
+
private parseMapExpression;
|
|
66
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expr-lang token types and AST definitions
|
|
3
|
+
*/
|
|
4
|
+
export declare enum TokenKind {
|
|
5
|
+
Identifier = "Identifier",
|
|
6
|
+
Number = "Number",
|
|
7
|
+
String = "String",
|
|
8
|
+
Operator = "Operator",
|
|
9
|
+
Bracket = "Bracket",
|
|
10
|
+
EOF = "EOF"
|
|
11
|
+
}
|
|
12
|
+
export interface Token {
|
|
13
|
+
kind: TokenKind;
|
|
14
|
+
value: string;
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ParseError {
|
|
21
|
+
message: string;
|
|
22
|
+
startLine: number;
|
|
23
|
+
startColumn: number;
|
|
24
|
+
endLine: number;
|
|
25
|
+
endColumn: number;
|
|
26
|
+
}
|
|
27
|
+
export declare const EOF_TOKEN: Token;
|
|
28
|
+
export declare const OPERATOR_PRECEDENCE: Record<string, number>;
|
|
29
|
+
export declare const UNARY_OPERATORS: Set<string>;
|
|
30
|
+
export declare const RIGHT_ASSOCIATIVE: Set<string>;
|
|
31
|
+
export declare const COMPARISON_OPERATORS: Set<string>;
|
|
32
|
+
export declare const KEYWORDS: Set<string>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ExprEditorProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
maxHeight?: number | string;
|
|
4
|
+
fontSize?: number;
|
|
5
|
+
size?: 'small' | 'middle' | 'large';
|
|
6
|
+
theme?: 'light' | 'dark';
|
|
7
|
+
value?: string;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
enableAutocomplete?: boolean;
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
onChange?: (value: string) => void;
|
|
13
|
+
onEnter?: (value: string) => void;
|
|
14
|
+
onBlur?: (value: string) => void;
|
|
15
|
+
onFocus?: (value: string) => void;
|
|
16
|
+
editorDidMount?: (editor: any) => void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as monaco from 'monaco-editor';
|
|
2
|
+
/**
|
|
3
|
+
* Validate an expr-lang expression and return Monaco editor markers.
|
|
4
|
+
* Uses the recursive descent parser for syntax errors,
|
|
5
|
+
* plus regex-based checks for structural issues like unbalanced quotes/brackets.
|
|
6
|
+
*/
|
|
7
|
+
export declare const validateExpr: (expr: string) => Omit<monaco.editor.IMarker, 'owner' | 'resource'>[];
|
|
8
|
+
/**
|
|
9
|
+
* Validate an expr-lang expression and return a plain array of human-readable error messages.
|
|
10
|
+
* Returns an empty array if the expression is valid.
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkExpr(expr: string): string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import promql from './promql';
|
|
2
2
|
import yaml from './yaml';
|
|
3
3
|
import sql from './sql';
|
|
4
|
+
import expr from './expr';
|
|
4
5
|
export { promql as PromQLMonacoEditor };
|
|
5
6
|
export { yaml as YamlMonacoEditor };
|
|
6
7
|
export { sql as SqlMonacoEditor };
|
|
8
|
+
export { expr as ExprMonacoEditor };
|