@surrealdb/codemirror 1.0.0-beta.1 → 1.0.0-beta.11
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 +79 -0
- package/dist/index.cjs +16 -10
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +15 -9
- package/package.json +1 -1
- package/src/surrealql.ts +17 -10
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
|
+
|
|
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
|
+
|
|
20
|
+
<a href="https://twitter.com/surrealdb"><img src="https://img.shields.io/badge/twitter-follow_us-1d9bf0.svg?style=flat-square"></a>
|
|
21
|
+
|
|
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
|
+
|
|
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
|
|
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:
|
|
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
|
|
31
|
-
["
|
|
32
|
-
["
|
|
33
|
-
["combined-results",
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
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(
|
|
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 = "
|
|
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 = "
|
|
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
|
|
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
|
|
29
|
-
["
|
|
30
|
-
["
|
|
31
|
-
["combined-results",
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
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(
|
|
47
|
+
return new LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
export { surrealql, surrealqlLanguage };
|
package/package.json
CHANGED
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
|
|
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 =
|
|
37
|
+
type Scope ="permission" | "index" | "combined-results" | "syntax";
|
|
38
38
|
|
|
39
|
-
const
|
|
40
|
-
["
|
|
41
|
-
["
|
|
42
|
-
["combined-results",
|
|
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
|
|
49
|
-
|
|
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 (!
|
|
58
|
+
if (!scopeId) {
|
|
52
59
|
throw new Error(`Unknown language scope: ${scope}`);
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
return new LanguageSupport(
|
|
62
|
+
return new LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
|
|
56
63
|
}
|