@surrealdb/codemirror 1.0.0-beta.1 → 1.0.0-beta.10

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/README.md ADDED
@@ -0,0 +1,79 @@
1
+ <br>
2
+
3
+ <p align="center">
4
+ <img width=120 src="https://raw.githubusercontent.com/surrealdb/icons/main/surreal.svg" />
5
+ </p>
6
+
7
+ <h3 align="center">SurrealQL Support for CodeMirror</h3>
8
+
9
+ <br>
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/surrealdb/surrealql-codemirror"><img src="https://img.shields.io/badge/status-beta-ff00bb.svg?style=flat-square"></a>
13
+ &nbsp;
14
+ <a href="https://www.npmjs.com/package/@surrealdb/codemirror"><img src="https://img.shields.io/npm/v/%40surrealdb%2Fcodemirror?style=flat-square"></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="https://surrealdb.com/discord"><img src="https://img.shields.io/discord/902568124350599239?label=discord&style=flat-square&color=5a66f6"></a>
19
+ &nbsp;
20
+ <a href="https://twitter.com/surrealdb"><img src="https://img.shields.io/badge/twitter-follow_us-1d9bf0.svg?style=flat-square"></a>
21
+ &nbsp;
22
+ <a href="https://www.linkedin.com/company/surrealdb/"><img src="https://img.shields.io/badge/linkedin-connect_with_us-0a66c2.svg?style=flat-square"></a>
23
+ &nbsp;
24
+ <a href="https://www.youtube.com/channel/UCjf2teVEuYVvvVC-gFZNq6w"><img src="https://img.shields.io/badge/youtube-subscribe-fc1c1c.svg?style=flat-square"></a>
25
+ </p>
26
+
27
+ # @surrealdb/codemirror
28
+
29
+ This library provides full support for the SurrealQL language within your CodeMirror editors.
30
+
31
+ Some features include:
32
+ - Intelligent SurrealQL highlighting
33
+ - Folding support for blocks, objects, and arrays
34
+ - Automatic indentation support
35
+ - Support for comment toggling
36
+ - Embedded JavaScript highlighting
37
+
38
+ ## How to install
39
+
40
+ Install it with:
41
+
42
+ ```sh
43
+ # using npm
44
+ npm i @surrealdb/codemirror
45
+ # or using pnpm
46
+ pnpm i @surrealdb/codemirror
47
+ # or using yarn
48
+ yarn add @surrealdb/codemirror
49
+ ```
50
+
51
+ Next, just import it with:
52
+
53
+ ```ts
54
+ const { surrealql } = require("@surrealdb/codemirror");
55
+ ```
56
+
57
+ or when you use modules:
58
+
59
+ ```ts
60
+ import { surrealql } from "@surrealdb/codemirror";
61
+ ```
62
+
63
+ ## Example usage
64
+
65
+ ```ts
66
+ import { surrealql } from "@surrealdb/codemirror";
67
+
68
+ const state = EditorState.create({
69
+ doc: "SELECT * FROM table",
70
+ extensions: [
71
+ surrealql()
72
+ ]
73
+ });
74
+
75
+ const editor = new EditorView({
76
+ parent: document.getElementById("editor"),
77
+ state: state,
78
+ });
79
+ ```
package/dist/index.cjs CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var language = require('@codemirror/language');
4
- var lezerSurrealql = require('lezer-surrealql');
4
+ var lezer = require('@surrealdb/lezer');
5
5
  var common = require('@lezer/common');
6
6
  var javascript = require('@lezer/javascript');
7
7
 
8
8
  const surrealqlLanguage = language.LRLanguage.define({
9
9
  name: "surrealql",
10
- parser: lezerSurrealql.parser.configure({
10
+ parser: lezer.parser.configure({
11
11
  props: [
12
12
  language.indentNodeProp.add({
13
13
  Object: language.continuedIndent({ except: /^\s*}/ }),
@@ -27,20 +27,26 @@ const surrealqlLanguage = language.LRLanguage.define({
27
27
  commentTokens: { line: "--" },
28
28
  },
29
29
  });
30
- const languageMap = new Map([
31
- ["default", surrealqlLanguage.configure({ top: "SurrealQL" })],
32
- ["permission", surrealqlLanguage.configure({ top: "PermissionInput" })],
33
- ["combined-results", surrealqlLanguage.configure({ top: "CombinedResults" })],
30
+ const scopeMap = new Map([
31
+ ["permission", "PermissionInput"],
32
+ ["index", "IndexInput"],
33
+ ["combined-results", "CombinedResults"],
34
+ ["syntax", "Syntax"],
34
35
  ]);
35
36
  /**
36
37
  * The CodeMirror extension used to add support for the SurrealQL language
38
+ *
39
+ * @param scope Limit the scope of the highlighting
37
40
  */
38
- function surrealql(scope = "default") {
39
- const language$1 = languageMap.get(scope);
40
- if (!language$1) {
41
+ function surrealql(scope) {
42
+ if (!scope) {
43
+ return new language.LanguageSupport(surrealqlLanguage);
44
+ }
45
+ const scopeId = scopeMap.get(scope);
46
+ if (!scopeId) {
41
47
  throw new Error(`Unknown language scope: ${scope}`);
42
48
  }
43
- return new language.LanguageSupport(language$1);
49
+ return new language.LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
44
50
  }
45
51
 
46
52
  exports.surrealql = surrealql;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { LRLanguage, LanguageSupport } from '@codemirror/language';
2
2
 
3
3
  declare const surrealqlLanguage: LRLanguage;
4
- type Scope = "default" | "permission" | "combined-results";
4
+ type Scope = "permission" | "index" | "combined-results" | "syntax";
5
5
  /**
6
6
  * The CodeMirror extension used to add support for the SurrealQL language
7
+ *
8
+ * @param scope Limit the scope of the highlighting
7
9
  */
8
10
  declare function surrealql(scope?: Scope): LanguageSupport;
9
11
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { LRLanguage, LanguageSupport } from '@codemirror/language';
2
2
 
3
3
  declare const surrealqlLanguage: LRLanguage;
4
- type Scope = "default" | "permission" | "combined-results";
4
+ type Scope = "permission" | "index" | "combined-results" | "syntax";
5
5
  /**
6
6
  * The CodeMirror extension used to add support for the SurrealQL language
7
+ *
8
+ * @param scope Limit the scope of the highlighting
7
9
  */
8
10
  declare function surrealql(scope?: Scope): LanguageSupport;
9
11
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LRLanguage, indentNodeProp, continuedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
2
- import { parser } from 'lezer-surrealql';
2
+ import { parser } from '@surrealdb/lezer';
3
3
  import { parseMixed } from '@lezer/common';
4
4
  import { parser as parser$1 } from '@lezer/javascript';
5
5
 
@@ -25,20 +25,26 @@ const surrealqlLanguage = /*@__PURE__*/LRLanguage.define({
25
25
  commentTokens: { line: "--" },
26
26
  },
27
27
  });
28
- const languageMap = /*@__PURE__*/new Map([
29
- ["default", /*@__PURE__*/surrealqlLanguage.configure({ top: "SurrealQL" })],
30
- ["permission", /*@__PURE__*/surrealqlLanguage.configure({ top: "PermissionInput" })],
31
- ["combined-results", /*@__PURE__*/surrealqlLanguage.configure({ top: "CombinedResults" })],
28
+ const scopeMap = /*@__PURE__*/new Map([
29
+ ["permission", "PermissionInput"],
30
+ ["index", "IndexInput"],
31
+ ["combined-results", "CombinedResults"],
32
+ ["syntax", "Syntax"],
32
33
  ]);
33
34
  /**
34
35
  * The CodeMirror extension used to add support for the SurrealQL language
36
+ *
37
+ * @param scope Limit the scope of the highlighting
35
38
  */
36
- function surrealql(scope = "default") {
37
- const language = languageMap.get(scope);
38
- if (!language) {
39
+ function surrealql(scope) {
40
+ if (!scope) {
41
+ return new LanguageSupport(surrealqlLanguage);
42
+ }
43
+ const scopeId = scopeMap.get(scope);
44
+ if (!scopeId) {
39
45
  throw new Error(`Unknown language scope: ${scope}`);
40
46
  }
41
- return new LanguageSupport(language);
47
+ return new LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
42
48
  }
43
49
 
44
50
  export { surrealql, surrealqlLanguage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surrealdb/codemirror",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.10",
4
4
  "author": "SurrealDB",
5
5
  "description": "SurrealQL language support for CodeMirror",
6
6
  "type": "module",
package/src/surrealql.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  LanguageSupport,
8
8
  } from "@codemirror/language";
9
9
 
10
- import { parser } from "lezer-surrealql";
10
+ import { parser } from "@surrealdb/lezer";
11
11
  import { parseMixed } from "@lezer/common";
12
12
  import { parser as jsParser } from "@lezer/javascript";
13
13
 
@@ -34,23 +34,30 @@ export const surrealqlLanguage = LRLanguage.define({
34
34
  },
35
35
  });
36
36
 
37
- type Scope = "default" | "permission" | "combined-results";
37
+ type Scope ="permission" | "index" | "combined-results" | "syntax";
38
38
 
39
- const languageMap = new Map<Scope, LRLanguage>([
40
- ["default", surrealqlLanguage.configure({ top: "SurrealQL" })],
41
- ["permission", surrealqlLanguage.configure({ top: "PermissionInput" })],
42
- ["combined-results", surrealqlLanguage.configure({ top: "CombinedResults" })],
39
+ const scopeMap = new Map<Scope, string>([
40
+ ["permission", "PermissionInput"],
41
+ ["index", "IndexInput"],
42
+ ["combined-results", "CombinedResults"],
43
+ ["syntax", "Syntax"],
43
44
  ]);
44
45
 
45
46
  /**
46
47
  * The CodeMirror extension used to add support for the SurrealQL language
48
+ *
49
+ * @param scope Limit the scope of the highlighting
47
50
  */
48
- export function surrealql(scope: Scope = "default") {
49
- const language = languageMap.get(scope);
51
+ export function surrealql(scope?: Scope) {
52
+ if (!scope) {
53
+ return new LanguageSupport(surrealqlLanguage);
54
+ }
55
+
56
+ const scopeId = scopeMap.get(scope);
50
57
 
51
- if (!language) {
58
+ if (!scopeId) {
52
59
  throw new Error(`Unknown language scope: ${scope}`);
53
60
  }
54
61
 
55
- return new LanguageSupport(language);
62
+ return new LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
56
63
  }