@vuu-ui/vuu-codemirror 2.1.19-beta.1 → 2.1.19-beta.2

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "2.1.19-beta.1",
2
+ "version": "2.1.19-beta.2",
3
3
  "author": "heswell",
4
4
  "license": "Apache-2.0",
5
5
  "devDependencies": {
6
- "@vuu-ui/vuu-table-types": "2.1.19-beta.1"
6
+ "@vuu-ui/vuu-table-types": "2.1.19-beta.2"
7
7
  },
8
8
  "dependencies": {
9
9
  "@codemirror/autocomplete": "^6.4.2",
@@ -11,20 +11,19 @@
11
11
  "@codemirror/language": "^6.6.0",
12
12
  "@codemirror/state": "^6.2.0",
13
13
  "@codemirror/view": "^6.9.3",
14
- "@vuu-ui/vuu-utils": "2.1.19-beta.1",
14
+ "@vuu-ui/vuu-utils": "2.1.19-beta.2",
15
15
  "@lezer/common": "1.2.3",
16
16
  "@lezer/highlight": "^1.1.3"
17
17
  },
18
18
  "type": "module",
19
19
  "files": [
20
20
  "README.md",
21
- "esm",
22
- "cjs",
21
+ "src",
23
22
  "/types"
24
23
  ],
25
24
  "exports": {
26
25
  ".": {
27
- "import": "./index.js",
26
+ "import": "./src/index.js",
28
27
  "types": "./types/index.d.ts"
29
28
  }
30
29
  },
@@ -0,0 +1,19 @@
1
+ import { closeBrackets } from "@codemirror/autocomplete";
2
+ import { defaultKeymap, history as commands_history, historyKeymap } from "@codemirror/commands";
3
+ import { defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
4
+ import { drawSelection, highlightSpecialChars, keymap } from "@codemirror/view";
5
+ const keyBindings = [
6
+ ...defaultKeymap,
7
+ ...historyKeymap
8
+ ];
9
+ const minimalSetup = (()=>[
10
+ highlightSpecialChars(),
11
+ commands_history(),
12
+ drawSelection(),
13
+ closeBrackets(),
14
+ syntaxHighlighting(defaultHighlightStyle, {
15
+ fallback: true
16
+ }),
17
+ keymap.of(keyBindings)
18
+ ])();
19
+ export { minimalSetup };
package/src/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./codemirror-basic-setup.js";
2
+ export * from "./parser-utils.js";
3
+ export * from "./suggestion-utils.js";
4
+ export { autocompletion, closeBrackets, startCompletion } from "@codemirror/autocomplete";
5
+ export { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
6
+ export { HighlightStyle, LRLanguage, LanguageSupport, defaultHighlightStyle, ensureSyntaxTree, syntaxHighlighting, syntaxTree } from "@codemirror/language";
7
+ export { AnnotationType, EditorState } from "@codemirror/state";
8
+ export { EditorView, drawSelection, highlightSpecialChars, keymap } from "@codemirror/view";
9
+ export { Tree } from "@lezer/common";
10
+ export { styleTags, tags } from "@lezer/highlight";
@@ -0,0 +1,25 @@
1
+ const getValue = (node, state)=>state.doc.sliceString(node.from, node.to);
2
+ const getNodeByName = (node, state, nodeName = "Column")=>{
3
+ if (node.firstChild?.name === nodeName) return getValue(node.firstChild, state);
4
+ {
5
+ let maybeColumnNode = node.prevSibling || node.parent;
6
+ while(maybeColumnNode && maybeColumnNode.name !== nodeName)maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
7
+ if (maybeColumnNode) return getValue(maybeColumnNode, state);
8
+ }
9
+ };
10
+ const getPreviousNode = (node)=>{
11
+ const prevNode = node.prevSibling;
12
+ console.log(`prevNode ${prevNode?.name}`);
13
+ return prevNode;
14
+ };
15
+ const getNamedParentNode = (node)=>{
16
+ let maybeParent = node.parent;
17
+ while(maybeParent && "⚠" === maybeParent.name)maybeParent = maybeParent.parent;
18
+ return maybeParent;
19
+ };
20
+ const getPreviousNamedNode = (node)=>{
21
+ let maybeParent = node.prevSibling;
22
+ while(maybeParent && "⚠" === maybeParent.name)maybeParent = maybeParent.prevSibling;
23
+ return maybeParent;
24
+ };
25
+ export { getNamedParentNode, getNodeByName, getPreviousNamedNode, getPreviousNode, getValue };
@@ -0,0 +1,111 @@
1
+ import { AnnotationType } from "@codemirror/state";
2
+ import { isNumericColumn } from "@vuu-ui/vuu-utils";
3
+ const NO_OPTIONS = {};
4
+ const applyWithCursorMove = ()=>(view, completion, from)=>{
5
+ const annotation = new AnnotationType();
6
+ view.dispatch({
7
+ changes: {
8
+ from,
9
+ insert: completion.label
10
+ },
11
+ annotations: annotation.of(completion)
12
+ }, {
13
+ changes: {
14
+ from: from + 1,
15
+ insert: " "
16
+ },
17
+ selection: {
18
+ anchor: from + 2,
19
+ head: from + 2
20
+ },
21
+ annotations: annotation.of(completion)
22
+ });
23
+ };
24
+ const toSuggestions = (values, options = NO_OPTIONS)=>{
25
+ const { moveCursorToEnd = false, prefix = "", quoted = false, suffix = " ", isIllustration = false } = options;
26
+ const quote = quoted ? '"' : "";
27
+ return values.map((value)=>({
28
+ isIllustration,
29
+ label: value,
30
+ apply: moveCursorToEnd ? applyWithCursorMove() : isIllustration ? `${quote}${prefix}${quote}` : `${prefix}${quote}${value}${quote}${suffix}`
31
+ }));
32
+ };
33
+ const asNameSuggestion = {
34
+ label: "as",
35
+ apply: "as ",
36
+ boost: 1
37
+ };
38
+ const booleanJoinSuggestions = [
39
+ {
40
+ label: "and",
41
+ apply: "and ",
42
+ boost: 5
43
+ },
44
+ {
45
+ label: "or",
46
+ apply: "or ",
47
+ boost: 3
48
+ }
49
+ ];
50
+ const equalityOperators = [
51
+ {
52
+ label: "=",
53
+ boost: 10,
54
+ type: "operator"
55
+ },
56
+ {
57
+ label: "!=",
58
+ boost: 9,
59
+ type: "operator"
60
+ }
61
+ ];
62
+ const stringOperators = [
63
+ ...equalityOperators,
64
+ {
65
+ label: "in",
66
+ boost: 6,
67
+ type: "operator"
68
+ },
69
+ {
70
+ label: "contains",
71
+ boost: 5,
72
+ type: "operator"
73
+ },
74
+ {
75
+ label: "starts",
76
+ boost: 5,
77
+ type: "operator"
78
+ },
79
+ {
80
+ label: "ends",
81
+ boost: 4,
82
+ type: "operator"
83
+ }
84
+ ];
85
+ const numericOperators = [
86
+ ...equalityOperators,
87
+ {
88
+ label: ">",
89
+ boost: 8,
90
+ type: "operator"
91
+ },
92
+ {
93
+ label: "<",
94
+ boost: 7,
95
+ type: "operator"
96
+ }
97
+ ];
98
+ const getRelationalOperators = (column)=>{
99
+ if (void 0 === column || isNumericColumn(column)) return numericOperators;
100
+ return equalityOperators;
101
+ };
102
+ const getNamePrompt = (entity)=>{
103
+ const label = entity ? `enter name for this ${entity}` : "enter name";
104
+ return [
105
+ {
106
+ label,
107
+ boost: 5
108
+ }
109
+ ];
110
+ };
111
+ export { asNameSuggestion, booleanJoinSuggestions, equalityOperators, getNamePrompt, getRelationalOperators, numericOperators, stringOperators, toSuggestions };