@agentix-e/spel-editor 0.0.0 → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2026-07-12
6
+
7
+ ### Added
8
+ - Initial release of `@agentix-e/spel-editor`
9
+ - `<spel-editor>` Web Component with CodeMirror 6 integration
10
+ - Syntax highlighting via spel-ts Tokenizer + StreamLanguage adapter
11
+ - Auto-completion with keyword, operator, and context-aware suggestions
12
+ - Real-time diagnostics (syntax, semantic, and context validation)
13
+ - Hover tooltips showing node type information
14
+ - Non-invasive theming via 12 CSS custom properties
15
+ - Programmatic API: `getValue()`, `setValue()`, `validate()`, `format()`, `insertSnippet()`
16
+ - `change` event with `value` and `isValid` detail
17
+ - Framework-agnostic — works with React, Vue, Angular, Svelte, or plain HTML
18
+
19
+ [0.1.0]: https://github.com/AgentiX-E/spel-editor/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentiX-E
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,95 @@
1
1
  # @agentix-e/spel-editor
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@agentix-e/spel-editor`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
3
+ > Web-embeddable Spring Expression Language (SpEL) editor.
4
+ > Based on CodeMirror 6 + spel-ts v1.1.0. Framework-agnostic Web Component.
5
+
6
+ [![GitHub](https://img.shields.io/npm/v/@agentix-e/spel-editor)](https://www.npmjs.com/package/@agentix-e/spel-editor)
7
+
8
+ ## Quick Start
9
+
10
+ ```bash
11
+ npm install @agentix-e/spel-editor
12
+ ```
13
+
14
+ ```html
15
+ <spel-editor
16
+ placeholder="Enter SpEL expression..."
17
+ min-height="100px"
18
+ ></spel-editor>
19
+
20
+ <script type="module">
21
+ import '@agentix-e/spel-editor';
22
+
23
+ const editor = document.querySelector('spel-editor');
24
+ editor.addEventListener('change', (e) => {
25
+ console.log('Expression:', e.detail.value);
26
+ console.log('Valid:', e.detail.isValid);
27
+ });
28
+ </script>
29
+ ```
30
+
31
+ ## Features
32
+
33
+ - **Syntax highlighting** — Accurate token-level coloring powered by spel-ts Tokenizer
34
+ - **Auto-completion** Keyword, operator, variable, and context-aware suggestions
35
+ - **Real-time diagnostics** Syntax, semantic, and context validation
36
+ - **Hover tooltips** — Node type information on hover
37
+ - **Non-invasive theming** — 12 CSS custom properties for complete visual control
38
+ - **Framework agnostic** — Works with React, Vue, Angular, Svelte, or plain HTML
39
+
40
+ ## API Reference
41
+
42
+ ### Properties (Attributes)
43
+
44
+ | Property | Attribute | Type | Default | Description |
45
+ |----------|-----------|------|---------|-------------|
46
+ | `value` | `value` | `string` | `''` | SpEL expression value |
47
+ | `placeholder` | `placeholder` | `string` | `'Enter SpEL expression...'` | Placeholder text when editor is empty |
48
+ | `readonly` | `readonly` | `boolean` | `false` | Read-only mode (prevents editing) |
49
+ | `disabled` | `disabled` | `boolean` | `false` | Disabled mode (editor becomes inert) |
50
+ | `minHeight` | `min-height` | `string` | `'80px'` | Minimum editor height (CSS value) |
51
+ | `contextSchema` | — | `ContextSchema \| null` | `null` | Context schema for completions and diagnostics. Set via JavaScript only (not an HTML attribute) |
52
+
53
+ ### Methods
54
+
55
+ | Method | Returns | Description |
56
+ |--------|---------|-------------|
57
+ | `getValue()` | `string` | Get the current expression text from the editor |
58
+ | `setValue(value: string)` | `void` | Set the expression text programmatically |
59
+ | `validate()` | `SpelDiagnostic[]` | Get the current diagnostics from the debounced validation cache |
60
+ | `format()` | `void` | Format the current expression using SpelFormatter |
61
+ | `insertSnippet(snippet: string)` | `void` | Insert a text snippet at the current cursor position |
62
+ | `getEditorView()` | `EditorView \| null` | Get the underlying CodeMirror 6 EditorView instance |
63
+
64
+ ### Events
65
+
66
+ | Event | Detail Type | Description |
67
+ |-------|-------------|-------------|
68
+ | `change` | `SpelEditorDetail` | Fired when the expression value changes. Detail contains `{ value: string; isValid: boolean }` |
69
+ | `validate` | `{ diagnostics: SpelDiagnostic[] }` | Fired after debounced diagnostics complete. Detail contains the diagnostic results |
70
+
71
+ ### CSS Custom Properties
72
+
73
+ | Property | Default | Description |
74
+ |----------|---------|-------------|
75
+ | `--spel-bg` | `#ffffff` | Editor background |
76
+ | `--spel-font-family` | `'JetBrains Mono', monospace` | Editor font |
77
+ | `--spel-font-size` | `14px` | Editor font size |
78
+ | `--spel-line-height` | `1.6` | Editor line height |
79
+ | `--spel-cursor` | `#111827` | Cursor color |
80
+ | `--spel-line-highlight` | `#f3f4f6` | Active line highlight color |
81
+ | `--spel-selection-bg` | `#bfdbfe` | Selection background color |
82
+ | `--spel-gutter-bg` | `#f9fafb` | Gutter background |
83
+ | `--spel-gutter-fg` | `#9ca3af` | Gutter foreground (line numbers) |
84
+ | `--spel-border-width` | `1px` | Editor border width |
85
+ | `--spel-border-color` | `#d0d5dd` | Editor border color |
86
+ | `--spel-border-radius` | `6px` | Editor border radius |
87
+
88
+ ## License
89
+
90
+ MIT © AgentiX-E
91
+
92
+ ## Ecosystem
93
+
94
+ - [@agentix-e/spel-ts](https://github.com/AgentiX-E/spel-ts) — Core SpEL parser and evaluator
95
+ - [@agentix-e/nl2spel](https://github.com/AgentiX-E/nl2spel) — Natural language → SpEL generation (optional)
@@ -0,0 +1,57 @@
1
+ import * as lit from 'lit';
2
+ import { LitElement, PropertyValues } from 'lit';
3
+ import { EditorView } from '@codemirror/view';
4
+ import { ContextSchema, SpelDiagnostic } from '@agentix-e/spel-ts';
5
+ export { ContextSchema, SpelDiagnostic } from '@agentix-e/spel-ts';
6
+
7
+ /**
8
+ * `<spel-editor>` — Web-embeddable SpEL expression editor.
9
+ */
10
+ declare class SpelEditor extends LitElement {
11
+ #private;
12
+ static styles: lit.CSSResult;
13
+ value: string;
14
+ contextSchema: ContextSchema | null;
15
+ placeholder: string;
16
+ readonly: boolean;
17
+ disabled: boolean;
18
+ minHeight: string;
19
+ private containerEl;
20
+ render(): lit.TemplateResult<1>;
21
+ firstUpdated(): void;
22
+ updated(changed: PropertyValues): void;
23
+ connectedCallback(): void;
24
+ disconnectedCallback(): void;
25
+ /**
26
+ * Get the current expression text from the editor.
27
+ */
28
+ getValue(): string;
29
+ /**
30
+ * Set the expression text programmatically.
31
+ */
32
+ setValue(value: string): void;
33
+ /**
34
+ * Insert a text snippet at the current cursor position.
35
+ */
36
+ insertSnippet(snippet: string): void;
37
+ /**
38
+ * Get the current diagnostics from the debounced validation cache.
39
+ */
40
+ validate(): SpelDiagnostic[];
41
+ /**
42
+ * Format the current expression using SpelFormatter.
43
+ */
44
+ format(): void;
45
+ /**
46
+ * Get the underlying CodeMirror 6 EditorView instance.
47
+ */
48
+ getEditorView(): EditorView | null;
49
+ }
50
+
51
+ /** Event detail for 'change' event */
52
+ interface SpelEditorDetail {
53
+ value: string;
54
+ isValid: boolean;
55
+ }
56
+
57
+ export { SpelEditor, type SpelEditorDetail };
package/dist/index.js ADDED
@@ -0,0 +1,595 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __typeError = (msg) => {
4
+ throw TypeError(msg);
5
+ };
6
+ var __decorateClass = (decorators, target, key, kind) => {
7
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
9
+ if (decorator = decorators[i])
10
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
+ if (kind && result) __defProp(target, key, result);
12
+ return result;
13
+ };
14
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
15
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
16
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
17
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
18
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
19
+
20
+ // src/spel-editor.ts
21
+ import { LitElement, html, css } from "lit";
22
+ import { customElement, property, query } from "lit/decorators.js";
23
+ import { EditorView, keymap, placeholder as cmPlaceholder } from "@codemirror/view";
24
+ import { EditorState } from "@codemirror/state";
25
+ import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
26
+ import { closeBrackets, autocompletion } from "@codemirror/autocomplete";
27
+ import { linter } from "@codemirror/lint";
28
+
29
+ // src/cm6/spel-language.ts
30
+ import { LanguageSupport } from "@codemirror/language";
31
+
32
+ // src/cm6/spel-grammar.ts
33
+ import { StreamLanguage } from "@codemirror/language";
34
+ import { Tokenizer as SpelTokenizer, TokenKind } from "@agentix-e/spel-ts";
35
+ function tokenKindToStyle(kind) {
36
+ switch (kind) {
37
+ // Keywords
38
+ case TokenKind.LITERAL_NULL:
39
+ return "keyword";
40
+ case TokenKind.LITERAL_BOOLEAN:
41
+ return "bool";
42
+ case TokenKind.MATCHES:
43
+ case TokenKind.BETWEEN:
44
+ case TokenKind.INSTANCEOF:
45
+ case TokenKind.MOD:
46
+ case TokenKind.NEW:
47
+ return "keyword";
48
+ // Literals
49
+ case TokenKind.LITERAL_INT:
50
+ case TokenKind.LITERAL_LONG:
51
+ case TokenKind.LITERAL_FLOAT:
52
+ case TokenKind.LITERAL_DOUBLE:
53
+ case TokenKind.LITERAL_HEX:
54
+ return "number";
55
+ case TokenKind.LITERAL_STRING:
56
+ return "string";
57
+ // Variables
58
+ case TokenKind.IDENTIFIER:
59
+ return "variableName";
60
+ // Operators
61
+ case TokenKind.PLUS:
62
+ case TokenKind.MINUS:
63
+ case TokenKind.STAR:
64
+ case TokenKind.SLASH:
65
+ case TokenKind.PERCENT:
66
+ case TokenKind.POWER:
67
+ case TokenKind.INC:
68
+ case TokenKind.DEC:
69
+ case TokenKind.ASSIGN:
70
+ return "operator";
71
+ // Comparison
72
+ case TokenKind.EQ:
73
+ case TokenKind.NE:
74
+ case TokenKind.LT:
75
+ case TokenKind.LE:
76
+ case TokenKind.GT:
77
+ case TokenKind.GE:
78
+ case TokenKind.AND:
79
+ case TokenKind.OR:
80
+ case TokenKind.NOT:
81
+ return "operator";
82
+ // Type/Bean references
83
+ case TokenKind.HASH:
84
+ case TokenKind.AT:
85
+ case TokenKind.AMP_AT:
86
+ return "typeName";
87
+ // Punctuation
88
+ case TokenKind.LPAREN:
89
+ case TokenKind.RPAREN:
90
+ case TokenKind.LBRACKET:
91
+ case TokenKind.RBRACKET:
92
+ case TokenKind.LBRACE:
93
+ case TokenKind.RBRACE:
94
+ case TokenKind.COMMA:
95
+ case TokenKind.COLON:
96
+ case TokenKind.DOT:
97
+ case TokenKind.SAFE_NAV:
98
+ case TokenKind.QMARK:
99
+ case TokenKind.ELVIS:
100
+ case TokenKind.DOTDOT:
101
+ return "punctuation";
102
+ // Selection/Projection
103
+ case TokenKind.PROJECTION:
104
+ case TokenKind.SELECTION:
105
+ case TokenKind.SELECT_FIRST:
106
+ case TokenKind.SELECT_LAST:
107
+ return "operatorKeyword";
108
+ // Type
109
+ case TokenKind.TYPE_START:
110
+ return "typeName";
111
+ default:
112
+ return "";
113
+ }
114
+ }
115
+ function createSpelStreamParser() {
116
+ let _tokenizer = null;
117
+ let _tokens = [];
118
+ let _tokenIndex = 0;
119
+ return StreamLanguage.define({
120
+ startState: () => null,
121
+ token: (stream) => {
122
+ if (!_tokenizer || _tokenIndex === 0) {
123
+ _tokenizer = new SpelTokenizer(stream.string);
124
+ let rawTokens;
125
+ try {
126
+ rawTokens = _tokenizer.tokenize();
127
+ } catch {
128
+ _tokens = [];
129
+ _tokenIndex = 0;
130
+ stream.skipToEnd();
131
+ return null;
132
+ }
133
+ _tokens = [];
134
+ _tokenIndex = 0;
135
+ for (let i = 0; i < rawTokens.length - 1; i++) {
136
+ const tok = rawTokens[i];
137
+ const style = tokenKindToStyle(tok.kind);
138
+ if (tok.kind === TokenKind.IDENTIFIER) {
139
+ const prevTok = i > 0 ? rawTokens[i - 1] : null;
140
+ if (prevTok?.kind === TokenKind.HASH) {
141
+ _tokens.push({
142
+ from: tok.startPos,
143
+ to: tok.endPos,
144
+ style: "variableName"
145
+ });
146
+ continue;
147
+ }
148
+ if (prevTok?.kind === TokenKind.DOT || prevTok?.kind === TokenKind.SAFE_NAV) {
149
+ _tokens.push({
150
+ from: tok.startPos,
151
+ to: tok.endPos,
152
+ style: "propertyName"
153
+ });
154
+ continue;
155
+ }
156
+ }
157
+ _tokens.push({ from: tok.startPos, to: tok.endPos, style });
158
+ }
159
+ }
160
+ while (_tokenIndex < _tokens.length) {
161
+ const t = _tokens[_tokenIndex];
162
+ if (t.from >= stream.pos) {
163
+ stream.pos = t.to;
164
+ _tokenIndex++;
165
+ return t.style || null;
166
+ }
167
+ _tokenIndex++;
168
+ }
169
+ stream.skipToEnd();
170
+ _tokenIndex = 0;
171
+ return null;
172
+ }
173
+ });
174
+ }
175
+
176
+ // src/cm6/spel-language.ts
177
+ function spelLanguage() {
178
+ return new LanguageSupport(createSpelStreamParser());
179
+ }
180
+
181
+ // src/cm6/completion-source.ts
182
+ import "@codemirror/autocomplete";
183
+ import { SpelCompletionEngine } from "@agentix-e/spel-ts";
184
+ function spelCompletion(getContextSchema) {
185
+ return (context) => {
186
+ const expression = context.state.sliceDoc();
187
+ const position = context.pos;
188
+ const schema = getContextSchema?.() ?? void 0;
189
+ const items = SpelCompletionEngine.getCompletions(expression, position, schema);
190
+ const validFor = /\w*/;
191
+ return {
192
+ from: context.matchBefore(validFor)?.from ?? position,
193
+ options: items.map((item) => mapToCM6Completion(item)),
194
+ // Allow completions at any position
195
+ validFor: () => true
196
+ };
197
+ };
198
+ }
199
+ function mapToCM6Completion(item) {
200
+ const type = mapKindToCM6Type(item.kind);
201
+ return {
202
+ label: item.label,
203
+ type,
204
+ detail: item.detail,
205
+ info: item.documentation,
206
+ apply: item.insertText,
207
+ // Higher priority items appear first
208
+ boost: item.sortPriority / 100
209
+ };
210
+ }
211
+ function mapKindToCM6Type(kind) {
212
+ switch (kind) {
213
+ case "keyword":
214
+ return "keyword";
215
+ case "operator":
216
+ return "operator";
217
+ case "variable":
218
+ return "variable";
219
+ case "property":
220
+ return "property";
221
+ case "method":
222
+ return "method";
223
+ case "function":
224
+ return "function";
225
+ case "type":
226
+ return "type";
227
+ default:
228
+ return "text";
229
+ }
230
+ }
231
+
232
+ // src/cm6/lint-source.ts
233
+ import "@codemirror/lint";
234
+ import {
235
+ SpelDiagnosticEngine,
236
+ DiagnosticSeverity
237
+ } from "@agentix-e/spel-ts";
238
+ function spelLint(getContextSchema) {
239
+ return (view) => {
240
+ const expression = view.state.sliceDoc();
241
+ const schema = getContextSchema?.() ?? void 0;
242
+ if (expression.trim().length === 0) return [];
243
+ const diagnostics = SpelDiagnosticEngine.validate(expression, schema);
244
+ return diagnostics.map((d) => mapToCM6Diagnostic(d));
245
+ };
246
+ }
247
+ function mapToCM6Diagnostic(d) {
248
+ return {
249
+ from: d.from,
250
+ to: d.to,
251
+ message: d.message,
252
+ severity: mapSeverity(d.severity),
253
+ source: d.code
254
+ };
255
+ }
256
+ function mapSeverity(sev) {
257
+ switch (sev) {
258
+ case DiagnosticSeverity.ERROR:
259
+ return "error";
260
+ case DiagnosticSeverity.WARNING:
261
+ return "warning";
262
+ case DiagnosticSeverity.INFO:
263
+ return "info";
264
+ }
265
+ }
266
+
267
+ // src/cm6/hover-tooltip.ts
268
+ import { hoverTooltip } from "@codemirror/view";
269
+ import {
270
+ AstWalker,
271
+ NodeType,
272
+ SpelExpressionParser
273
+ } from "@agentix-e/spel-ts";
274
+ function spelHover() {
275
+ return hoverTooltip(createHoverSource());
276
+ }
277
+ function createHoverSource() {
278
+ return (view, pos) => {
279
+ const expression = view.state.sliceDoc();
280
+ if (expression.trim().length === 0) return null;
281
+ try {
282
+ const parser = new SpelExpressionParser();
283
+ const ast = parser.parseRaw(expression);
284
+ const node = AstWalker.findNodeAt(ast, pos);
285
+ if (!node) return null;
286
+ const info = getNodeInfo(node);
287
+ if (!info) return null;
288
+ return {
289
+ pos: node.startPos,
290
+ end: node.endPos,
291
+ create() {
292
+ const dom = document.createElement("div");
293
+ dom.style.cssText = "padding: 4px 8px; font-size: 13px; max-width: 300px;";
294
+ dom.textContent = info;
295
+ return { dom };
296
+ }
297
+ };
298
+ } catch {
299
+ return null;
300
+ }
301
+ };
302
+ }
303
+ function getNodeInfo(node) {
304
+ switch (node.nodeType) {
305
+ case NodeType.VARIABLE_REFERENCE:
306
+ return `Variable: #${node.getVariableName()}`;
307
+ case NodeType.PROPERTY_OR_FIELD_REFERENCE:
308
+ return `Property: .${node.getName()}`;
309
+ case NodeType.BEAN_REFERENCE:
310
+ return `Spring Bean: @${node.getBeanName()}`;
311
+ case NodeType.TYPE_REFERENCE:
312
+ return `Type: T(${node.getTypeName()})`;
313
+ default:
314
+ return null;
315
+ }
316
+ }
317
+
318
+ // src/spel-editor.ts
319
+ import { SpelFormatter, SpelDiagnosticEngine as SpelDiagnosticEngine2 } from "@agentix-e/spel-ts";
320
+ var EDITOR_STYLES = css`
321
+ :host {
322
+ display: block;
323
+ }
324
+ .cm-container {
325
+ overflow: hidden;
326
+ }
327
+ .cm-editor {
328
+ height: 100%;
329
+ font-family: var(--spel-font-family, 'JetBrains Mono', monospace);
330
+ font-size: var(--spel-font-size, 14px);
331
+ line-height: var(--spel-line-height, 1.6);
332
+ }
333
+ .cm-editor.cm-focused {
334
+ outline: none;
335
+ }
336
+ .cm-editor .cm-scroller {
337
+ overflow: auto;
338
+ }
339
+ .cm-editor .cm-content {
340
+ caret-color: var(--spel-cursor, #111827);
341
+ }
342
+ .cm-editor .cm-cursor,
343
+ .cm-editor .cm-dropCursor {
344
+ border-left-color: var(--spel-cursor, #111827);
345
+ }
346
+ .cm-editor .cm-activeLine {
347
+ background-color: var(--spel-line-highlight, #f3f4f6);
348
+ }
349
+ .cm-editor .cm-selectionBackground,
350
+ .cm-editor.cm-focused .cm-selectionBackground {
351
+ background: var(--spel-selection-bg, #bfdbfe) !important;
352
+ }
353
+ .cm-editor .cm-gutters {
354
+ background: var(--spel-gutter-bg, #f9fafb);
355
+ color: var(--spel-gutter-fg, #9ca3af);
356
+ border: none;
357
+ }
358
+ `;
359
+ var _editorView, _diagnosticCache, _diagnosticDebounceTimer, _SpelEditor_instances, scheduleDiagnostics_fn, runDiagnostics_fn, createEditor_fn, updateEditorState_fn, fireChange_fn;
360
+ var SpelEditor = class extends LitElement {
361
+ constructor() {
362
+ super(...arguments);
363
+ __privateAdd(this, _SpelEditor_instances);
364
+ this.value = "";
365
+ this.contextSchema = null;
366
+ this.placeholder = "Enter SpEL expression...";
367
+ this.readonly = false;
368
+ this.disabled = false;
369
+ this.minHeight = "80px";
370
+ __privateAdd(this, _editorView, null);
371
+ __privateAdd(this, _diagnosticCache, []);
372
+ __privateAdd(this, _diagnosticDebounceTimer, null);
373
+ }
374
+ render() {
375
+ return html`
376
+ <div
377
+ class="cm-container"
378
+ role="textbox"
379
+ aria-label=${this.placeholder}
380
+ aria-readonly=${this.readonly ? "true" : "false"}
381
+ aria-disabled=${this.disabled ? "true" : "false"}
382
+ tabindex="0"
383
+ style="
384
+ min-height: ${this.minHeight};
385
+ border: var(--spel-border-width, 1px) solid var(--spel-border-color, #d0d5dd);
386
+ border-radius: var(--spel-border-radius, 6px);
387
+ background: var(--spel-bg, #ffffff);
388
+ "
389
+ ></div>
390
+ `;
391
+ }
392
+ firstUpdated() {
393
+ __privateMethod(this, _SpelEditor_instances, createEditor_fn).call(this);
394
+ }
395
+ updated(changed) {
396
+ if (changed.has("disabled") || changed.has("readonly")) {
397
+ __privateMethod(this, _SpelEditor_instances, updateEditorState_fn).call(this);
398
+ }
399
+ if (!__privateGet(this, _editorView) && this.containerEl) {
400
+ __privateMethod(this, _SpelEditor_instances, createEditor_fn).call(this);
401
+ }
402
+ if (changed.has("contextSchema")) {
403
+ __privateMethod(this, _SpelEditor_instances, scheduleDiagnostics_fn).call(this);
404
+ }
405
+ }
406
+ connectedCallback() {
407
+ super.connectedCallback();
408
+ if (this.hasUpdated && !__privateGet(this, _editorView)) {
409
+ void this.updateComplete.then(() => {
410
+ if (!__privateGet(this, _editorView)) {
411
+ __privateMethod(this, _SpelEditor_instances, createEditor_fn).call(this);
412
+ }
413
+ });
414
+ }
415
+ }
416
+ disconnectedCallback() {
417
+ super.disconnectedCallback();
418
+ if (__privateGet(this, _diagnosticDebounceTimer)) {
419
+ clearTimeout(__privateGet(this, _diagnosticDebounceTimer));
420
+ __privateSet(this, _diagnosticDebounceTimer, null);
421
+ }
422
+ __privateGet(this, _editorView)?.destroy();
423
+ __privateSet(this, _editorView, null);
424
+ }
425
+ /**
426
+ * Get the current expression text from the editor.
427
+ */
428
+ getValue() {
429
+ return __privateGet(this, _editorView)?.state.sliceDoc() ?? this.value;
430
+ }
431
+ /**
432
+ * Set the expression text programmatically.
433
+ */
434
+ setValue(value) {
435
+ this.value = value;
436
+ if (__privateGet(this, _editorView)) {
437
+ __privateGet(this, _editorView).dispatch({
438
+ changes: {
439
+ from: 0,
440
+ to: __privateGet(this, _editorView).state.doc.length,
441
+ insert: value
442
+ },
443
+ selection: { anchor: value.length }
444
+ });
445
+ __privateMethod(this, _SpelEditor_instances, scheduleDiagnostics_fn).call(this);
446
+ }
447
+ }
448
+ /**
449
+ * Insert a text snippet at the current cursor position.
450
+ */
451
+ insertSnippet(snippet) {
452
+ if (!__privateGet(this, _editorView)) return;
453
+ const { from, to } = __privateGet(this, _editorView).state.selection.main;
454
+ __privateGet(this, _editorView).dispatch({
455
+ changes: { from, to, insert: snippet },
456
+ selection: { anchor: from + snippet.length }
457
+ });
458
+ }
459
+ /**
460
+ * Get the current diagnostics from the debounced validation cache.
461
+ */
462
+ validate() {
463
+ return __privateGet(this, _diagnosticCache);
464
+ }
465
+ /**
466
+ * Format the current expression using SpelFormatter.
467
+ */
468
+ format() {
469
+ if (!__privateGet(this, _editorView)) return;
470
+ const current = __privateGet(this, _editorView).state.sliceDoc();
471
+ const formatted = SpelFormatter.format(current);
472
+ if (formatted && formatted !== current) {
473
+ __privateGet(this, _editorView).dispatch({
474
+ changes: {
475
+ from: 0,
476
+ to: __privateGet(this, _editorView).state.doc.length,
477
+ insert: formatted
478
+ },
479
+ selection: { anchor: formatted.length }
480
+ });
481
+ }
482
+ }
483
+ /**
484
+ * Get the underlying CodeMirror 6 EditorView instance.
485
+ */
486
+ getEditorView() {
487
+ return __privateGet(this, _editorView);
488
+ }
489
+ };
490
+ _editorView = new WeakMap();
491
+ _diagnosticCache = new WeakMap();
492
+ _diagnosticDebounceTimer = new WeakMap();
493
+ _SpelEditor_instances = new WeakSet();
494
+ /**
495
+ * Schedule a debounced diagnostic run (300ms).
496
+ * Avoids redundant computation on rapid typing.
497
+ */
498
+ scheduleDiagnostics_fn = function() {
499
+ if (__privateGet(this, _diagnosticDebounceTimer)) {
500
+ clearTimeout(__privateGet(this, _diagnosticDebounceTimer));
501
+ }
502
+ __privateSet(this, _diagnosticDebounceTimer, setTimeout(() => {
503
+ __privateMethod(this, _SpelEditor_instances, runDiagnostics_fn).call(this);
504
+ __privateSet(this, _diagnosticDebounceTimer, null);
505
+ }, 300));
506
+ };
507
+ /**
508
+ * Populate diagnosticCache by running validation.
509
+ * Dispatches a `validate` event after diagnostics complete.
510
+ */
511
+ runDiagnostics_fn = function() {
512
+ if (!__privateGet(this, _editorView)) return;
513
+ const expr = __privateGet(this, _editorView).state.sliceDoc();
514
+ if (expr.trim().length === 0) {
515
+ __privateSet(this, _diagnosticCache, []);
516
+ return;
517
+ }
518
+ __privateSet(this, _diagnosticCache, SpelDiagnosticEngine2.validate(expr, this.contextSchema ?? void 0));
519
+ this.dispatchEvent(
520
+ new CustomEvent("validate", {
521
+ detail: { diagnostics: __privateGet(this, _diagnosticCache) },
522
+ bubbles: true,
523
+ composed: true
524
+ })
525
+ );
526
+ };
527
+ createEditor_fn = function() {
528
+ const extensions = [
529
+ spelLanguage(),
530
+ autocompletion({ override: [spelCompletion(() => this.contextSchema)] }),
531
+ linter(spelLint(() => this.contextSchema)),
532
+ spelHover(),
533
+ history(),
534
+ closeBrackets(),
535
+ keymap.of([...defaultKeymap, ...historyKeymap]),
536
+ cmPlaceholder(this.placeholder),
537
+ EditorView.updateListener.of((update) => {
538
+ if (update.docChanged) {
539
+ this.value = update.state.sliceDoc();
540
+ __privateMethod(this, _SpelEditor_instances, fireChange_fn).call(this);
541
+ __privateMethod(this, _SpelEditor_instances, scheduleDiagnostics_fn).call(this);
542
+ }
543
+ })
544
+ ];
545
+ if (this.readonly || this.disabled) {
546
+ extensions.push(EditorState.readOnly.of(true));
547
+ }
548
+ __privateSet(this, _editorView, new EditorView({
549
+ state: EditorState.create({ doc: this.value, extensions }),
550
+ parent: this.containerEl
551
+ }));
552
+ __privateMethod(this, _SpelEditor_instances, scheduleDiagnostics_fn).call(this);
553
+ };
554
+ updateEditorState_fn = function() {
555
+ __privateGet(this, _editorView)?.destroy();
556
+ __privateSet(this, _editorView, null);
557
+ __privateMethod(this, _SpelEditor_instances, createEditor_fn).call(this);
558
+ };
559
+ fireChange_fn = function() {
560
+ const expr = this.value.trim();
561
+ const syntaxDiags = expr.length === 0 ? [] : SpelDiagnosticEngine2.checkSyntax(this.value);
562
+ const detail = {
563
+ value: this.value,
564
+ isValid: syntaxDiags.length === 0
565
+ };
566
+ this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
567
+ };
568
+ SpelEditor.styles = EDITOR_STYLES;
569
+ __decorateClass([
570
+ property({ type: String })
571
+ ], SpelEditor.prototype, "value", 2);
572
+ __decorateClass([
573
+ property({ type: Object, attribute: false })
574
+ ], SpelEditor.prototype, "contextSchema", 2);
575
+ __decorateClass([
576
+ property({ type: String })
577
+ ], SpelEditor.prototype, "placeholder", 2);
578
+ __decorateClass([
579
+ property({ type: Boolean, reflect: true })
580
+ ], SpelEditor.prototype, "readonly", 2);
581
+ __decorateClass([
582
+ property({ type: Boolean, reflect: true })
583
+ ], SpelEditor.prototype, "disabled", 2);
584
+ __decorateClass([
585
+ property({ type: String, attribute: "min-height" })
586
+ ], SpelEditor.prototype, "minHeight", 2);
587
+ __decorateClass([
588
+ query(".cm-container")
589
+ ], SpelEditor.prototype, "containerEl", 2);
590
+ SpelEditor = __decorateClass([
591
+ customElement("spel-editor")
592
+ ], SpelEditor);
593
+ export {
594
+ SpelEditor
595
+ };
package/package.json CHANGED
@@ -1,10 +1,81 @@
1
1
  {
2
2
  "name": "@agentix-e/spel-editor",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @agentix-e/spel-editor",
3
+ "version": "0.1.1",
4
+ "description": "Web-embeddable Spring Expression Language (SpEL) editor — CodeMirror 6 + spel-ts powered",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/",
16
+ "README.md",
17
+ "LICENSE",
18
+ "CHANGELOG.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup src/index.ts --format esm --dts --clean",
22
+ "test": "vitest run --coverage",
23
+ "test:watch": "vitest",
24
+ "typecheck": "tsc --noEmit",
25
+ "format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts'",
26
+ "format:check": "prettier --check 'src/**/*.ts' 'tests/**/*.ts'",
27
+ "clean": "rm -rf dist",
28
+ "prepublishOnly": "pnpm build && pnpm test && pnpm typecheck"
29
+ },
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "dependencies": {
34
+ "@agentix-e/spel-ts": "^1.1.0",
35
+ "@codemirror/autocomplete": "^6.0.0",
36
+ "@codemirror/commands": "^6.0.0",
37
+ "@codemirror/language": "^6.0.0",
38
+ "@codemirror/lint": "^6.0.0",
39
+ "@codemirror/state": "^6.0.0",
40
+ "@codemirror/view": "^6.0.0",
41
+ "lit": "^3.0.0"
42
+ },
43
+ "peerDependencies": {
44
+ "@agentix-e/nl2spel": ">=1.1.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@agentix-e/nl2spel": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "devDependencies": {
52
+ "@vitest/coverage-v8": "^3.0.0",
53
+ "jsdom": "^29.1.1",
54
+ "prettier": "^3.9.5",
55
+ "tsup": "^8.0.0",
56
+ "typescript": "^5.8.3",
57
+ "vitest": "^3.0.0"
58
+ },
5
59
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
60
+ "spel",
61
+ "editor",
62
+ "code-editor",
63
+ "expression-language",
64
+ "spring",
65
+ "codemirror",
66
+ "web-component"
67
+ ],
68
+ "license": "MIT",
69
+ "author": "AgentiX-E",
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/AgentiX-E/spel-editor.git"
73
+ },
74
+ "bugs": {
75
+ "url": "https://github.com/AgentiX-E/spel-editor/issues"
76
+ },
77
+ "homepage": "https://github.com/AgentiX-E/spel-editor#readme",
78
+ "publishConfig": {
79
+ "access": "public"
80
+ }
10
81
  }