@valtzu/codemirror-lang-el 1.0.0 → 1.1.0
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/CHANGELOG.md +6 -0
- package/README.md +10 -0
- package/dist/index.cjs +22 -4
- package/dist/index.d.cts +26 -6
- package/dist/index.d.ts +26 -6
- package/dist/index.js +22 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -36,6 +36,16 @@
|
|
|
36
36
|
|
|
37
37
|
### Installation
|
|
38
38
|
|
|
39
|
+
#### Web Component
|
|
40
|
+
|
|
41
|
+
If you're using Bootstrap UI, check the [Web Component](https://github.com/valtzu/symfony-expression-editor) to hide all CodeMirror stuff.
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
45
|
+
<script type="module" src="https://esm.sh/symfony-expression-editor@0.1.0"></script>
|
|
46
|
+
<textarea class="form-control" is="expression-editor" rows="1">'foobar' starts with 'foo'</textarea>
|
|
47
|
+
```
|
|
48
|
+
|
|
39
49
|
#### Symfony AssetMapper
|
|
40
50
|
|
|
41
51
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,8 @@ exports.ELScalar = void 0;
|
|
|
46
46
|
ELScalar["String"] = "string";
|
|
47
47
|
/** Equivalent to PHP `null` */
|
|
48
48
|
ELScalar["Null"] = "null";
|
|
49
|
+
/** Equivalent to PHP `array` */
|
|
50
|
+
ELScalar["Array"] = "array";
|
|
49
51
|
/** Equivalent to PHP `mixed` */
|
|
50
52
|
ELScalar["Any"] = "any";
|
|
51
53
|
})(exports.ELScalar || (exports.ELScalar = {}));
|
|
@@ -77,9 +79,12 @@ const createInfoElement = (html) => {
|
|
|
77
79
|
return dom;
|
|
78
80
|
};
|
|
79
81
|
const createCompletionInfoElement = (html) => {
|
|
82
|
+
if (!html) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
80
85
|
const dom = document.createElement("div");
|
|
81
86
|
dom.innerHTML = html;
|
|
82
|
-
return dom;
|
|
87
|
+
return { dom };
|
|
83
88
|
};
|
|
84
89
|
function resolveFunctionDefinition(node, state, config) {
|
|
85
90
|
var _a;
|
|
@@ -282,6 +287,19 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
282
287
|
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} <code>${identifier}</code> not found` });
|
|
283
288
|
}
|
|
284
289
|
break;
|
|
290
|
+
case BinaryExpression:
|
|
291
|
+
const operatorNode = node.node.getChild(OperatorKeyword);
|
|
292
|
+
if (operatorNode) {
|
|
293
|
+
const operator = state.sliceDoc(operatorNode.from, operatorNode.to);
|
|
294
|
+
if (operator === 'in') {
|
|
295
|
+
const rightArgument = node.node.lastChild;
|
|
296
|
+
const types = resolveTypes(state, rightArgument, config);
|
|
297
|
+
if (!types.has(exports.ELScalar.Array)) {
|
|
298
|
+
diagnostics.push({ from: rightArgument.from, to: rightArgument.to, severity: 'error', message: `<code>${exports.ELScalar.Array}</code> expected, got <code>${[...types].join('|')}</code>` });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
285
303
|
}
|
|
286
304
|
if (identifier && ((_f = node.node.parent) === null || _f === void 0 ? void 0 : _f.type.isError)) {
|
|
287
305
|
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
@@ -313,7 +331,7 @@ const autocompleteFunction = (x) => {
|
|
|
313
331
|
view.dispatch(Object.assign(Object.assign({}, autocomplete.insertCompletionText(view.state, `${x.name}()`, from, to)), { selection: { anchor: from + x.name.length + (((_b = (_a = x.args) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 ? 1 : 2) } }));
|
|
314
332
|
},
|
|
315
333
|
detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
|
|
316
|
-
info: () =>
|
|
334
|
+
info: () => createCompletionInfoElement(x.info),
|
|
317
335
|
type: "function",
|
|
318
336
|
});
|
|
319
337
|
};
|
|
@@ -322,7 +340,7 @@ const autocompleteIdentifier = (x) => {
|
|
|
322
340
|
return ({
|
|
323
341
|
label: x.name,
|
|
324
342
|
apply: x.name,
|
|
325
|
-
info: () =>
|
|
343
|
+
info: () => createCompletionInfoElement(x.info),
|
|
326
344
|
detail: x.detail || ((_a = x.type) === null || _a === void 0 ? void 0 : _a.join('|')),
|
|
327
345
|
type: 'variable',
|
|
328
346
|
});
|
|
@@ -335,7 +353,7 @@ function completeOperatorKeyword(state, config, tree, from, to, explicit) {
|
|
|
335
353
|
options: (_a = keywords.map(({ name, info, detail }) => ({
|
|
336
354
|
label: name,
|
|
337
355
|
apply: `${name} `,
|
|
338
|
-
info: () =>
|
|
356
|
+
info: () => createCompletionInfoElement(info),
|
|
339
357
|
detail,
|
|
340
358
|
type: "keyword"
|
|
341
359
|
}))) !== null && _a !== void 0 ? _a : [],
|
package/dist/index.d.cts
CHANGED
|
@@ -66,6 +66,8 @@ declare enum ELScalar {
|
|
|
66
66
|
String = "string",
|
|
67
67
|
/** Equivalent to PHP `null` */
|
|
68
68
|
Null = "null",
|
|
69
|
+
/** Equivalent to PHP `array` */
|
|
70
|
+
Array = "array",
|
|
69
71
|
/** Equivalent to PHP `mixed` */
|
|
70
72
|
Any = "any"
|
|
71
73
|
}
|
|
@@ -78,14 +80,18 @@ declare function expressionLanguageCompletion(context: CompletionContext): Compl
|
|
|
78
80
|
|
|
79
81
|
declare const complete_d_expressionLanguageCompletion: typeof expressionLanguageCompletion;
|
|
80
82
|
declare namespace complete_d {
|
|
81
|
-
export {
|
|
83
|
+
export {
|
|
84
|
+
complete_d_expressionLanguageCompletion as expressionLanguageCompletion,
|
|
85
|
+
};
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
declare const expressionLanguageLinter: _codemirror_state.Extension;
|
|
85
89
|
|
|
86
90
|
declare const linter_d_expressionLanguageLinter: typeof expressionLanguageLinter;
|
|
87
91
|
declare namespace linter_d {
|
|
88
|
-
export {
|
|
92
|
+
export {
|
|
93
|
+
linter_d_expressionLanguageLinter as expressionLanguageLinter,
|
|
94
|
+
};
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
declare const Function: number;
|
|
@@ -94,7 +100,9 @@ declare const Property: number;
|
|
|
94
100
|
declare const Variable: number;
|
|
95
101
|
|
|
96
102
|
declare const createInfoElement: (html: string) => HTMLDivElement;
|
|
97
|
-
declare const createCompletionInfoElement: (html: string) =>
|
|
103
|
+
declare const createCompletionInfoElement: (html: string) => {
|
|
104
|
+
dom: HTMLDivElement;
|
|
105
|
+
} | undefined;
|
|
98
106
|
declare function resolveFunctionDefinition(node: SyntaxNode | null, state: EditorState, config: ExpressionLanguageConfig): ELFunction | undefined;
|
|
99
107
|
declare const resolveIdentifier: (nodeTypeId: typeof Method | typeof Property | typeof Function | typeof Variable, identifier?: string, config?: {
|
|
100
108
|
identifiers?: ELIdentifier[];
|
|
@@ -112,7 +120,15 @@ declare const utils_d_resolveFunctionDefinition: typeof resolveFunctionDefinitio
|
|
|
112
120
|
declare const utils_d_resolveIdentifier: typeof resolveIdentifier;
|
|
113
121
|
declare const utils_d_resolveTypes: typeof resolveTypes;
|
|
114
122
|
declare namespace utils_d {
|
|
115
|
-
export {
|
|
123
|
+
export {
|
|
124
|
+
utils_d_createCompletionInfoElement as createCompletionInfoElement,
|
|
125
|
+
utils_d_createInfoElement as createInfoElement,
|
|
126
|
+
utils_d_getExpressionLanguageConfig as getExpressionLanguageConfig,
|
|
127
|
+
utils_d_keywords as keywords,
|
|
128
|
+
utils_d_resolveFunctionDefinition as resolveFunctionDefinition,
|
|
129
|
+
utils_d_resolveIdentifier as resolveIdentifier,
|
|
130
|
+
utils_d_resolveTypes as resolveTypes,
|
|
131
|
+
};
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
declare const cursorTooltipField: StateField<readonly Tooltip[]>;
|
|
@@ -123,10 +139,14 @@ declare const keywordTooltip: _codemirror_state.Extension & {
|
|
|
123
139
|
declare const tooltip_d_cursorTooltipField: typeof cursorTooltipField;
|
|
124
140
|
declare const tooltip_d_keywordTooltip: typeof keywordTooltip;
|
|
125
141
|
declare namespace tooltip_d {
|
|
126
|
-
export {
|
|
142
|
+
export {
|
|
143
|
+
tooltip_d_cursorTooltipField as cursorTooltipField,
|
|
144
|
+
tooltip_d_keywordTooltip as keywordTooltip,
|
|
145
|
+
};
|
|
127
146
|
}
|
|
128
147
|
|
|
129
148
|
declare const ELLanguage: LRLanguage;
|
|
130
149
|
declare function expressionlanguage(config?: ExpressionLanguageConfig, extensions?: Extension[]): LanguageSupport;
|
|
131
150
|
|
|
132
|
-
export {
|
|
151
|
+
export { ELLanguage, ELScalar, complete_d as _complete, linter_d as _linter, tooltip_d as _tooltip, utils_d as _utils, expressionlanguage };
|
|
152
|
+
export type { ELFunction, ELIdentifier, ELKeyword, ELParameter, ELType, ELTypeName, ExpressionLanguageConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ declare enum ELScalar {
|
|
|
66
66
|
String = "string",
|
|
67
67
|
/** Equivalent to PHP `null` */
|
|
68
68
|
Null = "null",
|
|
69
|
+
/** Equivalent to PHP `array` */
|
|
70
|
+
Array = "array",
|
|
69
71
|
/** Equivalent to PHP `mixed` */
|
|
70
72
|
Any = "any"
|
|
71
73
|
}
|
|
@@ -78,14 +80,18 @@ declare function expressionLanguageCompletion(context: CompletionContext): Compl
|
|
|
78
80
|
|
|
79
81
|
declare const complete_d_expressionLanguageCompletion: typeof expressionLanguageCompletion;
|
|
80
82
|
declare namespace complete_d {
|
|
81
|
-
export {
|
|
83
|
+
export {
|
|
84
|
+
complete_d_expressionLanguageCompletion as expressionLanguageCompletion,
|
|
85
|
+
};
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
declare const expressionLanguageLinter: _codemirror_state.Extension;
|
|
85
89
|
|
|
86
90
|
declare const linter_d_expressionLanguageLinter: typeof expressionLanguageLinter;
|
|
87
91
|
declare namespace linter_d {
|
|
88
|
-
export {
|
|
92
|
+
export {
|
|
93
|
+
linter_d_expressionLanguageLinter as expressionLanguageLinter,
|
|
94
|
+
};
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
declare const Function: number;
|
|
@@ -94,7 +100,9 @@ declare const Property: number;
|
|
|
94
100
|
declare const Variable: number;
|
|
95
101
|
|
|
96
102
|
declare const createInfoElement: (html: string) => HTMLDivElement;
|
|
97
|
-
declare const createCompletionInfoElement: (html: string) =>
|
|
103
|
+
declare const createCompletionInfoElement: (html: string) => {
|
|
104
|
+
dom: HTMLDivElement;
|
|
105
|
+
} | undefined;
|
|
98
106
|
declare function resolveFunctionDefinition(node: SyntaxNode | null, state: EditorState, config: ExpressionLanguageConfig): ELFunction | undefined;
|
|
99
107
|
declare const resolveIdentifier: (nodeTypeId: typeof Method | typeof Property | typeof Function | typeof Variable, identifier?: string, config?: {
|
|
100
108
|
identifiers?: ELIdentifier[];
|
|
@@ -112,7 +120,15 @@ declare const utils_d_resolveFunctionDefinition: typeof resolveFunctionDefinitio
|
|
|
112
120
|
declare const utils_d_resolveIdentifier: typeof resolveIdentifier;
|
|
113
121
|
declare const utils_d_resolveTypes: typeof resolveTypes;
|
|
114
122
|
declare namespace utils_d {
|
|
115
|
-
export {
|
|
123
|
+
export {
|
|
124
|
+
utils_d_createCompletionInfoElement as createCompletionInfoElement,
|
|
125
|
+
utils_d_createInfoElement as createInfoElement,
|
|
126
|
+
utils_d_getExpressionLanguageConfig as getExpressionLanguageConfig,
|
|
127
|
+
utils_d_keywords as keywords,
|
|
128
|
+
utils_d_resolveFunctionDefinition as resolveFunctionDefinition,
|
|
129
|
+
utils_d_resolveIdentifier as resolveIdentifier,
|
|
130
|
+
utils_d_resolveTypes as resolveTypes,
|
|
131
|
+
};
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
declare const cursorTooltipField: StateField<readonly Tooltip[]>;
|
|
@@ -123,10 +139,14 @@ declare const keywordTooltip: _codemirror_state.Extension & {
|
|
|
123
139
|
declare const tooltip_d_cursorTooltipField: typeof cursorTooltipField;
|
|
124
140
|
declare const tooltip_d_keywordTooltip: typeof keywordTooltip;
|
|
125
141
|
declare namespace tooltip_d {
|
|
126
|
-
export {
|
|
142
|
+
export {
|
|
143
|
+
tooltip_d_cursorTooltipField as cursorTooltipField,
|
|
144
|
+
tooltip_d_keywordTooltip as keywordTooltip,
|
|
145
|
+
};
|
|
127
146
|
}
|
|
128
147
|
|
|
129
148
|
declare const ELLanguage: LRLanguage;
|
|
130
149
|
declare function expressionlanguage(config?: ExpressionLanguageConfig, extensions?: Extension[]): LanguageSupport;
|
|
131
150
|
|
|
132
|
-
export {
|
|
151
|
+
export { ELLanguage, ELScalar, complete_d as _complete, linter_d as _linter, tooltip_d as _tooltip, utils_d as _utils, expressionlanguage };
|
|
152
|
+
export type { ELFunction, ELIdentifier, ELKeyword, ELParameter, ELType, ELTypeName, ExpressionLanguageConfig };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,8 @@ var ELScalar = /*@__PURE__*/(function (ELScalar) {
|
|
|
43
43
|
ELScalar["String"] = "string";
|
|
44
44
|
/** Equivalent to PHP `null` */
|
|
45
45
|
ELScalar["Null"] = "null";
|
|
46
|
+
/** Equivalent to PHP `array` */
|
|
47
|
+
ELScalar["Array"] = "array";
|
|
46
48
|
/** Equivalent to PHP `mixed` */
|
|
47
49
|
ELScalar["Any"] = "any";
|
|
48
50
|
return ELScalar})(ELScalar || (ELScalar = {}));
|
|
@@ -74,9 +76,12 @@ const createInfoElement = (html) => {
|
|
|
74
76
|
return dom;
|
|
75
77
|
};
|
|
76
78
|
const createCompletionInfoElement = (html) => {
|
|
79
|
+
if (!html) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
77
82
|
const dom = document.createElement("div");
|
|
78
83
|
dom.innerHTML = html;
|
|
79
|
-
return dom;
|
|
84
|
+
return { dom };
|
|
80
85
|
};
|
|
81
86
|
function resolveFunctionDefinition(node, state, config) {
|
|
82
87
|
var _a;
|
|
@@ -279,6 +284,19 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
279
284
|
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} <code>${identifier}</code> not found` });
|
|
280
285
|
}
|
|
281
286
|
break;
|
|
287
|
+
case BinaryExpression:
|
|
288
|
+
const operatorNode = node.node.getChild(OperatorKeyword);
|
|
289
|
+
if (operatorNode) {
|
|
290
|
+
const operator = state.sliceDoc(operatorNode.from, operatorNode.to);
|
|
291
|
+
if (operator === 'in') {
|
|
292
|
+
const rightArgument = node.node.lastChild;
|
|
293
|
+
const types = resolveTypes(state, rightArgument, config);
|
|
294
|
+
if (!types.has(ELScalar.Array)) {
|
|
295
|
+
diagnostics.push({ from: rightArgument.from, to: rightArgument.to, severity: 'error', message: `<code>${ELScalar.Array}</code> expected, got <code>${[...types].join('|')}</code>` });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
break;
|
|
282
300
|
}
|
|
283
301
|
if (identifier && ((_f = node.node.parent) === null || _f === void 0 ? void 0 : _f.type.isError)) {
|
|
284
302
|
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
@@ -310,7 +328,7 @@ const autocompleteFunction = (x) => {
|
|
|
310
328
|
view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, `${x.name}()`, from, to)), { selection: { anchor: from + x.name.length + (((_b = (_a = x.args) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 ? 1 : 2) } }));
|
|
311
329
|
},
|
|
312
330
|
detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
|
|
313
|
-
info: () =>
|
|
331
|
+
info: () => createCompletionInfoElement(x.info),
|
|
314
332
|
type: "function",
|
|
315
333
|
});
|
|
316
334
|
};
|
|
@@ -319,7 +337,7 @@ const autocompleteIdentifier = (x) => {
|
|
|
319
337
|
return ({
|
|
320
338
|
label: x.name,
|
|
321
339
|
apply: x.name,
|
|
322
|
-
info: () =>
|
|
340
|
+
info: () => createCompletionInfoElement(x.info),
|
|
323
341
|
detail: x.detail || ((_a = x.type) === null || _a === void 0 ? void 0 : _a.join('|')),
|
|
324
342
|
type: 'variable',
|
|
325
343
|
});
|
|
@@ -332,7 +350,7 @@ function completeOperatorKeyword(state, config, tree, from, to, explicit) {
|
|
|
332
350
|
options: (_a = keywords.map(({ name, info, detail }) => ({
|
|
333
351
|
label: name,
|
|
334
352
|
apply: `${name} `,
|
|
335
|
-
info: () =>
|
|
353
|
+
info: () => createCompletionInfoElement(info),
|
|
336
354
|
detail,
|
|
337
355
|
type: "keyword"
|
|
338
356
|
}))) !== null && _a !== void 0 ? _a : [],
|
package/package.json
CHANGED