@fc-components/monaco-editor 0.2.1 → 0.3.2

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.
@@ -12,6 +12,7 @@ var monacoPromql = require('monaco-promql');
12
12
  var lezerMetricsql = require('@fc-components/lezer-metricsql');
13
13
  var uuid = require('uuid');
14
14
  var css = require('@emotion/css');
15
+ var sqlFormatter = require('sql-formatter');
15
16
 
16
17
  function _arrayLikeToArray(r, a) {
17
18
  (null == a || a > r.length) && (a = r.length);
@@ -3665,7 +3666,19 @@ var getSqlCompletionProvider = function getSqlCompletionProvider() {
3665
3666
  };
3666
3667
  };
3667
3668
 
3668
- var _templateObject$2, _templateObject2$2;
3669
+ function formatSql(sql) {
3670
+ try {
3671
+ return sqlFormatter.format(sql, {
3672
+ tabWidth: 2,
3673
+ keywordCase: 'upper'
3674
+ });
3675
+ } catch (_unused) {
3676
+ // If formatting fails, return the original SQL
3677
+ return sql;
3678
+ }
3679
+ }
3680
+
3681
+ var _templateObject$2, _templateObject2$2, _templateObject3;
3669
3682
  var SQL_LANG_ID = 'sql';
3670
3683
  var SIZE_MAP$2 = {
3671
3684
  small: {
@@ -3693,7 +3706,8 @@ var themeMap$2 = {
3693
3706
  };
3694
3707
  var containerDisabledClassName$2 = /*#__PURE__*/css.css(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
3695
3708
  var containerReadOnlyClassName$2 = /*#__PURE__*/css.css(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
3696
- function SqlEditor(props) {
3709
+ var formatBtnClassName = /*#__PURE__*/css.css(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 4px;\n right: 4px;\n z-index: 10;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n padding: 0;\n border: none;\n background: transparent;\n border-radius: 4px;\n cursor: pointer;\n color: inherit;\n opacity: 0.6;\n transition: opacity 0.15s;\n\n &:hover {\n opacity: 1;\n background: var(--format-btn-hover-bg, rgba(128, 128, 128, 0.15));\n }\n"])));
3710
+ var SqlEditor = /*#__PURE__*/React.forwardRef(function (props, ref) {
3697
3711
  var id = uuid.v4();
3698
3712
  var className = props.className,
3699
3713
  maxHeight = props.maxHeight,
@@ -3705,6 +3719,8 @@ function SqlEditor(props) {
3705
3719
  _props$value = props.value,
3706
3720
  value = _props$value === void 0 ? '' : _props$value,
3707
3721
  placeholder = props.placeholder,
3722
+ _props$enableFormat = props.enableFormat,
3723
+ enableFormat = _props$enableFormat === void 0 ? false : _props$enableFormat,
3708
3724
  _props$enableAutocomp = props.enableAutocomplete,
3709
3725
  enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
3710
3726
  _props$readOnly = props.readOnly,
@@ -3715,7 +3731,8 @@ function SqlEditor(props) {
3715
3731
  onEnter = props.onEnter,
3716
3732
  onBlur = props.onBlur,
3717
3733
  onFocus = props.onFocus,
3718
- editorDidMount = props.editorDidMount;
3734
+ editorDidMount = props.editorDidMount,
3735
+ renderFormatButton = props.renderFormatButton;
3719
3736
  var containerRef = React.useRef(null);
3720
3737
  var editorRef = React.useRef(null);
3721
3738
  var modelRef = React.useRef(null);
@@ -3829,6 +3846,18 @@ function SqlEditor(props) {
3829
3846
  }, '!suggestWidgetVisible && isEditorFocused' + id);
3830
3847
  editorDidMount == null || editorDidMount(editor);
3831
3848
  };
3849
+ var handleFormat = React.useCallback(function () {
3850
+ var editor = editorRef.current;
3851
+ if (!editor) return;
3852
+ var currentValue = editor.getValue();
3853
+ var formatted = formatSql(currentValue);
3854
+ editor.setValue(formatted);
3855
+ }, []);
3856
+ React.useImperativeHandle(ref, function () {
3857
+ return {
3858
+ format: handleFormat
3859
+ };
3860
+ });
3832
3861
  var themeValue = themeMap$2[theme];
3833
3862
  return React__default.createElement("div", {
3834
3863
  className: 'ant-input' + (size ? " " + SIZE_MAP$2[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$2 : '') + (readOnly ? " " + containerReadOnlyClassName$2 : '') + (className ? " " + className : ''),
@@ -3836,6 +3865,7 @@ function SqlEditor(props) {
3836
3865
  display: 'block',
3837
3866
  resize: 'vertical',
3838
3867
  overflow: 'auto',
3868
+ position: 'relative',
3839
3869
  minHeight: SIZE_MAP$2[size].minHeight,
3840
3870
  maxHeight: maxHeight
3841
3871
  }
@@ -3885,9 +3915,1963 @@ function SqlEditor(props) {
3885
3915
  alwaysConsumeMouseWheel: false
3886
3916
  }
3887
3917
  }
3918
+ })), enableFormat && (renderFormatButton ? renderFormatButton(handleFormat) : React__default.createElement("button", {
3919
+ onClick: handleFormat,
3920
+ className: formatBtnClassName,
3921
+ title: 'Format SQL',
3922
+ style: {
3923
+ '--format-btn-hover-bg': theme === 'dark' ? 'rgba(255,255,255,0.2)' : 'rgba(128,128,128,0.15)'
3924
+ }
3925
+ }, React__default.createElement("svg", {
3926
+ xmlns: 'http://www.w3.org/2000/svg',
3927
+ width: '16',
3928
+ height: '16',
3929
+ viewBox: '0 0 24 24',
3930
+ fill: 'none',
3931
+ stroke: 'currentColor',
3932
+ strokeWidth: '2',
3933
+ strokeLinecap: 'round',
3934
+ strokeLinejoin: 'round'
3935
+ }, React__default.createElement("path", {
3936
+ d: 'm21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72'
3937
+ }), React__default.createElement("path", {
3938
+ d: 'm14 7 3 3'
3939
+ }), React__default.createElement("path", {
3940
+ d: 'M5 6v4'
3941
+ }), React__default.createElement("path", {
3942
+ d: 'M19 14v4'
3943
+ }), React__default.createElement("path", {
3944
+ d: 'M10 2v2'
3945
+ }), React__default.createElement("path", {
3946
+ d: 'M7 8H3'
3947
+ }), React__default.createElement("path", {
3948
+ d: 'M21 16h-4'
3949
+ }), React__default.createElement("path", {
3950
+ d: 'M11 3H9'
3951
+ })))));
3952
+ });
3953
+
3954
+ var languageConfiguration$3 = {
3955
+ wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
3956
+ comments: {
3957
+ lineComment: '//',
3958
+ blockComment: ['/*', '*/']
3959
+ },
3960
+ brackets: [['{', '}'], ['[', ']'], ['(', ')']],
3961
+ autoClosingPairs: [{
3962
+ open: '{',
3963
+ close: '}'
3964
+ }, {
3965
+ open: '[',
3966
+ close: ']'
3967
+ }, {
3968
+ open: '(',
3969
+ close: ')'
3970
+ }, {
3971
+ open: '"',
3972
+ close: '"'
3973
+ }, {
3974
+ open: "'",
3975
+ close: "'"
3976
+ }, {
3977
+ open: '`',
3978
+ close: '`'
3979
+ }],
3980
+ surroundingPairs: [{
3981
+ open: '{',
3982
+ close: '}'
3983
+ }, {
3984
+ open: '[',
3985
+ close: ']'
3986
+ }, {
3987
+ open: '(',
3988
+ close: ')'
3989
+ }, {
3990
+ open: '"',
3991
+ close: '"'
3992
+ }, {
3993
+ open: "'",
3994
+ close: "'"
3995
+ }, {
3996
+ open: '`',
3997
+ close: '`'
3998
+ }],
3999
+ folding: {
4000
+ offSide: false
4001
+ }
4002
+ };
4003
+ // Expr-lang keywords
4004
+ var keywords$3 = ['let', 'true', 'false', 'nil', 'in', 'not', 'and', 'or', 'if', 'else'];
4005
+ // Expr-lang built-in functions
4006
+ var stringFunctions = ['trim', 'trimPrefix', 'trimSuffix', 'upper', 'lower', 'split', 'splitAfter', 'replace', 'repeat', 'indexOf', 'lastIndexOf', 'hasPrefix', 'hasSuffix', 'contains', 'startsWith', 'endsWith'];
4007
+ var dateFunctions = ['now', 'duration', 'date', 'timezone'];
4008
+ var numberFunctions = ['max', 'min', 'abs', 'ceil', 'floor', 'round'];
4009
+ var arrayFunctions = ['all', 'any', 'one', 'none', 'map', 'filter', 'find', 'findIndex', 'findLast', 'findLastIndex', 'groupBy', 'count', 'concat', 'flatten', 'uniq', 'join', 'reduce', 'sum', 'mean', 'median', 'first', 'last', 'take', 'reverse', 'sort', 'sortBy'];
4010
+ var mapFunctions = ['keys', 'values'];
4011
+ var typeConversionFunctions = ['type', 'int', 'float', 'string', 'toJSON', 'fromJSON', 'toBase64', 'fromBase64', 'toPairs', 'fromPairs'];
4012
+ var miscFunctions = ['len', 'get'];
4013
+ var bitwiseFunctions = ['bitand', 'bitor', 'bitxor', 'bitnand', 'bitnot', 'bitshl', 'bitshr', 'bitushr'];
4014
+ var builtinFunctions = /*#__PURE__*/[].concat(stringFunctions, dateFunctions, numberFunctions, arrayFunctions, mapFunctions, typeConversionFunctions, miscFunctions, bitwiseFunctions);
4015
+ var language$3 = {
4016
+ defaultToken: '',
4017
+ tokenPostfix: '.expr',
4018
+ brackets: [{
4019
+ open: '(',
4020
+ close: ')',
4021
+ token: 'delimiter.parenthesis'
4022
+ }, {
4023
+ open: '{',
4024
+ close: '}',
4025
+ token: 'delimiter.curly'
4026
+ }, {
4027
+ open: '[',
4028
+ close: ']',
4029
+ token: 'delimiter.square'
4030
+ }],
4031
+ keywords: keywords$3,
4032
+ builtinFunctions: builtinFunctions,
4033
+ operators: ['+', '-', '*', '/', '%', '^', '**', '==', '!=', '<', '>', '<=', '>=', '!', '&&', '||', '?:', '??', '.', '?.', 'in', 'matches', '..', '|'],
4034
+ escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
4035
+ digits: /\d+(_+\d+)*/,
4036
+ hexdigits: /[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
4037
+ octdigits: /[0-7]+(_+[0-7]+)*/,
4038
+ bindigits: /[01]+(_+[01]+)*/,
4039
+ tokenizer: {
4040
+ root: [{
4041
+ include: '@whitespace'
4042
+ }, {
4043
+ include: '@comments'
4044
+ }, {
4045
+ include: '@numbers'
4046
+ }, {
4047
+ include: '@strings'
4048
+ }, {
4049
+ include: '@bytes'
4050
+ },
4051
+ // Function calls: identifier followed by '('
4052
+ [/[a-zA-Z_]\w*(?=\s*\()/, {
4053
+ cases: {
4054
+ '@builtinFunctions': 'keyword.function',
4055
+ '@default': 'identifier.function'
4056
+ }
4057
+ }],
4058
+ // Keywords and identifiers
4059
+ [/[a-zA-Z_]\w*/, {
4060
+ cases: {
4061
+ '@keywords': 'keyword',
4062
+ '@default': 'identifier'
4063
+ }
4064
+ }],
4065
+ // Operators
4066
+ [/[?][?:]/, 'operator'], [/[?][.]/, 'operator'], [/[.]{2}/, 'operator'], [/[*]{2}/, 'operator'], [/[|]/, 'operator'], [/[+\-*/%^]/, 'operator'], [/==|!=|<=|>=|<|>/, 'operator'], [/!|&&|\|\|/, 'operator'], [/[=]/, 'operator'], [/[.~]/, 'operator'],
4067
+ // Delimiters
4068
+ [/[,;]/, 'delimiter'], [/[{}()\[\]]/, '@brackets']],
4069
+ whitespace: [[/[ \t\r\n]+/, 'white']],
4070
+ comments: [[/\/\/.*$/, 'comment'], [/\/\*/, {
4071
+ token: 'comment.quote',
4072
+ next: '@comment'
4073
+ }]],
4074
+ comment: [[/[^*/]+/, 'comment'], [/\*\//, {
4075
+ token: 'comment.quote',
4076
+ next: '@pop'
4077
+ }], [/./, 'comment']],
4078
+ numbers: [[/0[xX]@hexdigits/, 'number.hex'], [/0[oO]@octdigits/, 'number.octal'], [/0[bB]@bindigits/, 'number.binary'], [/(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?/, 'number']],
4079
+ strings: [[/"/, {
4080
+ token: 'string.double',
4081
+ next: '@string_double'
4082
+ }], [/'/, {
4083
+ token: 'string',
4084
+ next: '@string_single'
4085
+ }], [/`/, {
4086
+ token: 'string.backtick',
4087
+ next: '@string_backtick'
4088
+ }]],
4089
+ string_double: [[/[^"\\]+/, 'string.double'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/"/, {
4090
+ token: 'string.double',
4091
+ next: '@pop'
4092
+ }]],
4093
+ string_single: [[/[^'\\]+/, 'string'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/'/, {
4094
+ token: 'string',
4095
+ next: '@pop'
4096
+ }]],
4097
+ string_backtick: [[/[^`]+/, 'string.backtick'], [/`/, {
4098
+ token: 'string.backtick',
4099
+ next: '@pop'
4100
+ }]],
4101
+ bytes: [[/[bB]"/, {
4102
+ token: 'string.bytes',
4103
+ next: '@bytes_double'
4104
+ }], [/[bB]'/, {
4105
+ token: 'string.bytes',
4106
+ next: '@bytes_single'
4107
+ }]],
4108
+ bytes_double: [[/[^"\\]+/, 'string.bytes'], [/\\(?:[abfnrtv\\"]|x[0-9A-Fa-f]{2}|[0-7]{3})/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/"/, {
4109
+ token: 'string.bytes',
4110
+ next: '@pop'
4111
+ }]],
4112
+ bytes_single: [[/[^'\\]+/, 'string.bytes'], [/\\(?:[abfnrtv\\']|x[0-9A-Fa-f]{2}|[0-7]{3})/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/'/, {
4113
+ token: 'string.bytes',
4114
+ next: '@pop'
4115
+ }]]
4116
+ }
4117
+ };
4118
+
4119
+ var EXPR_KEYWORDS = ['let', 'true', 'false', 'nil', 'in', 'not', 'and', 'or', 'if', 'else'];
4120
+ var EXPR_FUNCTIONS = [
4121
+ // String functions
4122
+ {
4123
+ name: 'trim',
4124
+ signature: 'trim(str[, chars])',
4125
+ description: 'Removes white spaces from both ends of a string',
4126
+ category: 'string'
4127
+ }, {
4128
+ name: 'trimPrefix',
4129
+ signature: 'trimPrefix(str, prefix)',
4130
+ description: 'Removes the specified prefix from the string',
4131
+ category: 'string'
4132
+ }, {
4133
+ name: 'trimSuffix',
4134
+ signature: 'trimSuffix(str, suffix)',
4135
+ description: 'Removes the specified suffix from the string',
4136
+ category: 'string'
4137
+ }, {
4138
+ name: 'upper',
4139
+ signature: 'upper(str)',
4140
+ description: 'Converts all characters to uppercase',
4141
+ category: 'string'
4142
+ }, {
4143
+ name: 'lower',
4144
+ signature: 'lower(str)',
4145
+ description: 'Converts all characters to lowercase',
4146
+ category: 'string'
4147
+ }, {
4148
+ name: 'split',
4149
+ signature: 'split(str, delimiter[, n])',
4150
+ description: 'Splits a string at each instance of the delimiter',
4151
+ category: 'string'
4152
+ }, {
4153
+ name: 'splitAfter',
4154
+ signature: 'splitAfter(str, delimiter[, n])',
4155
+ description: 'Splits a string after each instance of the delimiter',
4156
+ category: 'string'
4157
+ }, {
4158
+ name: 'replace',
4159
+ signature: 'replace(str, old, new)',
4160
+ description: 'Replaces all occurrences of old with new',
4161
+ category: 'string'
4162
+ }, {
4163
+ name: 'repeat',
4164
+ signature: 'repeat(str, n)',
4165
+ description: 'Repeats a string n times',
4166
+ category: 'string'
4167
+ }, {
4168
+ name: 'indexOf',
4169
+ signature: 'indexOf(str, substring)',
4170
+ description: 'Returns the index of the first occurrence of substring',
4171
+ category: 'string'
4172
+ }, {
4173
+ name: 'lastIndexOf',
4174
+ signature: 'lastIndexOf(str, substring)',
4175
+ description: 'Returns the index of the last occurrence of substring',
4176
+ category: 'string'
4177
+ }, {
4178
+ name: 'hasPrefix',
4179
+ signature: 'hasPrefix(str, prefix)',
4180
+ description: 'Returns true if string starts with the given prefix',
4181
+ category: 'string'
4182
+ }, {
4183
+ name: 'hasSuffix',
4184
+ signature: 'hasSuffix(str, suffix)',
4185
+ description: 'Returns true if string ends with the given suffix',
4186
+ category: 'string'
4187
+ }, {
4188
+ name: 'contains',
4189
+ signature: 'contains(str, substr)',
4190
+ description: 'Returns true if string contains the given substring',
4191
+ category: 'string'
4192
+ }, {
4193
+ name: 'startsWith',
4194
+ signature: 'startsWith(str, prefix)',
4195
+ description: 'Returns true if string starts with the given prefix',
4196
+ category: 'string'
4197
+ }, {
4198
+ name: 'endsWith',
4199
+ signature: 'endsWith(str, suffix)',
4200
+ description: 'Returns true if string ends with the given suffix',
4201
+ category: 'string'
4202
+ },
4203
+ // Date functions
4204
+ {
4205
+ name: 'now',
4206
+ signature: 'now()',
4207
+ description: 'Returns the current date as a time.Time value',
4208
+ category: 'date'
4209
+ }, {
4210
+ name: 'duration',
4211
+ signature: 'duration(str)',
4212
+ description: 'Returns time.Duration value of the given string',
4213
+ category: 'date'
4214
+ }, {
4215
+ name: 'date',
4216
+ signature: 'date(str[, format[, timezone]])',
4217
+ description: 'Converts the given string into a date representation',
4218
+ category: 'date'
4219
+ }, {
4220
+ name: 'timezone',
4221
+ signature: 'timezone(str)',
4222
+ description: 'Returns the timezone of the given string',
4223
+ category: 'date'
4224
+ },
4225
+ // Number functions
4226
+ {
4227
+ name: 'max',
4228
+ signature: 'max(n1, n2)',
4229
+ description: 'Returns the maximum of two numbers',
4230
+ category: 'number'
4231
+ }, {
4232
+ name: 'min',
4233
+ signature: 'min(n1, n2)',
4234
+ description: 'Returns the minimum of two numbers',
4235
+ category: 'number'
4236
+ }, {
4237
+ name: 'abs',
4238
+ signature: 'abs(n)',
4239
+ description: 'Returns the absolute value of a number',
4240
+ category: 'number'
4241
+ }, {
4242
+ name: 'ceil',
4243
+ signature: 'ceil(n)',
4244
+ description: 'Returns the least integer value greater than or equal to x',
4245
+ category: 'number'
4246
+ }, {
4247
+ name: 'floor',
4248
+ signature: 'floor(n)',
4249
+ description: 'Returns the greatest integer value less than or equal to x',
4250
+ category: 'number'
4251
+ }, {
4252
+ name: 'round',
4253
+ signature: 'round(n)',
4254
+ description: 'Returns the nearest integer, rounding half away from zero',
4255
+ category: 'number'
4256
+ },
4257
+ // Array functions
4258
+ {
4259
+ name: 'all',
4260
+ signature: 'all(array, predicate)',
4261
+ description: 'Returns true if all elements satisfy the predicate',
4262
+ category: 'array'
4263
+ }, {
4264
+ name: 'any',
4265
+ signature: 'any(array, predicate)',
4266
+ description: 'Returns true if any elements satisfy the predicate',
4267
+ category: 'array'
4268
+ }, {
4269
+ name: 'one',
4270
+ signature: 'one(array, predicate)',
4271
+ description: 'Returns true if exactly one element satisfies the predicate',
4272
+ category: 'array'
4273
+ }, {
4274
+ name: 'none',
4275
+ signature: 'none(array, predicate)',
4276
+ description: 'Returns true if no elements satisfy the predicate',
4277
+ category: 'array'
4278
+ }, {
4279
+ name: 'map',
4280
+ signature: 'map(array, predicate)',
4281
+ description: 'Returns new array by applying the predicate to each element',
4282
+ category: 'array'
4283
+ }, {
4284
+ name: 'filter',
4285
+ signature: 'filter(array, predicate)',
4286
+ description: 'Returns new array by filtering elements by predicate',
4287
+ category: 'array'
4288
+ }, {
4289
+ name: 'find',
4290
+ signature: 'find(array, predicate)',
4291
+ description: 'Finds the first element satisfying the predicate',
4292
+ category: 'array'
4293
+ }, {
4294
+ name: 'findIndex',
4295
+ signature: 'findIndex(array, predicate)',
4296
+ description: 'Finds the index of the first element satisfying the predicate',
4297
+ category: 'array'
4298
+ }, {
4299
+ name: 'findLast',
4300
+ signature: 'findLast(array, predicate)',
4301
+ description: 'Finds the last element satisfying the predicate',
4302
+ category: 'array'
4303
+ }, {
4304
+ name: 'findLastIndex',
4305
+ signature: 'findLastIndex(array, predicate)',
4306
+ description: 'Finds the index of the last element satisfying the predicate',
4307
+ category: 'array'
4308
+ }, {
4309
+ name: 'groupBy',
4310
+ signature: 'groupBy(array, predicate)',
4311
+ description: 'Groups elements by the result of the predicate',
4312
+ category: 'array'
4313
+ }, {
4314
+ name: 'count',
4315
+ signature: 'count(array[, predicate])',
4316
+ description: 'Returns the number of elements satisfying the predicate',
4317
+ category: 'array'
4318
+ }, {
4319
+ name: 'concat',
4320
+ signature: 'concat(array1, array2[, ...])',
4321
+ description: 'Concatenates two or more arrays',
4322
+ category: 'array'
4323
+ }, {
4324
+ name: 'flatten',
4325
+ signature: 'flatten(array)',
4326
+ description: 'Flattens an array into one-dimensional array',
4327
+ category: 'array'
4328
+ }, {
4329
+ name: 'uniq',
4330
+ signature: 'uniq(array)',
4331
+ description: 'Removes duplicates from an array',
4332
+ category: 'array'
4333
+ }, {
4334
+ name: 'join',
4335
+ signature: 'join(array[, delimiter])',
4336
+ description: 'Joins an array of strings into a single string',
4337
+ category: 'array'
4338
+ }, {
4339
+ name: 'reduce',
4340
+ signature: 'reduce(array, predicate[, initial])',
4341
+ description: 'Reduces an array to a single value',
4342
+ category: 'array'
4343
+ }, {
4344
+ name: 'sum',
4345
+ signature: 'sum(array[, predicate])',
4346
+ description: 'Returns the sum of all numbers in an array',
4347
+ category: 'array'
4348
+ }, {
4349
+ name: 'mean',
4350
+ signature: 'mean(array)',
4351
+ description: 'Returns the average of all numbers in an array',
4352
+ category: 'array'
4353
+ }, {
4354
+ name: 'median',
4355
+ signature: 'median(array)',
4356
+ description: 'Returns the median of all numbers in an array',
4357
+ category: 'array'
4358
+ }, {
4359
+ name: 'first',
4360
+ signature: 'first(array)',
4361
+ description: 'Returns the first element from an array',
4362
+ category: 'array'
4363
+ }, {
4364
+ name: 'last',
4365
+ signature: 'last(array)',
4366
+ description: 'Returns the last element from an array',
4367
+ category: 'array'
4368
+ }, {
4369
+ name: 'take',
4370
+ signature: 'take(array, n)',
4371
+ description: 'Returns the first n elements from an array',
4372
+ category: 'array'
4373
+ }, {
4374
+ name: 'reverse',
4375
+ signature: 'reverse(array)',
4376
+ description: 'Returns a new reversed copy of the array',
4377
+ category: 'array'
4378
+ }, {
4379
+ name: 'sort',
4380
+ signature: 'sort(array[, order])',
4381
+ description: 'Sorts an array in ascending or descending order',
4382
+ category: 'array'
4383
+ }, {
4384
+ name: 'sortBy',
4385
+ signature: 'sortBy(array[, predicate, order])',
4386
+ description: 'Sorts an array by the result of the predicate',
4387
+ category: 'array'
4388
+ },
4389
+ // Map functions
4390
+ {
4391
+ name: 'keys',
4392
+ signature: 'keys(map)',
4393
+ description: 'Returns an array containing the keys of the map',
4394
+ category: 'map'
4395
+ }, {
4396
+ name: 'values',
4397
+ signature: 'values(map)',
4398
+ description: 'Returns an array containing the values of the map',
4399
+ category: 'map'
4400
+ },
4401
+ // Type conversion functions
4402
+ {
4403
+ name: 'type',
4404
+ signature: 'type(v)',
4405
+ description: 'Returns the type of the given value',
4406
+ category: 'conversion'
4407
+ }, {
4408
+ name: 'int',
4409
+ signature: 'int(v)',
4410
+ description: 'Returns the integer value of a number or string',
4411
+ category: 'conversion'
4412
+ }, {
4413
+ name: 'float',
4414
+ signature: 'float(v)',
4415
+ description: 'Returns the float value of a number or string',
4416
+ category: 'conversion'
4417
+ }, {
4418
+ name: 'string',
4419
+ signature: 'string(v)',
4420
+ description: 'Converts a value to its string representation',
4421
+ category: 'conversion'
4422
+ }, {
4423
+ name: 'toJSON',
4424
+ signature: 'toJSON(v)',
4425
+ description: 'Converts a value to JSON string representation',
4426
+ category: 'conversion'
4427
+ }, {
4428
+ name: 'fromJSON',
4429
+ signature: 'fromJSON(v)',
4430
+ description: 'Parses a JSON string to a value',
4431
+ category: 'conversion'
4432
+ }, {
4433
+ name: 'toBase64',
4434
+ signature: 'toBase64(v)',
4435
+ description: 'Encodes a string into Base64 format',
4436
+ category: 'conversion'
4437
+ }, {
4438
+ name: 'fromBase64',
4439
+ signature: 'fromBase64(v)',
4440
+ description: 'Decodes a Base64 encoded string',
4441
+ category: 'conversion'
4442
+ }, {
4443
+ name: 'toPairs',
4444
+ signature: 'toPairs(map)',
4445
+ description: 'Converts a map to an array of key-value pairs',
4446
+ category: 'conversion'
4447
+ }, {
4448
+ name: 'fromPairs',
4449
+ signature: 'fromPairs(array)',
4450
+ description: 'Converts an array of key-value pairs to a map',
4451
+ category: 'conversion'
4452
+ },
4453
+ // Miscellaneous functions
4454
+ {
4455
+ name: 'len',
4456
+ signature: 'len(v)',
4457
+ description: 'Returns the length of an array, map, or string',
4458
+ category: 'misc'
4459
+ }, {
4460
+ name: 'get',
4461
+ signature: 'get(v, index)',
4462
+ description: 'Retrieves element at the specified index from an array or map',
4463
+ category: 'misc'
4464
+ },
4465
+ // Bitwise functions
4466
+ {
4467
+ name: 'bitand',
4468
+ signature: 'bitand(int, int)',
4469
+ description: 'Returns the bitwise AND of two integers',
4470
+ category: 'bitwise'
4471
+ }, {
4472
+ name: 'bitor',
4473
+ signature: 'bitor(int, int)',
4474
+ description: 'Returns the bitwise OR of two integers',
4475
+ category: 'bitwise'
4476
+ }, {
4477
+ name: 'bitxor',
4478
+ signature: 'bitxor(int, int)',
4479
+ description: 'Returns the bitwise XOR of two integers',
4480
+ category: 'bitwise'
4481
+ }, {
4482
+ name: 'bitnand',
4483
+ signature: 'bitnand(int, int)',
4484
+ description: 'Returns the bitwise AND NOT of two integers',
4485
+ category: 'bitwise'
4486
+ }, {
4487
+ name: 'bitnot',
4488
+ signature: 'bitnot(int)',
4489
+ description: 'Returns the bitwise NOT of an integer',
4490
+ category: 'bitwise'
4491
+ }, {
4492
+ name: 'bitshl',
4493
+ signature: 'bitshl(int, int)',
4494
+ description: 'Returns the Left Shift of an integer',
4495
+ category: 'bitwise'
4496
+ }, {
4497
+ name: 'bitshr',
4498
+ signature: 'bitshr(int, int)',
4499
+ description: 'Returns the Right Shift of an integer',
4500
+ category: 'bitwise'
4501
+ }, {
4502
+ name: 'bitushr',
4503
+ signature: 'bitushr(int, int)',
4504
+ description: 'Returns the unsigned Right Shift of an integer',
4505
+ category: 'bitwise'
4506
+ }];
4507
+ var getExprCompletionProvider = function getExprCompletionProvider() {
4508
+ return {
4509
+ provideCompletionItems: function provideCompletionItems(model, position, _context, _token) {
4510
+ var word = model.getWordUntilPosition(position);
4511
+ var range = new monaco.Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
4512
+ var suggestions = [].concat(EXPR_KEYWORDS.map(function (keyword) {
4513
+ return {
4514
+ label: keyword,
4515
+ kind: monaco.languages.CompletionItemKind.Keyword,
4516
+ insertText: keyword,
4517
+ range: range,
4518
+ sortText: '1' + keyword
4519
+ };
4520
+ }), EXPR_FUNCTIONS.map(function (func) {
4521
+ return {
4522
+ label: func.name,
4523
+ kind: monaco.languages.CompletionItemKind.Function,
4524
+ insertText: func.name,
4525
+ detail: func.signature,
4526
+ documentation: func.description + (" (" + func.category + ")"),
4527
+ range: range,
4528
+ sortText: '2' + func.name,
4529
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
4530
+ };
4531
+ }));
4532
+ return {
4533
+ suggestions: suggestions
4534
+ };
4535
+ }
4536
+ };
4537
+ };
4538
+
4539
+ /**
4540
+ * Expr-lang token types and AST definitions
4541
+ */
4542
+ var TokenKind;
4543
+ (function (TokenKind) {
4544
+ TokenKind["Identifier"] = "Identifier";
4545
+ TokenKind["Number"] = "Number";
4546
+ TokenKind["String"] = "String";
4547
+ TokenKind["Operator"] = "Operator";
4548
+ TokenKind["Bracket"] = "Bracket";
4549
+ TokenKind["EOF"] = "EOF";
4550
+ })(TokenKind || (TokenKind = {}));
4551
+ var EOF_TOKEN = {
4552
+ kind: TokenKind.EOF,
4553
+ value: '',
4554
+ start: 0,
4555
+ end: 0,
4556
+ line: 0,
4557
+ column: 0
4558
+ };
4559
+ // Operator precedence (higher = binds tighter)
4560
+ var OPERATOR_PRECEDENCE = {
4561
+ '??': 1,
4562
+ '||': 2,
4563
+ or: 2,
4564
+ '&&': 3,
4565
+ and: 3,
4566
+ '==': 4,
4567
+ '!=': 4,
4568
+ '<': 5,
4569
+ '>': 5,
4570
+ '<=': 5,
4571
+ '>=': 5,
4572
+ "in": 5,
4573
+ matches: 5,
4574
+ contains: 5,
4575
+ startsWith: 5,
4576
+ endsWith: 5,
4577
+ '+': 6,
4578
+ '-': 6,
4579
+ '*': 7,
4580
+ '/': 7,
4581
+ '%': 7,
4582
+ '^': 8,
4583
+ '**': 8
4584
+ };
4585
+ // Unary operators
4586
+ var UNARY_OPERATORS = /*#__PURE__*/new Set(['!', 'not', '-']);
4587
+ // Comparison operators (for chained comparisons)
4588
+ var COMPARISON_OPERATORS = /*#__PURE__*/new Set(['<', '>', '<=', '>=', '==', '!=']);
4589
+
4590
+ // Tokens that should be treated as Operators even if they look like identifiers
4591
+ var OPERATOR_TOKENS = /*#__PURE__*/new Set(['let', 'if', 'else', 'not', 'and', 'or', 'in', 'matches', 'contains', 'startsWith', 'endsWith', 'hasPrefix', 'hasSuffix']);
4592
+ var Lexer = /*#__PURE__*/function () {
4593
+ function Lexer() {
4594
+ this.input = '';
4595
+ this.pos = 0;
4596
+ this.line = 1;
4597
+ this.column = 1;
4598
+ this.startLine = 1;
4599
+ this.startColumn = 1;
4600
+ }
4601
+ var _proto = Lexer.prototype;
4602
+ _proto.reset = function reset(input) {
4603
+ this.input = input;
4604
+ this.pos = 0;
4605
+ this.line = 1;
4606
+ this.column = 1;
4607
+ this.startLine = 1;
4608
+ this.startColumn = 1;
4609
+ };
4610
+ _proto.next = function next() {
4611
+ this.skipWhitespace();
4612
+ this.skipComments();
4613
+ if (this.pos >= this.input.length) {
4614
+ return _extends({}, EOF_TOKEN, {
4615
+ start: this.pos,
4616
+ end: this.pos,
4617
+ line: this.line,
4618
+ column: this.column
4619
+ });
4620
+ }
4621
+ this.startLine = this.line;
4622
+ this.startColumn = this.column;
4623
+ var ch = this.input[this.pos];
4624
+ // String literals
4625
+ if (ch === '"' || ch === "'") {
4626
+ return this.readString(ch);
4627
+ }
4628
+ if (ch === '`') {
4629
+ return this.readBacktickString();
4630
+ }
4631
+ // Byte literals: b"..." or b'...' or B"..." or B'...'
4632
+ if ((ch === 'b' || ch === 'B') && this.pos + 1 < this.input.length) {
4633
+ var _next = this.input[this.pos + 1];
4634
+ if (_next === '"' || _next === "'") {
4635
+ return this.readByteLiteral();
4636
+ }
4637
+ }
4638
+ // Numbers
4639
+ if (this.isDigit(ch) || ch === '.' && this.pos + 1 < this.input.length && this.isDigit(this.input[this.pos + 1])) {
4640
+ return this.readNumber();
4641
+ }
4642
+ // Identifiers and keywords
4643
+ if (this.isIdentStart(ch)) {
4644
+ var token = this.readIdentOrKeyword();
4645
+ return token;
4646
+ }
4647
+ // Operators and brackets
4648
+ return this.readOperatorOrBracket();
4649
+ };
4650
+ _proto.skipWhitespace = function skipWhitespace() {
4651
+ while (this.pos < this.input.length) {
4652
+ var ch = this.input[this.pos];
4653
+ if (ch === ' ' || ch === '\t' || ch === '\r') {
4654
+ this.pos++;
4655
+ this.column++;
4656
+ } else if (ch === '\n') {
4657
+ this.pos++;
4658
+ this.line++;
4659
+ this.column = 1;
4660
+ } else {
4661
+ break;
4662
+ }
4663
+ }
4664
+ };
4665
+ _proto.skipComments = function skipComments() {
4666
+ while (this.pos < this.input.length) {
4667
+ // Line comment //
4668
+ if (this.input[this.pos] === '/' && this.pos + 1 < this.input.length && this.input[this.pos + 1] === '/') {
4669
+ this.pos += 2;
4670
+ this.column += 2;
4671
+ while (this.pos < this.input.length && this.input[this.pos] !== '\n') {
4672
+ this.pos++;
4673
+ this.column++;
4674
+ }
4675
+ this.skipWhitespace();
4676
+ continue;
4677
+ }
4678
+ // Block comment /* */
4679
+ if (this.input[this.pos] === '/' && this.pos + 1 < this.input.length && this.input[this.pos + 1] === '*') {
4680
+ this.pos += 2;
4681
+ this.column += 2;
4682
+ while (this.pos < this.input.length) {
4683
+ if (this.input[this.pos] === '*' && this.pos + 1 < this.input.length && this.input[this.pos + 1] === '/') {
4684
+ this.pos += 2;
4685
+ this.column += 2;
4686
+ break;
4687
+ }
4688
+ if (this.input[this.pos] === '\n') {
4689
+ this.line++;
4690
+ this.column = 1;
4691
+ } else {
4692
+ this.column++;
4693
+ }
4694
+ this.pos++;
4695
+ }
4696
+ this.skipWhitespace();
4697
+ continue;
4698
+ }
4699
+ break;
4700
+ }
4701
+ };
4702
+ _proto.readString = function readString(quote) {
4703
+ var start = this.pos;
4704
+ this.pos++; // skip opening quote
4705
+ this.column++;
4706
+ var value = '';
4707
+ while (this.pos < this.input.length) {
4708
+ var ch = this.input[this.pos];
4709
+ if (ch === '\\') {
4710
+ if (this.pos + 1 >= this.input.length) break;
4711
+ var next = this.input[this.pos + 1];
4712
+ switch (next) {
4713
+ case 'n':
4714
+ value += '\n';
4715
+ break;
4716
+ case 't':
4717
+ value += '\t';
4718
+ break;
4719
+ case 'r':
4720
+ value += '\r';
4721
+ break;
4722
+ case '\\':
4723
+ value += '\\';
4724
+ break;
4725
+ case quote:
4726
+ value += quote;
4727
+ break;
4728
+ case 'x':
4729
+ {
4730
+ var hex = this.input.substr(this.pos + 2, 2);
4731
+ value += String.fromCharCode(parseInt(hex, 16));
4732
+ this.pos += 2;
4733
+ this.column += 2;
4734
+ break;
4735
+ }
4736
+ case 'u':
4737
+ {
4738
+ var unicode = this.input.substr(this.pos + 2, 4);
4739
+ value += String.fromCharCode(parseInt(unicode, 16));
4740
+ this.pos += 2;
4741
+ this.column += 2;
4742
+ break;
4743
+ }
4744
+ default:
4745
+ value += next;
4746
+ }
4747
+ this.pos += 2;
4748
+ this.column += 2;
4749
+ } else if (ch === quote) {
4750
+ this.pos++; // skip closing quote
4751
+ this.column++;
4752
+ return this.makeToken(TokenKind.String, value, start);
4753
+ } else {
4754
+ value += ch;
4755
+ this.pos++;
4756
+ this.column++;
4757
+ if (ch === '\n') {
4758
+ this.line++;
4759
+ this.column = 1;
4760
+ }
4761
+ }
4762
+ }
4763
+ return this.makeToken(TokenKind.String, value, start);
4764
+ };
4765
+ _proto.readBacktickString = function readBacktickString() {
4766
+ var start = this.pos;
4767
+ this.pos++; // skip opening backtick
4768
+ this.column++;
4769
+ var value = '';
4770
+ while (this.pos < this.input.length) {
4771
+ var ch = this.input[this.pos];
4772
+ if (ch === '`') {
4773
+ this.pos++;
4774
+ this.column++;
4775
+ return this.makeToken(TokenKind.String, value, start);
4776
+ }
4777
+ value += ch;
4778
+ this.pos++;
4779
+ if (ch === '\n') {
4780
+ this.line++;
4781
+ this.column = 1;
4782
+ } else {
4783
+ this.column++;
4784
+ }
4785
+ }
4786
+ return this.makeToken(TokenKind.String, value, start);
4787
+ };
4788
+ _proto.readByteLiteral = function readByteLiteral() {
4789
+ // b"..." or b'...' or B"..." or B'...'
4790
+ var start = this.pos;
4791
+ this.pos++; // skip 'b' or 'B'
4792
+ this.column++;
4793
+ var quote = this.input[this.pos];
4794
+ this.pos++; // skip quote
4795
+ this.column++;
4796
+ var value = '';
4797
+ while (this.pos < this.input.length) {
4798
+ var ch = this.input[this.pos];
4799
+ if (ch === '\\') {
4800
+ if (this.pos + 1 >= this.input.length) break;
4801
+ var next = this.input[this.pos + 1];
4802
+ switch (next) {
4803
+ case 'n':
4804
+ value += '\n';
4805
+ break;
4806
+ case 't':
4807
+ value += '\t';
4808
+ break;
4809
+ case 'r':
4810
+ value += '\r';
4811
+ break;
4812
+ case '\\':
4813
+ value += '\\';
4814
+ break;
4815
+ case quote:
4816
+ value += quote;
4817
+ break;
4818
+ case 'x':
4819
+ {
4820
+ var hex = this.input.substr(this.pos + 2, 2);
4821
+ value += String.fromCharCode(parseInt(hex, 16));
4822
+ this.pos += 2;
4823
+ this.column += 2;
4824
+ break;
4825
+ }
4826
+ default:
4827
+ // octal escape \NNN
4828
+ if (this.isDigit(next)) {
4829
+ var octal = this.input.substr(this.pos + 1, 3);
4830
+ value += String.fromCharCode(parseInt(octal, 8));
4831
+ this.pos += 2;
4832
+ this.column += 2;
4833
+ break;
4834
+ }
4835
+ value += next;
4836
+ }
4837
+ this.pos += 2;
4838
+ this.column += 2;
4839
+ } else if (ch === quote) {
4840
+ this.pos++;
4841
+ this.column++;
4842
+ return this.makeToken(TokenKind.String, value, start);
4843
+ } else {
4844
+ value += ch;
4845
+ this.pos++;
4846
+ this.column++;
4847
+ }
4848
+ }
4849
+ return this.makeToken(TokenKind.String, value, start);
4850
+ };
4851
+ _proto.readNumber = function readNumber() {
4852
+ var start = this.pos;
4853
+ var value = '';
4854
+ while (this.pos < this.input.length) {
4855
+ var ch = this.input[this.pos];
4856
+ if (this.isDigit(ch) || ch === '.' || ch === 'e' || ch === 'E' || ch === '+' || ch === '-' || ch === '_' || ch === 'x' || ch === 'X' || ch === 'o' || ch === 'O' || ch === 'b' || ch === 'B' || ch >= 'a' && ch <= 'f' || ch >= 'A' && ch <= 'F') {
4857
+ value += ch;
4858
+ this.pos++;
4859
+ this.column++;
4860
+ } else {
4861
+ break;
4862
+ }
4863
+ }
4864
+ return this.makeToken(TokenKind.Number, value, start);
4865
+ };
4866
+ _proto.readIdentOrKeyword = function readIdentOrKeyword() {
4867
+ var start = this.pos;
4868
+ var value = '';
4869
+ while (this.pos < this.input.length) {
4870
+ var ch = this.input[this.pos];
4871
+ if (this.isIdentPart(ch)) {
4872
+ value += ch;
4873
+ this.pos++;
4874
+ this.column++;
4875
+ } else {
4876
+ break;
4877
+ }
4878
+ }
4879
+ // Keywords that are operators
4880
+ if (OPERATOR_TOKENS.has(value)) {
4881
+ return this.makeToken(TokenKind.Operator, value, start);
4882
+ }
4883
+ return this.makeToken(TokenKind.Identifier, value, start);
4884
+ };
4885
+ _proto.readOperatorOrBracket = function readOperatorOrBracket() {
4886
+ var start = this.pos;
4887
+ var ch = this.input[this.pos];
4888
+ // Brackets
4889
+ if ('()[]{}'.includes(ch)) {
4890
+ this.pos++;
4891
+ this.column++;
4892
+ return this.makeToken(TokenKind.Bracket, ch, start);
4893
+ }
4894
+ // Multi-character operators
4895
+ var twoChar = this.input.substr(this.pos, 2);
4896
+ var threeChar = this.input.substr(this.pos, 3);
4897
+ // 3-character operators: **=
4898
+ // 2-character operators
4899
+ var twoCharOps = ['==', '!=', '<=', '>=', '&&', '||', '??', '?.', '..', '**', '//', '::', '->'];
4900
+ var threeCharOps = ['...', '<<=', '>>='];
4901
+ if (threeCharOps.includes(threeChar)) {
4902
+ this.pos += 3;
4903
+ this.column += 3;
4904
+ return this.makeToken(TokenKind.Operator, threeChar, start);
4905
+ }
4906
+ if (twoCharOps.includes(twoChar)) {
4907
+ this.pos += 2;
4908
+ this.column += 2;
4909
+ return this.makeToken(TokenKind.Operator, twoChar, start);
4910
+ }
4911
+ // Single-character operators and separators
4912
+ var singleCharOps = '+-*/%^=<>!&|?.,;:#@$~';
4913
+ if (singleCharOps.includes(ch)) {
4914
+ this.pos++;
4915
+ this.column++;
4916
+ return this.makeToken(TokenKind.Operator, ch, start);
4917
+ }
4918
+ // Unrecognized character
4919
+ this.pos++;
4920
+ this.column++;
4921
+ return this.makeToken(TokenKind.Operator, ch, start);
4922
+ };
4923
+ _proto.isDigit = function isDigit(ch) {
4924
+ return ch >= '0' && ch <= '9';
4925
+ };
4926
+ _proto.isIdentStart = function isIdentStart(ch) {
4927
+ return ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch === '_' || ch === '$';
4928
+ };
4929
+ _proto.isIdentPart = function isIdentPart(ch) {
4930
+ return this.isIdentStart(ch) || this.isDigit(ch);
4931
+ };
4932
+ _proto.makeToken = function makeToken(kind, value, start) {
4933
+ return {
4934
+ kind: kind,
4935
+ value: value,
4936
+ start: start,
4937
+ end: this.pos,
4938
+ line: this.startLine,
4939
+ column: this.startColumn
4940
+ };
4941
+ };
4942
+ return Lexer;
4943
+ }();
4944
+
4945
+ var ExprParser = /*#__PURE__*/function () {
4946
+ function ExprParser() {
4947
+ this.current = _extends({}, EOF_TOKEN);
4948
+ this.errors = [];
4949
+ this.lexer = new Lexer();
4950
+ }
4951
+ /**
4952
+ * Parse an expr-lang expression and return any syntax errors.
4953
+ * Returns empty array if the expression is valid.
4954
+ */
4955
+ var _proto = ExprParser.prototype;
4956
+ _proto.parse = function parse(input) {
4957
+ this.errors = [];
4958
+ this.lexer.reset(input);
4959
+ this.advance();
4960
+ if (input.trim().length === 0) {
4961
+ return [];
4962
+ }
4963
+ this.parseSequenceExpression();
4964
+ // Check for unexpected tokens at the end
4965
+ if (this.curKind() !== TokenKind.EOF && this.errors.length === 0) {
4966
+ this.error("unexpected token \"" + this.curVal() + "\"");
4967
+ }
4968
+ return this.errors;
4969
+ };
4970
+ _proto.advance = function advance() {
4971
+ this.current = this.lexer.next();
4972
+ };
4973
+ _proto.curKind = function curKind() {
4974
+ return this.current.kind;
4975
+ };
4976
+ _proto.curVal = function curVal() {
4977
+ return this.current.value;
4978
+ };
4979
+ _proto.expect = function expect(kind, value) {
4980
+ if (this.curKind() === kind && (value === undefined || this.curVal() === value)) {
4981
+ this.advance();
4982
+ return true;
4983
+ }
4984
+ if (value) {
4985
+ this.error("expected \"" + value + "\" but got \"" + this.curVal() + "\"");
4986
+ } else {
4987
+ this.error("unexpected token \"" + this.curVal() + "\"");
4988
+ }
4989
+ return false;
4990
+ };
4991
+ _proto.error = function error(message) {
4992
+ if (this.errors.length === 0) {
4993
+ // Calculate end position — approximate
4994
+ var endLine = this.current.line;
4995
+ var endColumn = this.current.column + this.curVal().length;
4996
+ this.errors.push({
4997
+ message: message,
4998
+ startLine: this.current.line,
4999
+ startColumn: this.current.column,
5000
+ endLine: endLine,
5001
+ endColumn: endColumn
5002
+ });
5003
+ }
5004
+ };
5005
+ _proto.errorAt = function errorAt(token, message) {
5006
+ if (this.errors.length === 0) {
5007
+ var endColumn = token.column + token.value.length;
5008
+ this.errors.push({
5009
+ message: message,
5010
+ startLine: token.line,
5011
+ startColumn: token.column,
5012
+ endLine: token.line,
5013
+ endColumn: endColumn
5014
+ });
5015
+ }
5016
+ }
5017
+ // ========== Parsing Functions ==========
5018
+ /**
5019
+ * parseSequenceExpression parses multiple expressions separated by semicolons.
5020
+ */;
5021
+ _proto.parseSequenceExpression = function parseSequenceExpression() {
5022
+ if (this.errors.length > 0) return;
5023
+ this.parseExpression(0);
5024
+ while (this.curVal() === ';' && this.errors.length === 0) {
5025
+ this.advance();
5026
+ if (this.curKind() === TokenKind.EOF) break;
5027
+ this.parseExpression(0);
5028
+ }
5029
+ }
5030
+ /**
5031
+ * parseExpression uses precedence climbing to parse binary expressions.
5032
+ */;
5033
+ _proto.parseExpression = function parseExpression(precedence) {
5034
+ if (this.errors.length > 0) return;
5035
+ // Handle "let" at precedence 0
5036
+ if (precedence === 0 && this.curVal() === 'let') {
5037
+ this.parseVariableDeclaration();
5038
+ return;
5039
+ }
5040
+ // Handle "if" at precedence 0
5041
+ if (precedence === 0 && this.curVal() === 'if') {
5042
+ this.parseConditionalIf();
5043
+ return;
5044
+ }
5045
+ // Handle unary operators
5046
+ if (UNARY_OPERATORS.has(this.curVal()) && this.curKind() === TokenKind.Operator) {
5047
+ var unaryToken = this.current;
5048
+ this.advance();
5049
+ if (this.curKind() === TokenKind.EOF) {
5050
+ this.errorAt(unaryToken, 'unexpected token EOF');
5051
+ return;
5052
+ }
5053
+ if (this.errors.length > 0) return;
5054
+ this.parsePrimary();
5055
+ if (this.errors.length > 0) return;
5056
+ this.parsePostfixExpression();
5057
+ return;
5058
+ }
5059
+ this.parsePrimary();
5060
+ if (this.errors.length > 0) return;
5061
+ this.parsePostfixExpression();
5062
+ if (this.errors.length > 0) return;
5063
+ // Handle binary operators with precedence climbing
5064
+ while (this.curKind() === TokenKind.Operator && this.errors.length === 0) {
5065
+ var op = this.curVal();
5066
+ var opToken = this.current;
5067
+ // Handle pipe operator |
5068
+ if (op === '|') {
5069
+ this.advance(); // skip |
5070
+ if (this.curKind() === TokenKind.EOF) {
5071
+ this.errorAt(opToken, 'unexpected token EOF');
5072
+ return;
5073
+ }
5074
+ if (this.curKind() === TokenKind.Identifier) {
5075
+ this.advance(); // skip identifier
5076
+ this.parseArguments();
5077
+ if (this.curVal() === ';') break;
5078
+ continue;
5079
+ }
5080
+ this.error("expected identifier after pipe \"|\" but got \"" + this.curVal() + "\"");
5081
+ return;
5082
+ }
5083
+ // Handle semicolon — end of this expression
5084
+ if (op === ';') break;
5085
+ // Check precedence
5086
+ var opPrec = OPERATOR_PRECEDENCE[op];
5087
+ if (opPrec === undefined || opPrec < precedence) break;
5088
+ // Handle "not" prefix for "not in", "not contains", etc.
5089
+ if (op === 'not') {
5090
+ this.advance();
5091
+ var nextOp = this.curVal();
5092
+ var negatedPrec = OPERATOR_PRECEDENCE[nextOp];
5093
+ if (negatedPrec !== undefined && negatedPrec >= precedence) {
5094
+ this.advance();
5095
+ this.parseExpression(negatedPrec + 1);
5096
+ continue;
5097
+ }
5098
+ this.error("unexpected token \"" + nextOp + "\" after \"not\"");
5099
+ return;
5100
+ }
5101
+ // Handle chained comparisons: a < b < c => (a < b) && (b < c)
5102
+ if (COMPARISON_OPERATORS.has(op)) {
5103
+ this.advance();
5104
+ if (this.curKind() === TokenKind.EOF) {
5105
+ this.errorAt(opToken, 'unexpected token EOF');
5106
+ return;
5107
+ }
5108
+ this.parseExpression(opPrec + 1);
5109
+ // Keep parsing chained comparisons
5110
+ while (this.curKind() === TokenKind.Operator && COMPARISON_OPERATORS.has(this.curVal()) && this.errors.length === 0) {
5111
+ var chainOpToken = this.current;
5112
+ this.advance();
5113
+ if (this.curKind() === TokenKind.EOF) {
5114
+ this.errorAt(chainOpToken, 'unexpected token EOF');
5115
+ return;
5116
+ }
5117
+ this.parseExpression((OPERATOR_PRECEDENCE[this.curVal()] || 0) + 1);
5118
+ }
5119
+ continue;
5120
+ }
5121
+ this.advance();
5122
+ if (this.curKind() === TokenKind.EOF) {
5123
+ this.errorAt(opToken, 'unexpected token EOF');
5124
+ return;
5125
+ }
5126
+ // Right-associative operators bind to the right
5127
+ // For simplicity, parse with same precedence for right-assoc
5128
+ this.parseExpression(opPrec + 1);
5129
+ // Handle ternary ? :
5130
+ if (precedence === 0 && this.curVal() === '?') {
5131
+ this.parseConditional();
5132
+ }
5133
+ }
5134
+ // Handle ternary ? : at precedence 0
5135
+ if (precedence === 0 && this.curVal() === '?') {
5136
+ this.parseConditional();
5137
+ }
5138
+ }
5139
+ /**
5140
+ * parsePrimary handles unary operators, parentheses, and the #/. pointer prefix.
5141
+ */;
5142
+ _proto.parsePrimary = function parsePrimary() {
5143
+ if (this.errors.length > 0) return;
5144
+ // Unary operators are handled in parseExpression
5145
+ // Parenthesized expression
5146
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '(') {
5147
+ this.advance(); // skip (
5148
+ this.parseSequenceExpression();
5149
+ if (!this.expect(TokenKind.Bracket, ')')) {
5150
+ return;
5151
+ }
5152
+ return;
5153
+ }
5154
+ // Handle # or . prefix (in predicates)
5155
+ if ((this.curVal() === '#' || this.curVal() === '.') && this.curKind() === TokenKind.Operator) {
5156
+ this.advance();
5157
+ if (this.curKind() === TokenKind.Identifier) {
5158
+ this.advance();
5159
+ }
5160
+ this.parsePostfixExpression();
5161
+ return;
5162
+ }
5163
+ this.parseSecondary();
5164
+ }
5165
+ /**
5166
+ * parseSecondary handles identifiers, literals, arrays, and maps.
5167
+ */;
5168
+ _proto.parseSecondary = function parseSecondary() {
5169
+ if (this.errors.length > 0) return;
5170
+ var token = this.current;
5171
+ switch (token.kind) {
5172
+ case TokenKind.Identifier:
5173
+ {
5174
+ this.advance();
5175
+ // Check for function call
5176
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '(') {
5177
+ this.parseArguments();
5178
+ }
5179
+ break;
5180
+ }
5181
+ case TokenKind.Number:
5182
+ {
5183
+ this.advance();
5184
+ break;
5185
+ }
5186
+ case TokenKind.String:
5187
+ {
5188
+ this.advance();
5189
+ break;
5190
+ }
5191
+ case TokenKind.Bracket:
5192
+ {
5193
+ if (token.value === '[') {
5194
+ this.parseArrayExpression();
5195
+ } else if (token.value === '{') {
5196
+ this.parseMapExpression();
5197
+ } else {
5198
+ this.error("unexpected token \"" + token.value + "\"");
5199
+ }
5200
+ break;
5201
+ }
5202
+ default:
5203
+ this.error("unexpected token \"" + token.value + "\"");
5204
+ break;
5205
+ }
5206
+ }
5207
+ /**
5208
+ * parsePostfixExpression handles .member, ?.member, [index], [from:to], and calls after the primary.
5209
+ */;
5210
+ _proto.parsePostfixExpression = function parsePostfixExpression() {
5211
+ while (this.errors.length === 0) {
5212
+ var token = this.current;
5213
+ // .member or ?.member
5214
+ if (token.kind === TokenKind.Operator && (token.value === '.' || token.value === '?.')) {
5215
+ this.advance();
5216
+ // After . or ?., expect an identifier (or operator like "not" that can be a method name)
5217
+ if (this.curKind() === TokenKind.Identifier || this.curKind() === TokenKind.Operator) {
5218
+ this.advance();
5219
+ // Check for method call: obj.method()
5220
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '(') {
5221
+ this.parseArguments();
5222
+ }
5223
+ } else if (this.curKind() === TokenKind.Bracket && this.curVal() === '[' && token.value === '?.') {
5224
+ // obj?[index] — handle bracket after ?.
5225
+ this.advance();
5226
+ this.parseExpression(0);
5227
+ this.expect(TokenKind.Bracket, ']');
5228
+ } else {
5229
+ this.error("expected property name after \"" + token.value + "\" but got \"" + this.curVal() + "\"");
5230
+ return;
5231
+ }
5232
+ continue;
5233
+ }
5234
+ // [index] or [from:to]
5235
+ if (token.kind === TokenKind.Bracket && token.value === '[') {
5236
+ this.advance();
5237
+ // Check for slice: [:] or [:to]
5238
+ if (this.curKind() === TokenKind.Operator && this.curVal() === ':') {
5239
+ this.advance();
5240
+ if (this.curKind() !== TokenKind.Bracket || this.curVal() !== ']') {
5241
+ this.parseExpression(0);
5242
+ }
5243
+ this.expect(TokenKind.Bracket, ']');
5244
+ } else {
5245
+ // Index expression
5246
+ this.parseExpression(0);
5247
+ // Check for slice: [from:]
5248
+ if (this.curKind() === TokenKind.Operator && this.curVal() === ':') {
5249
+ this.advance();
5250
+ if (this.curKind() !== TokenKind.Bracket || this.curVal() !== ']') {
5251
+ this.parseExpression(0);
5252
+ }
5253
+ }
5254
+ this.expect(TokenKind.Bracket, ']');
5255
+ }
5256
+ continue;
5257
+ }
5258
+ // Function call after member access
5259
+ if (token.kind === TokenKind.Bracket && token.value === '(') {
5260
+ this.parseArguments();
5261
+ continue;
5262
+ }
5263
+ break;
5264
+ }
5265
+ }
5266
+ /**
5267
+ * parseVariableDeclaration parses "let name = value; rest"
5268
+ */;
5269
+ _proto.parseVariableDeclaration = function parseVariableDeclaration() {
5270
+ this.expect(TokenKind.Operator, 'let');
5271
+ if (this.errors.length > 0) return;
5272
+ if (this.curKind() !== TokenKind.Identifier) {
5273
+ this.error("expected variable name after \"let\" but got \"" + this.curVal() + "\"");
5274
+ return;
5275
+ }
5276
+ this.advance(); // skip variable name
5277
+ if (!this.expect(TokenKind.Operator, '=')) return;
5278
+ this.parseExpression(0);
5279
+ if (this.errors.length > 0) return;
5280
+ // Optional semicolon after value
5281
+ if (this.curVal() === ';') {
5282
+ this.advance();
5283
+ if (this.curKind() !== TokenKind.EOF) {
5284
+ this.parseSequenceExpression();
5285
+ }
5286
+ }
5287
+ }
5288
+ /**
5289
+ * parseConditionalIf parses "if expr { expr1 } else { expr2 }" or "if expr { expr1 } else if ..."
5290
+ */;
5291
+ _proto.parseConditionalIf = function parseConditionalIf() {
5292
+ this.advance(); // skip 'if'
5293
+ if (this.errors.length > 0) return;
5294
+ this.parseExpression(0);
5295
+ if (this.errors.length > 0) return;
5296
+ if (!this.expect(TokenKind.Bracket, '{')) return;
5297
+ this.parseSequenceExpression();
5298
+ if (this.errors.length > 0) return;
5299
+ if (!this.expect(TokenKind.Bracket, '}')) return;
5300
+ if (!this.expect(TokenKind.Operator, 'else')) return;
5301
+ // Nested if
5302
+ if (this.curVal() === 'if') {
5303
+ this.parseConditionalIf();
5304
+ return;
5305
+ }
5306
+ if (!this.expect(TokenKind.Bracket, '{')) return;
5307
+ this.parseSequenceExpression();
5308
+ if (this.errors.length > 0) return;
5309
+ this.expect(TokenKind.Bracket, '}');
5310
+ }
5311
+ /**
5312
+ * parseConditional parses "expr ? expr1 : expr2" or "expr ?: expr2"
5313
+ */;
5314
+ _proto.parseConditional = function parseConditional() {
5315
+ if (this.curVal() !== '?') return;
5316
+ this.advance(); // skip ?
5317
+ // Elvis operator ?:
5318
+ if (this.curVal() === ':') {
5319
+ this.advance();
5320
+ this.parseExpression(0);
5321
+ return;
5322
+ }
5323
+ this.parseExpression(0);
5324
+ if (this.errors.length > 0) return;
5325
+ if (!this.expect(TokenKind.Operator, ':')) return;
5326
+ this.parseExpression(0);
5327
+ }
5328
+ /**
5329
+ * parseArguments parses function call arguments: (arg1, arg2, ...)
5330
+ */;
5331
+ _proto.parseArguments = function parseArguments() {
5332
+ if (!this.expect(TokenKind.Bracket, '(')) return;
5333
+ while (this.curKind() !== TokenKind.Bracket || this.curVal() !== ')') {
5334
+ if (this.curKind() === TokenKind.EOF) {
5335
+ this.error('unexpected end of expression, expected ")"');
5336
+ return;
5337
+ }
5338
+ if (this.curVal() === ',') {
5339
+ this.advance();
5340
+ continue;
5341
+ }
5342
+ // Check for predicate { ... } argument
5343
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '{') {
5344
+ this.advance();
5345
+ this.parseSequenceExpression();
5346
+ this.expect(TokenKind.Bracket, '}');
5347
+ } else {
5348
+ this.parseExpression(0);
5349
+ }
5350
+ if (this.errors.length > 0) return;
5351
+ if (this.curVal() === ',') {
5352
+ this.advance();
5353
+ // Allow trailing comma
5354
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === ')') {
5355
+ break;
5356
+ }
5357
+ }
5358
+ }
5359
+ this.expect(TokenKind.Bracket, ')');
5360
+ }
5361
+ /**
5362
+ * parseArrayExpression parses "[elem1, elem2, ...]"
5363
+ */;
5364
+ _proto.parseArrayExpression = function parseArrayExpression() {
5365
+ this.expect(TokenKind.Bracket, '[');
5366
+ if (this.errors.length > 0) return;
5367
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === ']') {
5368
+ this.advance();
5369
+ return;
5370
+ }
5371
+ while (this.errors.length === 0) {
5372
+ this.parseExpression(0);
5373
+ if (this.errors.length > 0) return;
5374
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === ']') {
5375
+ break;
5376
+ }
5377
+ if (this.curVal() === ',') {
5378
+ this.advance();
5379
+ // Allow trailing comma
5380
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === ']') {
5381
+ break;
5382
+ }
5383
+ continue;
5384
+ }
5385
+ this.error("expected \",\" or \"]\" but got \"" + this.curVal() + "\"");
5386
+ return;
5387
+ }
5388
+ this.expect(TokenKind.Bracket, ']');
5389
+ }
5390
+ /**
5391
+ * parseMapExpression parses "{key: value, ...}"
5392
+ */;
5393
+ _proto.parseMapExpression = function parseMapExpression() {
5394
+ this.expect(TokenKind.Bracket, '{');
5395
+ if (this.errors.length > 0) return;
5396
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '}') {
5397
+ this.advance();
5398
+ return;
5399
+ }
5400
+ while (this.errors.length === 0) {
5401
+ // Key: identifier, string, number, or parenthesized expression
5402
+ if (this.curKind() === TokenKind.Identifier || this.curKind() === TokenKind.String || this.curKind() === TokenKind.Number) {
5403
+ this.advance();
5404
+ } else if (this.curKind() === TokenKind.Bracket && this.curVal() === '(') {
5405
+ this.advance();
5406
+ this.parseExpression(0);
5407
+ this.expect(TokenKind.Bracket, ')');
5408
+ } else {
5409
+ this.error("map key must be a string, number, identifier, or parenthesized expression, got \"" + this.curVal() + "\"");
5410
+ return;
5411
+ }
5412
+ if (!this.expect(TokenKind.Operator, ':')) return;
5413
+ this.parseExpression(0);
5414
+ if (this.errors.length > 0) return;
5415
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '}') {
5416
+ break;
5417
+ }
5418
+ if (this.curVal() === ',') {
5419
+ this.advance();
5420
+ if (this.curKind() === TokenKind.Bracket && this.curVal() === '}') {
5421
+ break;
5422
+ }
5423
+ continue;
5424
+ }
5425
+ this.error("expected \",\" or \"}\" but got \"" + this.curVal() + "\"");
5426
+ return;
5427
+ }
5428
+ this.expect(TokenKind.Bracket, '}');
5429
+ };
5430
+ return ExprParser;
5431
+ }();
5432
+
5433
+ var EXPR_LANG_ID = 'expr';
5434
+ var parser = /*#__PURE__*/new ExprParser();
5435
+ /**
5436
+ * Validate an expr-lang expression and return Monaco editor markers.
5437
+ * Uses the recursive descent parser for syntax errors,
5438
+ * plus regex-based checks for structural issues like unbalanced quotes/brackets.
5439
+ */
5440
+ var validateExpr = function validateExpr(expr) {
5441
+ var markers = [];
5442
+ if (!expr || expr.trim().length === 0) {
5443
+ return markers;
5444
+ }
5445
+ // 1. Parser-based syntax validation
5446
+ var parseErrors = parser.parse(expr);
5447
+ for (var _iterator = _createForOfIteratorHelperLoose(parseErrors), _step; !(_step = _iterator()).done;) {
5448
+ var err = _step.value;
5449
+ markers.push({
5450
+ severity: monaco.MarkerSeverity.Error,
5451
+ startLineNumber: err.startLine,
5452
+ startColumn: err.startColumn,
5453
+ endLineNumber: err.endLine,
5454
+ endColumn: err.endColumn,
5455
+ message: err.message
5456
+ });
5457
+ }
5458
+ // 2. Line-level structural checks (fallback for issues the parser might miss)
5459
+ var structuralMarkers = validateLineLevel(expr);
5460
+ markers.push.apply(markers, structuralMarkers);
5461
+ return markers;
5462
+ };
5463
+ /**
5464
+ * Basic line-level validation for quotes and bracket balancing.
5465
+ */
5466
+ function validateLineLevel(expr) {
5467
+ var markers = [];
5468
+ var lines = expr.split('\n');
5469
+ var inBlockComment = false;
5470
+ lines.forEach(function (line, index) {
5471
+ var lineNumber = index + 1;
5472
+ // Track block comment state
5473
+ if (!inBlockComment) {
5474
+ var blockCommentStart = line.indexOf('/*');
5475
+ if (blockCommentStart !== -1) {
5476
+ var blockCommentEnd = line.indexOf('*/', blockCommentStart + 2);
5477
+ if (blockCommentEnd === -1) {
5478
+ inBlockComment = true;
5479
+ }
5480
+ }
5481
+ } else {
5482
+ var _blockCommentEnd = line.indexOf('*/');
5483
+ if (_blockCommentEnd !== -1) {
5484
+ inBlockComment = false;
5485
+ }
5486
+ if (inBlockComment || line.trim().startsWith('/*')) {
5487
+ return;
5488
+ }
5489
+ }
5490
+ var trimmedLine = line.trim();
5491
+ if (trimmedLine.startsWith('//') || trimmedLine.startsWith('/*')) {
5492
+ return;
5493
+ }
5494
+ // Check for unclosed quotes
5495
+ var singleQuotes = countQuotesOutsideBlockComments(line);
5496
+ if (singleQuotes % 2 !== 0) {
5497
+ markers.push({
5498
+ severity: monaco.MarkerSeverity.Warning,
5499
+ startLineNumber: lineNumber,
5500
+ startColumn: 1,
5501
+ endLineNumber: lineNumber,
5502
+ endColumn: line.length + 1,
5503
+ message: "Unclosed single quote '",
5504
+ source: EXPR_LANG_ID
5505
+ });
5506
+ }
5507
+ var doubleQuotes = countDoubleQuotesOutsideBlockComments(line);
5508
+ if (doubleQuotes % 2 !== 0) {
5509
+ markers.push({
5510
+ severity: monaco.MarkerSeverity.Warning,
5511
+ startLineNumber: lineNumber,
5512
+ startColumn: 1,
5513
+ endLineNumber: lineNumber,
5514
+ endColumn: line.length + 1,
5515
+ message: 'Unclosed double quote "',
5516
+ source: EXPR_LANG_ID
5517
+ });
5518
+ }
5519
+ var backticks = (line.match(/`/g) || []).length;
5520
+ if (backticks % 2 !== 0) {
5521
+ markers.push({
5522
+ severity: monaco.MarkerSeverity.Warning,
5523
+ startLineNumber: lineNumber,
5524
+ startColumn: 1,
5525
+ endLineNumber: lineNumber,
5526
+ endColumn: line.length + 1,
5527
+ message: 'Unclosed backtick `',
5528
+ source: EXPR_LANG_ID
5529
+ });
5530
+ }
5531
+ // Check for unbalanced brackets
5532
+ var openParens = (line.match(/\(/g) || []).length;
5533
+ var closeParens = (line.match(/\)/g) || []).length;
5534
+ if (openParens > closeParens) {
5535
+ markers.push({
5536
+ severity: monaco.MarkerSeverity.Warning,
5537
+ startLineNumber: lineNumber,
5538
+ startColumn: 1,
5539
+ endLineNumber: lineNumber,
5540
+ endColumn: line.length + 1,
5541
+ message: 'Unmatched opening parenthesis',
5542
+ source: EXPR_LANG_ID
5543
+ });
5544
+ } else if (closeParens > openParens) {
5545
+ markers.push({
5546
+ severity: monaco.MarkerSeverity.Warning,
5547
+ startLineNumber: lineNumber,
5548
+ startColumn: 1,
5549
+ endLineNumber: lineNumber,
5550
+ endColumn: line.length + 1,
5551
+ message: 'Unmatched closing parenthesis',
5552
+ source: EXPR_LANG_ID
5553
+ });
5554
+ }
5555
+ var openBrackets = (line.match(/\[/g) || []).length;
5556
+ var closeBrackets = (line.match(/\]/g) || []).length;
5557
+ if (openBrackets > closeBrackets) {
5558
+ markers.push({
5559
+ severity: monaco.MarkerSeverity.Warning,
5560
+ startLineNumber: lineNumber,
5561
+ startColumn: 1,
5562
+ endLineNumber: lineNumber,
5563
+ endColumn: line.length + 1,
5564
+ message: 'Unmatched opening bracket',
5565
+ source: EXPR_LANG_ID
5566
+ });
5567
+ } else if (closeBrackets > openBrackets) {
5568
+ markers.push({
5569
+ severity: monaco.MarkerSeverity.Warning,
5570
+ startLineNumber: lineNumber,
5571
+ startColumn: 1,
5572
+ endLineNumber: lineNumber,
5573
+ endColumn: line.length + 1,
5574
+ message: 'Unmatched closing bracket',
5575
+ source: EXPR_LANG_ID
5576
+ });
5577
+ }
5578
+ var openBraces = (line.match(/\{/g) || []).length;
5579
+ var closeBraces = (line.match(/\}/g) || []).length;
5580
+ if (openBraces > closeBraces) {
5581
+ markers.push({
5582
+ severity: monaco.MarkerSeverity.Warning,
5583
+ startLineNumber: lineNumber,
5584
+ startColumn: 1,
5585
+ endLineNumber: lineNumber,
5586
+ endColumn: line.length + 1,
5587
+ message: 'Unmatched opening curly brace',
5588
+ source: EXPR_LANG_ID
5589
+ });
5590
+ } else if (closeBraces > openBraces) {
5591
+ markers.push({
5592
+ severity: monaco.MarkerSeverity.Warning,
5593
+ startLineNumber: lineNumber,
5594
+ startColumn: 1,
5595
+ endLineNumber: lineNumber,
5596
+ endColumn: line.length + 1,
5597
+ message: 'Unmatched closing curly brace',
5598
+ source: EXPR_LANG_ID
5599
+ });
5600
+ }
5601
+ });
5602
+ return markers;
5603
+ }
5604
+ function countQuotesOutsideBlockComments(line) {
5605
+ var withoutBlockComments = line.replace(/\/\*[\s\S]*?\*\//g, '');
5606
+ return (withoutBlockComments.match(/'/g) || []).length;
5607
+ }
5608
+ function countDoubleQuotesOutsideBlockComments(line) {
5609
+ var withoutBlockComments = line.replace(/\/\*[\s\S]*?\*\//g, '');
5610
+ return (withoutBlockComments.match(/"/g) || []).length;
5611
+ }
5612
+
5613
+ var _templateObject$3, _templateObject2$3;
5614
+ var EXPR_LANG_ID$1 = 'expr';
5615
+ var SIZE_MAP$3 = {
5616
+ small: {
5617
+ className: 'ant-input-sm',
5618
+ top: 1,
5619
+ bottom: 1,
5620
+ minHeight: 24
5621
+ },
5622
+ middle: {
5623
+ className: 'ant-input-md',
5624
+ top: 1,
5625
+ bottom: 1,
5626
+ minHeight: 32
5627
+ },
5628
+ large: {
5629
+ className: 'ant-input-lg',
5630
+ top: 3,
5631
+ bottom: 2,
5632
+ minHeight: 40
5633
+ }
5634
+ };
5635
+ var themeMap$3 = {
5636
+ light: 'expr-light',
5637
+ dark: 'expr-dark'
5638
+ };
5639
+ var containerDisabledClassName$3 = /*#__PURE__*/css.css(_templateObject$3 || (_templateObject$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
5640
+ var containerReadOnlyClassName$3 = /*#__PURE__*/css.css(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
5641
+ function ExprEditor(props) {
5642
+ var id = uuid.v4();
5643
+ var className = props.className,
5644
+ maxHeight = props.maxHeight,
5645
+ fontSize = props.fontSize,
5646
+ _props$size = props.size,
5647
+ size = _props$size === void 0 ? 'middle' : _props$size,
5648
+ _props$theme = props.theme,
5649
+ theme = _props$theme === void 0 ? 'light' : _props$theme,
5650
+ _props$value = props.value,
5651
+ value = _props$value === void 0 ? '' : _props$value,
5652
+ placeholder = props.placeholder,
5653
+ _props$enableAutocomp = props.enableAutocomplete,
5654
+ enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
5655
+ _props$readOnly = props.readOnly,
5656
+ readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
5657
+ _props$disabled = props.disabled,
5658
+ disabled = _props$disabled === void 0 ? false : _props$disabled,
5659
+ onChange = props.onChange,
5660
+ onEnter = props.onEnter,
5661
+ onBlur = props.onBlur,
5662
+ onFocus = props.onFocus,
5663
+ editorDidMount = props.editorDidMount;
5664
+ var containerRef = React.useRef(null);
5665
+ var editorRef = React.useRef(null);
5666
+ var modelRef = React.useRef(null);
5667
+ var disposablesRef = React.useRef([]);
5668
+ React.useEffect(function () {
5669
+ // Register language
5670
+ if (!monaco.languages.getLanguages().some(function (lang) {
5671
+ return lang.id === EXPR_LANG_ID$1;
5672
+ })) {
5673
+ monaco.languages.register({
5674
+ id: EXPR_LANG_ID$1
5675
+ });
5676
+ monaco.languages.setMonarchTokensProvider(EXPR_LANG_ID$1, language$3);
5677
+ monaco.languages.setLanguageConfiguration(EXPR_LANG_ID$1, languageConfiguration$3);
5678
+ }
5679
+ // Register completion provider
5680
+ if (enableAutocomplete) {
5681
+ var disposable = monaco.languages.registerCompletionItemProvider(EXPR_LANG_ID$1, getExprCompletionProvider());
5682
+ disposablesRef.current.push(disposable);
5683
+ }
5684
+ return function () {
5685
+ disposablesRef.current.forEach(function (disposable) {
5686
+ return disposable.dispose();
5687
+ });
5688
+ disposablesRef.current = [];
5689
+ };
5690
+ }, [enableAutocomplete]);
5691
+ var handleEditorMount = function handleEditorMount(editor) {
5692
+ editorRef.current = editor;
5693
+ modelRef.current = editor.getModel();
5694
+ monaco.editor.defineTheme('expr-light', {
5695
+ base: 'vs',
5696
+ inherit: true,
5697
+ rules: [],
5698
+ colors: {
5699
+ 'editor.background': '#00000000',
5700
+ focusBorder: '#00000000'
5701
+ }
5702
+ });
5703
+ monaco.editor.defineTheme('expr-dark', {
5704
+ base: 'vs-dark',
5705
+ inherit: true,
5706
+ rules: [],
5707
+ colors: {
5708
+ 'editor.background': '#00000000',
5709
+ focusBorder: '#00000000'
5710
+ }
5711
+ });
5712
+ var isEditorFocused = editor.createContextKey('isEditorFocused' + id, false);
5713
+ editor.onDidBlurEditorWidget(function () {
5714
+ isEditorFocused.set(false);
5715
+ onBlur == null || onBlur(editor.getValue());
5716
+ var position = editor.getPosition();
5717
+ if (position) {
5718
+ var newSelection = new monaco.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
5719
+ editor.setSelection(newSelection);
5720
+ }
5721
+ });
5722
+ editor.onDidFocusEditorText(function () {
5723
+ isEditorFocused.set(true);
5724
+ onFocus == null || onFocus(editor.getValue());
5725
+ });
5726
+ // Auto-height
5727
+ var updateElementHeight = function updateElementHeight() {
5728
+ var containerDiv = containerRef.current;
5729
+ if (containerDiv !== null) {
5730
+ var pixelHeight = editor.getContentHeight();
5731
+ containerDiv.style.minHeight = pixelHeight + "px";
5732
+ containerDiv.style.width = '100%';
5733
+ var pixelWidth = containerDiv.clientWidth;
5734
+ editor.layout({
5735
+ width: pixelWidth,
5736
+ height: pixelHeight
5737
+ });
5738
+ }
5739
+ };
5740
+ editor.onDidContentSizeChange(updateElementHeight);
5741
+ updateElementHeight();
5742
+ // Disable search box
5743
+ monaco.editor.addKeybindingRule({
5744
+ keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF,
5745
+ command: null
5746
+ });
5747
+ // Shift+Enter for newline
5748
+ editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, function () {
5749
+ var position = editor.getPosition();
5750
+ if (position) {
5751
+ editor.executeEdits('shift-enter', [{
5752
+ range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
5753
+ text: '\n'
5754
+ }]);
5755
+ editor.setPosition({
5756
+ lineNumber: position.lineNumber + 1,
5757
+ column: 1
5758
+ });
5759
+ }
5760
+ }, 'isEditorFocused' + id);
5761
+ // Prevent default Enter
5762
+ monaco.editor.addKeybindingRule({
5763
+ keybinding: monaco.KeyCode.Enter,
5764
+ command: '-',
5765
+ when: '!suggestWidgetVisible'
5766
+ });
5767
+ // Custom Enter handler
5768
+ editor.addCommand(monaco.KeyCode.Enter, function () {
5769
+ onEnter == null || onEnter(editor.getValue());
5770
+ }, '!suggestWidgetVisible && isEditorFocused' + id);
5771
+ // Setup validation on content change using decorations (no marker hover clutter)
5772
+ var model = editor.getModel();
5773
+ var errorDecorations = [];
5774
+ if (model) {
5775
+ var updateDecorations = function updateDecorations() {
5776
+ var exprValue = model.getValue();
5777
+ var markers = validateExpr(exprValue);
5778
+ var newDecorations = markers.map(function (m) {
5779
+ return {
5780
+ range: new monaco.Range(m.startLineNumber, m.startColumn, m.endLineNumber, m.endColumn),
5781
+ options: {
5782
+ className: 'expr-error-squiggly',
5783
+ hoverMessage: {
5784
+ value: m.message
5785
+ },
5786
+ minimap: {
5787
+ color: '#e51400',
5788
+ position: 1
5789
+ },
5790
+ overviewRuler: {
5791
+ color: '#e51400',
5792
+ position: monaco.editor.OverviewRulerLane.Right
5793
+ }
5794
+ }
5795
+ };
5796
+ });
5797
+ errorDecorations = model.deltaDecorations(errorDecorations, newDecorations);
5798
+ };
5799
+ var validateDisposable = model.onDidChangeContent(updateDecorations);
5800
+ disposablesRef.current.push(validateDisposable);
5801
+ // Run initial validation
5802
+ updateDecorations();
5803
+ }
5804
+ // Inject CSS for the red squiggly underline
5805
+ var styleEl = document.createElement('style');
5806
+ styleEl.textContent = "\n .expr-error-squiggly {\n background: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 3' preserveAspectRatio='none'%3E%3Cpath d='M0,2.5 L1.5,1 L3,2.5 L4.5,1 L6,2.5' stroke='%23e51400' stroke-width='0.6' fill='none'/%3E%3C/svg%3E\") repeat-x left bottom;\n background-size: 6px 3px;\n padding-bottom: 3px;\n }\n ";
5807
+ document.head.appendChild(styleEl);
5808
+ disposablesRef.current.push({
5809
+ dispose: function dispose() {
5810
+ return styleEl.remove();
5811
+ }
5812
+ });
5813
+ editorDidMount == null || editorDidMount(editor);
5814
+ };
5815
+ var handleChange = function handleChange(newValue, _e) {
5816
+ onChange == null || onChange(newValue);
5817
+ };
5818
+ var themeValue = themeMap$3[theme];
5819
+ return React__default.createElement("div", {
5820
+ className: 'ant-input' + (size ? " " + SIZE_MAP$3[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$3 : '') + (readOnly ? " " + containerReadOnlyClassName$3 : '') + (className ? " " + className : ''),
5821
+ style: {
5822
+ display: 'block',
5823
+ resize: 'vertical',
5824
+ overflow: 'auto',
5825
+ minHeight: SIZE_MAP$3[size].minHeight,
5826
+ maxHeight: maxHeight
5827
+ }
5828
+ }, React__default.createElement("div", {
5829
+ ref: containerRef,
5830
+ style: {
5831
+ height: '100%'
5832
+ }
5833
+ }, React__default.createElement(MonacoEditor, {
5834
+ language: EXPR_LANG_ID$1,
5835
+ theme: themeValue,
5836
+ value: value,
5837
+ onChange: handleChange,
5838
+ options: {
5839
+ placeholder: placeholder,
5840
+ selectOnLineNumbers: true,
5841
+ fontSize: fontSize || 12,
5842
+ roundedSelection: false,
5843
+ scrollBeyondLastLine: false,
5844
+ readOnly: readOnly || disabled,
5845
+ minimap: {
5846
+ enabled: false
5847
+ },
5848
+ lineNumbers: 'off',
5849
+ lineNumbersMinChars: 0,
5850
+ glyphMargin: false,
5851
+ folding: false,
5852
+ lineDecorationsWidth: 0,
5853
+ overviewRulerLanes: 0,
5854
+ overviewRulerBorder: false,
5855
+ hideCursorInOverviewRuler: true,
5856
+ hover: {
5857
+ enabled: true,
5858
+ delay: 200
5859
+ },
5860
+ fixedOverflowWidgets: true,
5861
+ renderLineHighlight: 'none',
5862
+ renderValidationDecorations: 'on',
5863
+ scrollbar: {
5864
+ vertical: 'hidden',
5865
+ horizontal: 'auto'
5866
+ },
5867
+ automaticLayout: true,
5868
+ wordWrap: 'on'
5869
+ },
5870
+ editorDidMount: handleEditorMount
3888
5871
  })));
3889
5872
  }
3890
5873
 
5874
+ exports.ExprMonacoEditor = ExprEditor;
3891
5875
  exports.PromQLMonacoEditor = PromQLEditor;
3892
5876
  exports.SqlMonacoEditor = SqlEditor;
3893
5877
  exports.YamlMonacoEditor = YamlEditor;