@seljs/editor 1.0.0 → 1.0.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/completion/completion-items.cjs +36 -0
  3. package/dist/completion/completion-items.mjs +32 -0
  4. package/dist/completion/index.cjs +1 -0
  5. package/dist/completion/index.d.mts +1 -0
  6. package/dist/completion/index.mjs +2 -0
  7. package/dist/completion/schema-completion.cjs +182 -0
  8. package/dist/completion/schema-completion.d.cts +25 -0
  9. package/dist/completion/schema-completion.d.mts +25 -0
  10. package/dist/completion/schema-completion.mjs +181 -0
  11. package/dist/completion/tree-context.cjs +108 -0
  12. package/dist/completion/tree-context.mjs +108 -0
  13. package/dist/editor/create-editor.cjs +16 -0
  14. package/dist/editor/create-editor.d.cts +7 -0
  15. package/dist/editor/create-editor.d.mts +7 -0
  16. package/dist/editor/create-editor.mjs +16 -0
  17. package/dist/editor/editor-config.cjs +49 -0
  18. package/dist/editor/editor-config.d.cts +7 -0
  19. package/dist/editor/editor-config.d.mts +7 -0
  20. package/dist/editor/editor-config.mjs +49 -0
  21. package/dist/editor/index.cjs +3 -0
  22. package/dist/editor/index.d.cts +6 -0
  23. package/dist/editor/index.d.mts +6 -0
  24. package/dist/editor/index.mjs +4 -0
  25. package/dist/editor/theme.cjs +35 -0
  26. package/dist/editor/theme.d.cts +7 -0
  27. package/dist/editor/theme.d.mts +7 -0
  28. package/dist/editor/theme.mjs +34 -0
  29. package/dist/editor/type-display.cjs +71 -0
  30. package/dist/editor/type-display.mjs +71 -0
  31. package/dist/editor/types.d.cts +31 -0
  32. package/dist/editor/types.d.mts +31 -0
  33. package/dist/index.cjs +20 -0
  34. package/dist/index.d.cts +10 -0
  35. package/dist/index.d.mts +10 -0
  36. package/dist/index.mjs +11 -0
  37. package/dist/language/semantic-highlighter.cjs +55 -0
  38. package/dist/language/semantic-highlighter.mjs +55 -0
  39. package/dist/language/tokenizer-config.cjs +9 -0
  40. package/dist/language/tokenizer-config.d.cts +12 -0
  41. package/dist/language/tokenizer-config.d.mts +12 -0
  42. package/dist/language/tokenizer-config.mjs +9 -0
  43. package/dist/linting/diagnostic-mapper.cjs +37 -0
  44. package/dist/linting/{diagnostic-mapper.d.ts → diagnostic-mapper.d.cts} +7 -6
  45. package/dist/linting/diagnostic-mapper.d.mts +29 -0
  46. package/dist/linting/diagnostic-mapper.mjs +37 -0
  47. package/dist/linting/index.cjs +2 -0
  48. package/dist/linting/index.d.mts +2 -0
  49. package/dist/linting/index.mjs +3 -0
  50. package/dist/linting/sel-linter.cjs +28 -0
  51. package/dist/linting/sel-linter.d.cts +13 -0
  52. package/dist/linting/sel-linter.d.mts +13 -0
  53. package/dist/linting/sel-linter.mjs +28 -0
  54. package/package.json +29 -22
  55. package/dist/completion/completion-items.d.ts +0 -8
  56. package/dist/completion/completion-items.d.ts.map +0 -1
  57. package/dist/completion/completion-items.js +0 -29
  58. package/dist/completion/index.d.ts +0 -2
  59. package/dist/completion/index.d.ts.map +0 -1
  60. package/dist/completion/index.js +0 -1
  61. package/dist/completion/schema-completion.d.ts +0 -22
  62. package/dist/completion/schema-completion.d.ts.map +0 -1
  63. package/dist/completion/schema-completion.js +0 -220
  64. package/dist/completion/tree-context.d.ts +0 -23
  65. package/dist/completion/tree-context.d.ts.map +0 -1
  66. package/dist/completion/tree-context.js +0 -154
  67. package/dist/editor/create-editor.d.ts +0 -4
  68. package/dist/editor/create-editor.d.ts.map +0 -1
  69. package/dist/editor/create-editor.js +0 -14
  70. package/dist/editor/editor-config.d.ts +0 -4
  71. package/dist/editor/editor-config.d.ts.map +0 -1
  72. package/dist/editor/editor-config.js +0 -64
  73. package/dist/editor/index.d.ts +0 -6
  74. package/dist/editor/index.d.ts.map +0 -1
  75. package/dist/editor/index.js +0 -3
  76. package/dist/editor/theme.d.ts +0 -3
  77. package/dist/editor/theme.d.ts.map +0 -1
  78. package/dist/editor/theme.js +0 -43
  79. package/dist/editor/type-display.d.ts +0 -4
  80. package/dist/editor/type-display.d.ts.map +0 -1
  81. package/dist/editor/type-display.js +0 -75
  82. package/dist/editor/types.d.ts +0 -28
  83. package/dist/editor/types.d.ts.map +0 -1
  84. package/dist/editor/types.js +0 -1
  85. package/dist/index.d.ts +0 -5
  86. package/dist/index.d.ts.map +0 -1
  87. package/dist/index.js +0 -4
  88. package/dist/language/index.d.ts +0 -2
  89. package/dist/language/index.d.ts.map +0 -1
  90. package/dist/language/index.js +0 -1
  91. package/dist/language/semantic-highlighter.d.ts +0 -4
  92. package/dist/language/semantic-highlighter.d.ts.map +0 -1
  93. package/dist/language/semantic-highlighter.js +0 -76
  94. package/dist/language/tokenizer-config.d.ts +0 -9
  95. package/dist/language/tokenizer-config.d.ts.map +0 -1
  96. package/dist/language/tokenizer-config.js +0 -6
  97. package/dist/linting/diagnostic-mapper.d.ts.map +0 -1
  98. package/dist/linting/diagnostic-mapper.js +0 -46
  99. package/dist/linting/index.d.ts +0 -3
  100. package/dist/linting/index.d.ts.map +0 -1
  101. package/dist/linting/index.js +0 -2
  102. package/dist/linting/sel-linter.d.ts +0 -12
  103. package/dist/linting/sel-linter.d.ts.map +0 -1
  104. package/dist/linting/sel-linter.js +0 -28
@@ -1,28 +0,0 @@
1
- import type { SELDiagnostic } from "../linting/diagnostic-mapper";
2
- import type { Extension } from "@codemirror/state";
3
- import type { SELSchema } from "@seljs/schema";
4
- export interface SELEditorConfig {
5
- /** Container element to mount into */
6
- parent: HTMLElement;
7
- /** Schema driving autocomplete and syntax highlighting */
8
- schema: SELSchema;
9
- /** Initial expression value */
10
- value?: string;
11
- /** Called on every expression change */
12
- onChange?: (value: string) => void;
13
- /** Validation function for error highlighting */
14
- validate?: (expression: string) => SELDiagnostic[] | Promise<SELDiagnostic[]>;
15
- /** Debounce delay for validation (default: 300ms) */
16
- validateDelay?: number;
17
- /** Dark mode */
18
- dark?: boolean;
19
- /** Whether the editor is read-only */
20
- readOnly?: boolean;
21
- /** Placeholder text */
22
- placeholder?: string;
23
- /** Show inferred output type below the editor */
24
- showType?: boolean;
25
- /** Additional CodeMirror extensions */
26
- extensions?: Extension[];
27
- }
28
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/editor/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC/B,sCAAsC;IACtC,MAAM,EAAE,WAAW,CAAC;IAEpB,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC;IAElB,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,wCAAwC;IACxC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAEnC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,aAAa,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAE9E,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,gBAAgB;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,sCAAsC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,uCAAuC;IACvC,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CACzB"}
@@ -1 +0,0 @@
1
- export {};
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./language/index";
2
- export * from "./completion/index";
3
- export * from "./linting/index";
4
- export * from "./editor/index";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from "./language/index";
2
- export * from "./completion/index";
3
- export * from "./linting/index";
4
- export * from "./editor/index";
@@ -1,2 +0,0 @@
1
- export * from "./tokenizer-config";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/language/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -1 +0,0 @@
1
- export * from "./tokenizer-config";
@@ -1,4 +0,0 @@
1
- import { type Extension } from "@codemirror/state";
2
- import type { TokenizerConfig } from "./tokenizer-config";
3
- export declare const createSemanticHighlighter: (config: TokenizerConfig, dark?: boolean) => Extension;
4
- //# sourceMappingURL=semantic-highlighter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semantic-highlighter.d.ts","sourceRoot":"","sources":["../../src/language/semantic-highlighter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,mBAAmB,CAAC;AAQpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA0E1D,eAAO,MAAM,yBAAyB,GACrC,QAAQ,eAAe,EACvB,cAAY,KACV,SAgBF,CAAC"}
@@ -1,76 +0,0 @@
1
- import { syntaxTree } from "@codemirror/language";
2
- import { RangeSetBuilder } from "@codemirror/state";
3
- import { Decoration, ViewPlugin, } from "@codemirror/view";
4
- const LIGHT_COLORS = {
5
- contract: "#00695c",
6
- function: "#1565c0",
7
- macro: "#6a1b9a",
8
- variable: "#37474f",
9
- };
10
- const DARK_COLORS = {
11
- contract: "#4db6ac",
12
- function: "#64b5f6",
13
- macro: "#ce93d8",
14
- variable: "#b0bec5",
15
- };
16
- const createDecorations = (dark) => {
17
- const colors = dark ? DARK_COLORS : LIGHT_COLORS;
18
- return {
19
- contract: Decoration.mark({
20
- attributes: { style: `color: ${colors.contract}` },
21
- }),
22
- function: Decoration.mark({
23
- attributes: { style: `color: ${colors.function}` },
24
- }),
25
- macro: Decoration.mark({ attributes: { style: `color: ${colors.macro}` } }),
26
- variable: Decoration.mark({
27
- attributes: { style: `color: ${colors.variable}` },
28
- }),
29
- };
30
- };
31
- const buildDecorations = (view, config, decos) => {
32
- const builder = new RangeSetBuilder();
33
- const tree = syntaxTree(view.state);
34
- for (const { from, to } of view.visibleRanges) {
35
- tree.iterate({
36
- from,
37
- to,
38
- enter(node) {
39
- if (node.name !== "Identifier") {
40
- return;
41
- }
42
- const name = view.state.doc.sliceString(node.from, node.to);
43
- let deco;
44
- if (config.contractNames.has(name)) {
45
- deco = decos.contract;
46
- }
47
- else if (config.functionNames.has(name)) {
48
- deco = decos.function;
49
- }
50
- else if (config.macroNames.has(name)) {
51
- deco = decos.macro;
52
- }
53
- else if (config.variableNames.has(name)) {
54
- deco = decos.variable;
55
- }
56
- if (deco) {
57
- builder.add(node.from, node.to, deco);
58
- }
59
- },
60
- });
61
- }
62
- return builder.finish();
63
- };
64
- export const createSemanticHighlighter = function (config, dark = false) {
65
- const decos = createDecorations(dark);
66
- return ViewPlugin.define((view) => ({
67
- decorations: buildDecorations(view, config, decos),
68
- update(update) {
69
- if (update.docChanged || update.viewportChanged) {
70
- this.decorations = buildDecorations(update.view, config, decos);
71
- }
72
- },
73
- }), {
74
- decorations: (v) => v.decorations,
75
- });
76
- };
@@ -1,9 +0,0 @@
1
- import type { SELSchema } from "@seljs/schema";
2
- export interface TokenizerConfig {
3
- contractNames: Set<string>;
4
- functionNames: Set<string>;
5
- macroNames: Set<string>;
6
- variableNames: Set<string>;
7
- }
8
- export declare const createTokenizerConfig: (schema: SELSchema) => TokenizerConfig;
9
- //# sourceMappingURL=tokenizer-config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokenizer-config.d.ts","sourceRoot":"","sources":["../../src/language/tokenizer-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC/B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,KAAG,eAKxD,CAAC"}
@@ -1,6 +0,0 @@
1
- export const createTokenizerConfig = (schema) => ({
2
- contractNames: new Set(schema.contracts.map((c) => c.name)),
3
- functionNames: new Set(schema.functions.map((f) => f.name)),
4
- macroNames: new Set(schema.macros.map((m) => m.name)),
5
- variableNames: new Set(schema.variables.map((v) => v.name)),
6
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagnostic-mapper.d.ts","sourceRoot":"","sources":["../../src/linting/diagnostic-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,UAAU,WAAW;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,QAAA,MAAM,cAAc,GACnB,eAAe,WAAW,GAAG,KAAK,EAClC,WAAW,MAAM,KACf,aAAa,EA4Bf,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,YAAY,EAAE,aAAa,EAAE,CAAC"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Maps a TypeCheckResult-shaped object or a caught Error to SELDiagnostic[].
3
- *
4
- * Handles both failure modes from `@seljs/runtime`'s `env.check()`:
5
- * 1. Returned result: `{ valid: false, error: TypeError }`
6
- * 2. Thrown exception: `SELParseError` or `SELTypeError`
7
- *
8
- * Usage:
9
- * ```ts
10
- * const validate = (expression: string): SELDiagnostic[] => {
11
- * try {
12
- * const result = env.check(expression);
13
- * return mapCheckResult(result, expression.length);
14
- * } catch (error) {
15
- * return mapCheckResult(error as Error, expression.length);
16
- * }
17
- * };
18
- * ```
19
- */
20
- const mapCheckResult = (resultOrError, docLength) => {
21
- // Thrown error path
22
- if (resultOrError instanceof Error) {
23
- return [
24
- {
25
- message: resultOrError.message,
26
- severity: "error",
27
- from: 0,
28
- to: Math.max(0, docLength),
29
- },
30
- ];
31
- }
32
- // Returned result path
33
- if (resultOrError.valid) {
34
- return [];
35
- }
36
- const message = resultOrError.error?.message ?? "Invalid expression";
37
- return [
38
- {
39
- message,
40
- severity: "error",
41
- from: 0,
42
- to: Math.max(0, docLength),
43
- },
44
- ];
45
- };
46
- export { mapCheckResult };
@@ -1,3 +0,0 @@
1
- export { createSELLinter, type SELLinterOptions } from "./sel-linter";
2
- export { mapCheckResult, type SELDiagnostic } from "./diagnostic-mapper";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/linting/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,2 +0,0 @@
1
- export { createSELLinter } from "./sel-linter";
2
- export { mapCheckResult } from "./diagnostic-mapper";
@@ -1,12 +0,0 @@
1
- import type { SELDiagnostic } from "./diagnostic-mapper";
2
- import type { Extension } from "@codemirror/state";
3
- interface SELLinterOptions {
4
- /** Validate an expression, return diagnostics */
5
- validate: (expression: string) => SELDiagnostic[] | Promise<SELDiagnostic[]>;
6
- /** Debounce delay in ms (default: 300) */
7
- delay?: number;
8
- }
9
- declare function createSELLinter(options: SELLinterOptions): Extension;
10
- export { createSELLinter };
11
- export type { SELLinterOptions };
12
- //# sourceMappingURL=sel-linter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sel-linter.d.ts","sourceRoot":"","sources":["../../src/linting/sel-linter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,UAAU,gBAAgB;IACzB,iDAAiD;IACjD,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,aAAa,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAE7E,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAqBD,iBAAS,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAe7D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,28 +0,0 @@
1
- import { linter } from "@codemirror/lint";
2
- const SEVERITY_MAP = {
3
- error: "error",
4
- warning: "warning",
5
- info: "info",
6
- };
7
- function mapToCMDiagnostic(diag, docLength) {
8
- const from = diag.from ?? 0;
9
- const to = diag.to ?? docLength;
10
- return {
11
- from: Math.max(0, Math.min(from, docLength)),
12
- to: Math.max(0, Math.min(to, docLength)),
13
- severity: SEVERITY_MAP[diag.severity],
14
- message: diag.message,
15
- };
16
- }
17
- function createSELLinter(options) {
18
- return linter(async (view) => {
19
- const doc = view.state.doc.toString();
20
- if (!doc) {
21
- return [];
22
- }
23
- const diagnostics = await options.validate(doc);
24
- const docLength = doc.length;
25
- return diagnostics.map((d) => mapToCMDiagnostic(d, docLength));
26
- }, { delay: options.delay ?? 300 });
27
- }
28
- export { createSELLinter };