@vuu-ui/vuu-codemirror 0.13.9 → 0.13.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.
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var autocomplete = require('@codemirror/autocomplete');
4
+ var commands = require('@codemirror/commands');
5
+ var language = require('@codemirror/language');
6
+ var view = require('@codemirror/view');
7
+
8
+ const keyBindings = [
9
+ ...commands.defaultKeymap,
10
+ ...commands.historyKeymap
11
+ ];
12
+ const minimalSetup = (() => [
13
+ view.highlightSpecialChars(),
14
+ commands.history(),
15
+ view.drawSelection(),
16
+ autocomplete.closeBrackets(),
17
+ language.syntaxHighlighting(language.defaultHighlightStyle, { fallback: true }),
18
+ view.keymap.of(keyBindings)
19
+ ])();
20
+
21
+ exports.minimalSetup = minimalSetup;
22
+ //# sourceMappingURL=codemirror-basic-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codemirror-basic-setup.js","sources":["../src/codemirror-basic-setup.ts"],"sourcesContent":["import { closeBrackets } from \"@codemirror/autocomplete\";\nimport { defaultKeymap, history, historyKeymap } from \"@codemirror/commands\";\nimport {\n defaultHighlightStyle,\n syntaxHighlighting,\n} from \"@codemirror/language\";\nimport { Extension } from \"@codemirror/state\";\nimport {\n drawSelection,\n highlightSpecialChars,\n KeyBinding,\n keymap,\n} from \"@codemirror/view\";\n\nconst keyBindings = [\n ...defaultKeymap,\n ...historyKeymap,\n] as ReadonlyArray<KeyBinding>;\n\nexport const minimalSetup: Extension = (() => [\n highlightSpecialChars(),\n history(),\n drawSelection(),\n closeBrackets(),\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n keymap.of(keyBindings),\n])();\n"],"names":["defaultKeymap","historyKeymap","highlightSpecialChars","history","drawSelection","closeBrackets","syntaxHighlighting","defaultHighlightStyle","keymap"],"mappings":";;;;;;;AAcA,MAAM,WAAc,GAAA;AAAA,EAClB,GAAGA,sBAAA;AAAA,EACH,GAAGC;AACL,CAAA;AAEO,MAAM,gBAA2B,MAAM;AAAA,EAC5CC,0BAAsB,EAAA;AAAA,EACtBC,gBAAQ,EAAA;AAAA,EACRC,kBAAc,EAAA;AAAA,EACdC,0BAAc,EAAA;AAAA,EACdC,2BAAmB,CAAAC,8BAAA,EAAuB,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EAC5DC,WAAA,CAAO,GAAG,WAAW;AACvB,CAAG;;;;"}
package/cjs/index.js CHANGED
@@ -7,117 +7,11 @@ var state = require('@codemirror/state');
7
7
  var view = require('@codemirror/view');
8
8
  var common = require('@lezer/common');
9
9
  var highlight = require('@lezer/highlight');
10
- var vuuUtils = require('@vuu-ui/vuu-utils');
10
+ var codemirrorBasicSetup = require('./codemirror-basic-setup.js');
11
+ var parserUtils = require('./parser-utils.js');
12
+ var suggestionUtils = require('./suggestion-utils.js');
11
13
 
12
- const keyBindings = [
13
- ...commands.defaultKeymap,
14
- ...commands.historyKeymap
15
- ];
16
- const minimalSetup = (() => [
17
- view.highlightSpecialChars(),
18
- commands.history(),
19
- view.drawSelection(),
20
- autocomplete.closeBrackets(),
21
- language.syntaxHighlighting(language.defaultHighlightStyle, { fallback: true }),
22
- view.keymap.of(keyBindings)
23
- ])();
24
14
 
25
- const getValue = (node, state) => state.doc.sliceString(node.from, node.to);
26
- const getNodeByName = (node, state, nodeName = "Column") => {
27
- if (node.firstChild?.name === nodeName) {
28
- return getValue(node.firstChild, state);
29
- } else {
30
- let maybeColumnNode = node.prevSibling || node.parent;
31
- while (maybeColumnNode && maybeColumnNode.name !== nodeName) {
32
- maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
33
- }
34
- if (maybeColumnNode) {
35
- return getValue(maybeColumnNode, state);
36
- }
37
- }
38
- };
39
- const getPreviousNode = (node) => {
40
- const prevNode = node.prevSibling;
41
- console.log(`prevNode ${prevNode?.name}`);
42
- return prevNode;
43
- };
44
- const getNamedParentNode = (node) => {
45
- let maybeParent = node.parent;
46
- while (maybeParent && maybeParent.name === "\u26A0") {
47
- maybeParent = maybeParent.parent;
48
- }
49
- return maybeParent;
50
- };
51
- const getPreviousNamedNode = (node) => {
52
- let maybeParent = node.prevSibling;
53
- while (maybeParent && maybeParent.name === "\u26A0") {
54
- maybeParent = maybeParent.prevSibling;
55
- }
56
- return maybeParent;
57
- };
58
-
59
- const NO_OPTIONS = {};
60
- const applyWithCursorMove = () => (view, completion, from) => {
61
- const annotation = new state.AnnotationType();
62
- view.dispatch(
63
- {
64
- changes: { from, insert: completion.label },
65
- annotations: annotation.of(completion)
66
- },
67
- {
68
- changes: { from: from + 1, insert: " " },
69
- selection: { anchor: from + 2, head: from + 2 },
70
- annotations: annotation.of(completion)
71
- }
72
- );
73
- };
74
- const toSuggestions = (values, options = NO_OPTIONS) => {
75
- const {
76
- moveCursorToEnd = false,
77
- prefix = "",
78
- quoted = false,
79
- suffix = " ",
80
- isIllustration = false
81
- } = options;
82
- const quote = quoted ? '"' : "";
83
- return values.map((value) => ({
84
- isIllustration,
85
- label: value,
86
- apply: moveCursorToEnd ? applyWithCursorMove() : isIllustration ? `${quote}${prefix}${quote}` : `${prefix}${quote}${value}${quote}${suffix}`
87
- }));
88
- };
89
- const asNameSuggestion = { label: "as", apply: "as ", boost: 1 };
90
- const booleanJoinSuggestions = [
91
- { label: "and", apply: "and ", boost: 5 },
92
- { label: "or", apply: "or ", boost: 3 }
93
- ];
94
- const equalityOperators = [
95
- { label: "=", boost: 10, type: "operator" },
96
- { label: "!=", boost: 9, type: "operator" }
97
- ];
98
- const stringOperators = [
99
- ...equalityOperators,
100
- { label: "in", boost: 6, type: "operator" },
101
- { label: "contains", boost: 5, type: "operator" },
102
- { label: "starts", boost: 5, type: "operator" },
103
- { label: "ends", boost: 4, type: "operator" }
104
- ];
105
- const numericOperators = [
106
- ...equalityOperators,
107
- { label: ">", boost: 8, type: "operator" },
108
- { label: "<", boost: 7, type: "operator" }
109
- ];
110
- const getRelationalOperators = (column) => {
111
- if (column === void 0 || vuuUtils.isNumericColumn(column)) {
112
- return numericOperators;
113
- } else {
114
- return equalityOperators;
115
- }
116
- };
117
- const getNamePrompt = (entity) => {
118
- const label = entity ? `enter name for this ${entity}` : "enter name";
119
- return [{ label, boost: 5 }];
120
- };
121
15
 
122
16
  Object.defineProperty(exports, "autocompletion", {
123
17
  enumerable: true,
@@ -207,18 +101,18 @@ Object.defineProperty(exports, "tags", {
207
101
  enumerable: true,
208
102
  get: function () { return highlight.tags; }
209
103
  });
210
- exports.asNameSuggestion = asNameSuggestion;
211
- exports.booleanJoinSuggestions = booleanJoinSuggestions;
212
- exports.equalityOperators = equalityOperators;
213
- exports.getNamePrompt = getNamePrompt;
214
- exports.getNamedParentNode = getNamedParentNode;
215
- exports.getNodeByName = getNodeByName;
216
- exports.getPreviousNamedNode = getPreviousNamedNode;
217
- exports.getPreviousNode = getPreviousNode;
218
- exports.getRelationalOperators = getRelationalOperators;
219
- exports.getValue = getValue;
220
- exports.minimalSetup = minimalSetup;
221
- exports.numericOperators = numericOperators;
222
- exports.stringOperators = stringOperators;
223
- exports.toSuggestions = toSuggestions;
104
+ exports.minimalSetup = codemirrorBasicSetup.minimalSetup;
105
+ exports.getNamedParentNode = parserUtils.getNamedParentNode;
106
+ exports.getNodeByName = parserUtils.getNodeByName;
107
+ exports.getPreviousNamedNode = parserUtils.getPreviousNamedNode;
108
+ exports.getPreviousNode = parserUtils.getPreviousNode;
109
+ exports.getValue = parserUtils.getValue;
110
+ exports.asNameSuggestion = suggestionUtils.asNameSuggestion;
111
+ exports.booleanJoinSuggestions = suggestionUtils.booleanJoinSuggestions;
112
+ exports.equalityOperators = suggestionUtils.equalityOperators;
113
+ exports.getNamePrompt = suggestionUtils.getNamePrompt;
114
+ exports.getRelationalOperators = suggestionUtils.getRelationalOperators;
115
+ exports.numericOperators = suggestionUtils.numericOperators;
116
+ exports.stringOperators = suggestionUtils.stringOperators;
117
+ exports.toSuggestions = suggestionUtils.toSuggestions;
224
118
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/codemirror-basic-setup.ts","../src/parser-utils.ts","../src/suggestion-utils.ts"],"sourcesContent":["import { closeBrackets } from \"@codemirror/autocomplete\";\nimport { defaultKeymap, history, historyKeymap } from \"@codemirror/commands\";\nimport {\n defaultHighlightStyle,\n syntaxHighlighting,\n} from \"@codemirror/language\";\nimport { Extension } from \"@codemirror/state\";\nimport {\n drawSelection,\n highlightSpecialChars,\n KeyBinding,\n keymap,\n} from \"@codemirror/view\";\n\nconst keyBindings = [\n ...defaultKeymap,\n ...historyKeymap,\n] as ReadonlyArray<KeyBinding>;\n\nexport const minimalSetup: Extension = (() => [\n highlightSpecialChars(),\n history(),\n drawSelection(),\n closeBrackets(),\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n keymap.of(keyBindings),\n])();\n","import { EditorState } from \"@codemirror/state\";\nimport type { SyntaxNode } from \"@lezer/common\";\n\nexport const getValue = (node: SyntaxNode, state: EditorState) =>\n state.doc.sliceString(node.from, node.to);\n\nexport const getNodeByName = (\n node: SyntaxNode,\n state: EditorState,\n nodeName = \"Column\"\n) => {\n if (node.firstChild?.name === nodeName) {\n return getValue(node.firstChild, state);\n } else {\n let maybeColumnNode = node.prevSibling || node.parent;\n while (maybeColumnNode && maybeColumnNode.name !== nodeName) {\n maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;\n }\n if (maybeColumnNode) {\n return getValue(maybeColumnNode, state);\n }\n }\n};\n\nexport const getPreviousNode = (node: SyntaxNode) => {\n const prevNode = node.prevSibling;\n console.log(`prevNode ${prevNode?.name}`);\n return prevNode;\n};\n\nexport const getNamedParentNode = (node: SyntaxNode) => {\n let maybeParent = node.parent;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.parent;\n }\n return maybeParent;\n};\n\nexport const getPreviousNamedNode = (node: SyntaxNode) => {\n let maybeParent = node.prevSibling;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.prevSibling;\n }\n return maybeParent;\n};\n","import { Completion } from \"@codemirror/autocomplete\";\nimport { AnnotationType } from \"@codemirror/state\";\nimport { EditorView } from \"@codemirror/view\";\nimport type { ColumnDescriptor } from \"@vuu-ui/vuu-table-types\";\nimport { isNumericColumn } from \"@vuu-ui/vuu-utils\";\n\nexport interface VuuCompletion extends Completion {\n isIllustration?: boolean;\n}\n\nexport type CompletionOptions = {\n moveCursorToEnd?: boolean;\n prefix?: string;\n quoted?: boolean;\n suffix?: string;\n isIllustration?: boolean;\n};\n\nconst NO_OPTIONS: CompletionOptions = {};\n\nconst applyWithCursorMove =\n () => (view: EditorView, completion: Completion, from: number) => {\n const annotation = new AnnotationType<Completion>();\n view.dispatch(\n {\n changes: { from, insert: completion.label },\n annotations: annotation.of(completion),\n },\n {\n changes: { from: from + 1, insert: \" \" },\n selection: { anchor: from + 2, head: from + 2 },\n annotations: annotation.of(completion),\n },\n );\n };\n\nexport const toSuggestions = (\n values: string[],\n options = NO_OPTIONS,\n): VuuCompletion[] => {\n const {\n moveCursorToEnd = false,\n prefix = \"\",\n quoted = false,\n suffix = \" \",\n isIllustration = false,\n } = options;\n const quote = quoted ? '\"' : \"\";\n return values.map((value) => ({\n isIllustration,\n label: value,\n apply: moveCursorToEnd\n ? applyWithCursorMove()\n : isIllustration\n ? `${quote}${prefix}${quote}`\n : `${prefix}${quote}${value}${quote}${suffix}`,\n }));\n};\n\nexport const asNameSuggestion = { label: \"as\", apply: \"as \", boost: 1 };\n\nexport const booleanJoinSuggestions: Completion[] = [\n { label: \"and\", apply: \"and \", boost: 5 },\n { label: \"or\", apply: \"or \", boost: 3 },\n];\n\nexport const equalityOperators: Completion[] = [\n { label: \"=\", boost: 10, type: \"operator\" },\n { label: \"!=\", boost: 9, type: \"operator\" },\n];\n\nexport const stringOperators: Completion[] = [\n ...equalityOperators,\n { label: \"in\", boost: 6, type: \"operator\" },\n { label: \"contains\", boost: 5, type: \"operator\" },\n { label: \"starts\", boost: 5, type: \"operator\" },\n { label: \"ends\", boost: 4, type: \"operator\" },\n];\n\nexport const numericOperators: Completion[] = [\n ...equalityOperators,\n { label: \">\", boost: 8, type: \"operator\" },\n { label: \"<\", boost: 7, type: \"operator\" },\n];\n\nexport const getRelationalOperators = (column?: ColumnDescriptor) => {\n if (column === undefined || isNumericColumn(column)) {\n return numericOperators;\n } else {\n return equalityOperators;\n }\n};\n\nexport const getNamePrompt = (entity?: string) => {\n const label = entity ? `enter name for this ${entity}` : \"enter name\";\n return [{ label, boost: 5 }];\n};\n"],"names":["defaultKeymap","historyKeymap","highlightSpecialChars","history","drawSelection","closeBrackets","syntaxHighlighting","defaultHighlightStyle","keymap","AnnotationType","isNumericColumn"],"mappings":";;;;;;;;;;;AAcA,MAAM,WAAc,GAAA;AAAA,EAClB,GAAGA,sBAAA;AAAA,EACH,GAAGC;AACL,CAAA;AAEO,MAAM,gBAA2B,MAAM;AAAA,EAC5CC,0BAAsB,EAAA;AAAA,EACtBC,gBAAQ,EAAA;AAAA,EACRC,kBAAc,EAAA;AAAA,EACdC,0BAAc,EAAA;AAAA,EACdC,2BAAmB,CAAAC,8BAAA,EAAuB,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EAC5DC,WAAA,CAAO,GAAG,WAAW;AACvB,CAAG;;ACvBU,MAAA,QAAA,GAAW,CAAC,IAAA,EAAkB,KACzC,KAAA,KAAA,CAAM,IAAI,WAAY,CAAA,IAAA,CAAK,IAAM,EAAA,IAAA,CAAK,EAAE;AAEnC,MAAM,aAAgB,GAAA,CAC3B,IACA,EAAA,KAAA,EACA,WAAW,QACR,KAAA;AACH,EAAI,IAAA,IAAA,CAAK,UAAY,EAAA,IAAA,KAAS,QAAU,EAAA;AACtC,IAAO,OAAA,QAAA,CAAS,IAAK,CAAA,UAAA,EAAY,KAAK,CAAA;AAAA,GACjC,MAAA;AACL,IAAI,IAAA,eAAA,GAAkB,IAAK,CAAA,WAAA,IAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ const getValue = (node, state) => state.doc.sliceString(node.from, node.to);
4
+ const getNodeByName = (node, state, nodeName = "Column") => {
5
+ if (node.firstChild?.name === nodeName) {
6
+ return getValue(node.firstChild, state);
7
+ } else {
8
+ let maybeColumnNode = node.prevSibling || node.parent;
9
+ while (maybeColumnNode && maybeColumnNode.name !== nodeName) {
10
+ maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
11
+ }
12
+ if (maybeColumnNode) {
13
+ return getValue(maybeColumnNode, state);
14
+ }
15
+ }
16
+ };
17
+ const getPreviousNode = (node) => {
18
+ const prevNode = node.prevSibling;
19
+ console.log(`prevNode ${prevNode?.name}`);
20
+ return prevNode;
21
+ };
22
+ const getNamedParentNode = (node) => {
23
+ let maybeParent = node.parent;
24
+ while (maybeParent && maybeParent.name === "\u26A0") {
25
+ maybeParent = maybeParent.parent;
26
+ }
27
+ return maybeParent;
28
+ };
29
+ const getPreviousNamedNode = (node) => {
30
+ let maybeParent = node.prevSibling;
31
+ while (maybeParent && maybeParent.name === "\u26A0") {
32
+ maybeParent = maybeParent.prevSibling;
33
+ }
34
+ return maybeParent;
35
+ };
36
+
37
+ exports.getNamedParentNode = getNamedParentNode;
38
+ exports.getNodeByName = getNodeByName;
39
+ exports.getPreviousNamedNode = getPreviousNamedNode;
40
+ exports.getPreviousNode = getPreviousNode;
41
+ exports.getValue = getValue;
42
+ //# sourceMappingURL=parser-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser-utils.js","sources":["../src/parser-utils.ts"],"sourcesContent":["import { EditorState } from \"@codemirror/state\";\nimport type { SyntaxNode } from \"@lezer/common\";\n\nexport const getValue = (node: SyntaxNode, state: EditorState) =>\n state.doc.sliceString(node.from, node.to);\n\nexport const getNodeByName = (\n node: SyntaxNode,\n state: EditorState,\n nodeName = \"Column\"\n) => {\n if (node.firstChild?.name === nodeName) {\n return getValue(node.firstChild, state);\n } else {\n let maybeColumnNode = node.prevSibling || node.parent;\n while (maybeColumnNode && maybeColumnNode.name !== nodeName) {\n maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;\n }\n if (maybeColumnNode) {\n return getValue(maybeColumnNode, state);\n }\n }\n};\n\nexport const getPreviousNode = (node: SyntaxNode) => {\n const prevNode = node.prevSibling;\n console.log(`prevNode ${prevNode?.name}`);\n return prevNode;\n};\n\nexport const getNamedParentNode = (node: SyntaxNode) => {\n let maybeParent = node.parent;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.parent;\n }\n return maybeParent;\n};\n\nexport const getPreviousNamedNode = (node: SyntaxNode) => {\n let maybeParent = node.prevSibling;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.prevSibling;\n }\n return maybeParent;\n};\n"],"names":[],"mappings":";;AAGa,MAAA,QAAA,GAAW,CAAC,IAAA,EAAkB,KACzC,KAAA,KAAA,CAAM,IAAI,WAAY,CAAA,IAAA,CAAK,IAAM,EAAA,IAAA,CAAK,EAAE;AAEnC,MAAM,aAAgB,GAAA,CAC3B,IACA,EAAA,KAAA,EACA,WAAW,QACR,KAAA;AACH,EAAI,IAAA,IAAA,CAAK,UAAY,EAAA,IAAA,KAAS,QAAU,EAAA;AACtC,IAAO,OAAA,QAAA,CAAS,IAAK,CAAA,UAAA,EAAY,KAAK,CAAA;AAAA,GACjC,MAAA;AACL,IAAI,IAAA,eAAA,GAAkB,IAAK,CAAA,WAAA,IAAe,IAAK,CAAA,MAAA;AAC/C,IAAO,OAAA,eAAA,IAAmB,eAAgB,CAAA,IAAA,KAAS,QAAU,EAAA;AAC3D,MAAkB,eAAA,GAAA,eAAA,CAAgB,eAAe,eAAgB,CAAA,MAAA;AAAA;AAEnE,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAO,OAAA,QAAA,CAAS,iBAAiB,KAAK,CAAA;AAAA;AACxC;AAEJ;AAEa,MAAA,eAAA,GAAkB,CAAC,IAAqB,KAAA;AACnD,EAAA,MAAM,WAAW,IAAK,CAAA,WAAA;AACtB,EAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,SAAA,EAAY,QAAU,EAAA,IAAI,CAAE,CAAA,CAAA;AACxC,EAAO,OAAA,QAAA;AACT;AAEa,MAAA,kBAAA,GAAqB,CAAC,IAAqB,KAAA;AACtD,EAAA,IAAI,cAAc,IAAK,CAAA,MAAA;AACvB,EAAO,OAAA,WAAA,IAAe,WAAY,CAAA,IAAA,KAAS,QAAK,EAAA;AAC9C,IAAA,WAAA,GAAc,WAAY,CAAA,MAAA;AAAA;AAE5B,EAAO,OAAA,WAAA;AACT;AAEa,MAAA,oBAAA,GAAuB,CAAC,IAAqB,KAAA;AACxD,EAAA,IAAI,cAAc,IAAK,CAAA,WAAA;AACvB,EAAO,OAAA,WAAA,IAAe,WAAY,CAAA,IAAA,KAAS,QAAK,EAAA;AAC9C,IAAA,WAAA,GAAc,WAAY,CAAA,WAAA;AAAA;AAE5B,EAAO,OAAA,WAAA;AACT;;;;;;;;"}
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var state = require('@codemirror/state');
4
+ var vuuUtils = require('@vuu-ui/vuu-utils');
5
+
6
+ const NO_OPTIONS = {};
7
+ const applyWithCursorMove = () => (view, completion, from) => {
8
+ const annotation = new state.AnnotationType();
9
+ view.dispatch(
10
+ {
11
+ changes: { from, insert: completion.label },
12
+ annotations: annotation.of(completion)
13
+ },
14
+ {
15
+ changes: { from: from + 1, insert: " " },
16
+ selection: { anchor: from + 2, head: from + 2 },
17
+ annotations: annotation.of(completion)
18
+ }
19
+ );
20
+ };
21
+ const toSuggestions = (values, options = NO_OPTIONS) => {
22
+ const {
23
+ moveCursorToEnd = false,
24
+ prefix = "",
25
+ quoted = false,
26
+ suffix = " ",
27
+ isIllustration = false
28
+ } = options;
29
+ const quote = quoted ? '"' : "";
30
+ return values.map((value) => ({
31
+ isIllustration,
32
+ label: value,
33
+ apply: moveCursorToEnd ? applyWithCursorMove() : isIllustration ? `${quote}${prefix}${quote}` : `${prefix}${quote}${value}${quote}${suffix}`
34
+ }));
35
+ };
36
+ const asNameSuggestion = { label: "as", apply: "as ", boost: 1 };
37
+ const booleanJoinSuggestions = [
38
+ { label: "and", apply: "and ", boost: 5 },
39
+ { label: "or", apply: "or ", boost: 3 }
40
+ ];
41
+ const equalityOperators = [
42
+ { label: "=", boost: 10, type: "operator" },
43
+ { label: "!=", boost: 9, type: "operator" }
44
+ ];
45
+ const stringOperators = [
46
+ ...equalityOperators,
47
+ { label: "in", boost: 6, type: "operator" },
48
+ { label: "contains", boost: 5, type: "operator" },
49
+ { label: "starts", boost: 5, type: "operator" },
50
+ { label: "ends", boost: 4, type: "operator" }
51
+ ];
52
+ const numericOperators = [
53
+ ...equalityOperators,
54
+ { label: ">", boost: 8, type: "operator" },
55
+ { label: "<", boost: 7, type: "operator" }
56
+ ];
57
+ const getRelationalOperators = (column) => {
58
+ if (column === void 0 || vuuUtils.isNumericColumn(column)) {
59
+ return numericOperators;
60
+ } else {
61
+ return equalityOperators;
62
+ }
63
+ };
64
+ const getNamePrompt = (entity) => {
65
+ const label = entity ? `enter name for this ${entity}` : "enter name";
66
+ return [{ label, boost: 5 }];
67
+ };
68
+
69
+ exports.asNameSuggestion = asNameSuggestion;
70
+ exports.booleanJoinSuggestions = booleanJoinSuggestions;
71
+ exports.equalityOperators = equalityOperators;
72
+ exports.getNamePrompt = getNamePrompt;
73
+ exports.getRelationalOperators = getRelationalOperators;
74
+ exports.numericOperators = numericOperators;
75
+ exports.stringOperators = stringOperators;
76
+ exports.toSuggestions = toSuggestions;
77
+ //# sourceMappingURL=suggestion-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestion-utils.js","sources":["../src/suggestion-utils.ts"],"sourcesContent":["import { Completion } from \"@codemirror/autocomplete\";\nimport { AnnotationType } from \"@codemirror/state\";\nimport { EditorView } from \"@codemirror/view\";\nimport type { ColumnDescriptor } from \"@vuu-ui/vuu-table-types\";\nimport { isNumericColumn } from \"@vuu-ui/vuu-utils\";\n\nexport interface VuuCompletion extends Completion {\n isIllustration?: boolean;\n}\n\nexport type CompletionOptions = {\n moveCursorToEnd?: boolean;\n prefix?: string;\n quoted?: boolean;\n suffix?: string;\n isIllustration?: boolean;\n};\n\nconst NO_OPTIONS: CompletionOptions = {};\n\nconst applyWithCursorMove =\n () => (view: EditorView, completion: Completion, from: number) => {\n const annotation = new AnnotationType<Completion>();\n view.dispatch(\n {\n changes: { from, insert: completion.label },\n annotations: annotation.of(completion),\n },\n {\n changes: { from: from + 1, insert: \" \" },\n selection: { anchor: from + 2, head: from + 2 },\n annotations: annotation.of(completion),\n },\n );\n };\n\nexport const toSuggestions = (\n values: string[],\n options = NO_OPTIONS,\n): VuuCompletion[] => {\n const {\n moveCursorToEnd = false,\n prefix = \"\",\n quoted = false,\n suffix = \" \",\n isIllustration = false,\n } = options;\n const quote = quoted ? '\"' : \"\";\n return values.map((value) => ({\n isIllustration,\n label: value,\n apply: moveCursorToEnd\n ? applyWithCursorMove()\n : isIllustration\n ? `${quote}${prefix}${quote}`\n : `${prefix}${quote}${value}${quote}${suffix}`,\n }));\n};\n\nexport const asNameSuggestion = { label: \"as\", apply: \"as \", boost: 1 };\n\nexport const booleanJoinSuggestions: Completion[] = [\n { label: \"and\", apply: \"and \", boost: 5 },\n { label: \"or\", apply: \"or \", boost: 3 },\n];\n\nexport const equalityOperators: Completion[] = [\n { label: \"=\", boost: 10, type: \"operator\" },\n { label: \"!=\", boost: 9, type: \"operator\" },\n];\n\nexport const stringOperators: Completion[] = [\n ...equalityOperators,\n { label: \"in\", boost: 6, type: \"operator\" },\n { label: \"contains\", boost: 5, type: \"operator\" },\n { label: \"starts\", boost: 5, type: \"operator\" },\n { label: \"ends\", boost: 4, type: \"operator\" },\n];\n\nexport const numericOperators: Completion[] = [\n ...equalityOperators,\n { label: \">\", boost: 8, type: \"operator\" },\n { label: \"<\", boost: 7, type: \"operator\" },\n];\n\nexport const getRelationalOperators = (column?: ColumnDescriptor) => {\n if (column === undefined || isNumericColumn(column)) {\n return numericOperators;\n } else {\n return equalityOperators;\n }\n};\n\nexport const getNamePrompt = (entity?: string) => {\n const label = entity ? `enter name for this ${entity}` : \"enter name\";\n return [{ label, boost: 5 }];\n};\n"],"names":["AnnotationType","isNumericColumn"],"mappings":";;;;;AAkBA,MAAM,aAAgC,EAAC;AAEvC,MAAM,mBACJ,GAAA,MAAM,CAAC,IAAA,EAAkB,YAAwB,IAAiB,KAAA;AAChE,EAAM,MAAA,UAAA,GAAa,IAAIA,oBAA2B,EAAA;AAClD,EAAK,IAAA,CAAA,QAAA;AAAA,IACH;AAAA,MACE,OAAS,EAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,WAAW,KAAM,EAAA;AAAA,MAC1C,WAAA,EAAa,UAAW,CAAA,EAAA,CAAG,UAAU;AAAA,KACvC;AAAA,IACA;AAAA,MACE,SAAS,EAAE,IAAA,EAAM,IAAO,GAAA,CAAA,EAAG,QAAQ,GAAI,EAAA;AAAA,MACvC,WAAW,EAAE,MAAA,EAAQ,OAAO,CAAG,EAAA,IAAA,EAAM,OAAO,CAAE,EAAA;AAAA,MAC9C,WAAA,EAAa,UAAW,CAAA,EAAA,CAAG,UAAU;AAAA;AACvC,GACF;AACF,CAAA;AAEK,MAAM,aAAgB,GAAA,CAC3B,MACA,EAAA,OAAA,GAAU,UACU,KAAA;AACpB,EAAM,MAAA;AAAA,IACJ,eAAkB,GAAA,KA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AW,EAAA;AAAA,EAChD,EAAE,KAAO,EAAA,QAAA,EAAU,KAAO,EAAA,CAAA,EAAG,MAAM,UAAW,EAAA;AAAA,EAC9C,EAAE,KAAO,EAAA,MAAA,EAAQ,KAAO,EAAA,CAAA,EAAG,MAAM,UAAW;AAC9C;AAEO,MAAM,gBAAiC,GAAA;AAAA,EAC5C,GAAG,iBAAA;AAAA,EACH,EAAE,KAAO,EAAA,GAAA,EAAK,KAAO,EAAA,CAAA,EAAG,MAAM,UAAW,EAAA;AAAA,EACzC,EAAE,KAAO,EAAA,GAAA,EAAK,KAAO,EAAA,CAAA,EAAG,MAAM,UAAW;AAC3C;AAEa,MAAA,sBAAA,GAAyB,CAAC,MAA8B,KAAA;AACnE,EAAA,IAAI,MAAW,KAAA,KAAA,CAAA,IAAaC,wBAAgB,CAAA,MAAM,CAAG,EAAA;AACnD,IAAO,OAAA,gBAAA;AAAA,GACF,MAAA;AACL,IAAO,OAAA,iBAAA;AAAA;AAEX;AAEa,MAAA,aAAA,GAAgB,CAAC,MAAoB,KAAA;AAChD,EAAA,MAAM,KAAQ,GAAA,MAAA,GAAS,CAAuB,oBAAA,EAAA,MAAM,CAAK,CAAA,GAAA,YAAA;AACzD,EAAA,OAAO,CAAC,EAAE,KAAO,EAAA,KAAA,EAAO,GAAG,CAAA;AAC7B;;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ import { closeBrackets } from '@codemirror/autocomplete';
2
+ import { defaultKeymap, historyKeymap, history } from '@codemirror/commands';
3
+ import { syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language';
4
+ import { highlightSpecialChars, drawSelection, keymap } from '@codemirror/view';
5
+
6
+ const keyBindings = [
7
+ ...defaultKeymap,
8
+ ...historyKeymap
9
+ ];
10
+ const minimalSetup = (() => [
11
+ highlightSpecialChars(),
12
+ history(),
13
+ drawSelection(),
14
+ closeBrackets(),
15
+ syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
16
+ keymap.of(keyBindings)
17
+ ])();
18
+
19
+ export { minimalSetup };
20
+ //# sourceMappingURL=codemirror-basic-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codemirror-basic-setup.js","sources":["../src/codemirror-basic-setup.ts"],"sourcesContent":["import { closeBrackets } from \"@codemirror/autocomplete\";\nimport { defaultKeymap, history, historyKeymap } from \"@codemirror/commands\";\nimport {\n defaultHighlightStyle,\n syntaxHighlighting,\n} from \"@codemirror/language\";\nimport { Extension } from \"@codemirror/state\";\nimport {\n drawSelection,\n highlightSpecialChars,\n KeyBinding,\n keymap,\n} from \"@codemirror/view\";\n\nconst keyBindings = [\n ...defaultKeymap,\n ...historyKeymap,\n] as ReadonlyArray<KeyBinding>;\n\nexport const minimalSetup: Extension = (() => [\n highlightSpecialChars(),\n history(),\n drawSelection(),\n closeBrackets(),\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n keymap.of(keyBindings),\n])();\n"],"names":[],"mappings":";;;;;AAcA,MAAM,WAAc,GAAA;AAAA,EAClB,GAAG,aAAA;AAAA,EACH,GAAG;AACL,CAAA;AAEO,MAAM,gBAA2B,MAAM;AAAA,EAC5C,qBAAsB,EAAA;AAAA,EACtB,OAAQ,EAAA;AAAA,EACR,aAAc,EAAA;AAAA,EACd,aAAc,EAAA;AAAA,EACd,kBAAmB,CAAA,qBAAA,EAAuB,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EAC5D,MAAA,CAAO,GAAG,WAAW;AACvB,CAAG;;;;"}
package/esm/index.js CHANGED
@@ -1,126 +1,11 @@
1
- import { closeBrackets } from '@codemirror/autocomplete';
2
1
  export { autocompletion, closeBrackets, startCompletion } from '@codemirror/autocomplete';
3
- import { defaultKeymap, historyKeymap, history } from '@codemirror/commands';
4
2
  export { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
5
- import { syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language';
6
3
  export { HighlightStyle, LRLanguage, LanguageSupport, defaultHighlightStyle, ensureSyntaxTree, syntaxHighlighting, syntaxTree } from '@codemirror/language';
7
- import { AnnotationType } from '@codemirror/state';
8
4
  export { AnnotationType, EditorState } from '@codemirror/state';
9
- import { highlightSpecialChars, drawSelection, keymap } from '@codemirror/view';
10
5
  export { EditorView, drawSelection, highlightSpecialChars, keymap } from '@codemirror/view';
11
6
  export { Tree } from '@lezer/common';
12
7
  export { styleTags, tags } from '@lezer/highlight';
13
- import { isNumericColumn } from '@vuu-ui/vuu-utils';
14
-
15
- const keyBindings = [
16
- ...defaultKeymap,
17
- ...historyKeymap
18
- ];
19
- const minimalSetup = (() => [
20
- highlightSpecialChars(),
21
- history(),
22
- drawSelection(),
23
- closeBrackets(),
24
- syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
25
- keymap.of(keyBindings)
26
- ])();
27
-
28
- const getValue = (node, state) => state.doc.sliceString(node.from, node.to);
29
- const getNodeByName = (node, state, nodeName = "Column") => {
30
- if (node.firstChild?.name === nodeName) {
31
- return getValue(node.firstChild, state);
32
- } else {
33
- let maybeColumnNode = node.prevSibling || node.parent;
34
- while (maybeColumnNode && maybeColumnNode.name !== nodeName) {
35
- maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
36
- }
37
- if (maybeColumnNode) {
38
- return getValue(maybeColumnNode, state);
39
- }
40
- }
41
- };
42
- const getPreviousNode = (node) => {
43
- const prevNode = node.prevSibling;
44
- console.log(`prevNode ${prevNode?.name}`);
45
- return prevNode;
46
- };
47
- const getNamedParentNode = (node) => {
48
- let maybeParent = node.parent;
49
- while (maybeParent && maybeParent.name === "\u26A0") {
50
- maybeParent = maybeParent.parent;
51
- }
52
- return maybeParent;
53
- };
54
- const getPreviousNamedNode = (node) => {
55
- let maybeParent = node.prevSibling;
56
- while (maybeParent && maybeParent.name === "\u26A0") {
57
- maybeParent = maybeParent.prevSibling;
58
- }
59
- return maybeParent;
60
- };
61
-
62
- const NO_OPTIONS = {};
63
- const applyWithCursorMove = () => (view, completion, from) => {
64
- const annotation = new AnnotationType();
65
- view.dispatch(
66
- {
67
- changes: { from, insert: completion.label },
68
- annotations: annotation.of(completion)
69
- },
70
- {
71
- changes: { from: from + 1, insert: " " },
72
- selection: { anchor: from + 2, head: from + 2 },
73
- annotations: annotation.of(completion)
74
- }
75
- );
76
- };
77
- const toSuggestions = (values, options = NO_OPTIONS) => {
78
- const {
79
- moveCursorToEnd = false,
80
- prefix = "",
81
- quoted = false,
82
- suffix = " ",
83
- isIllustration = false
84
- } = options;
85
- const quote = quoted ? '"' : "";
86
- return values.map((value) => ({
87
- isIllustration,
88
- label: value,
89
- apply: moveCursorToEnd ? applyWithCursorMove() : isIllustration ? `${quote}${prefix}${quote}` : `${prefix}${quote}${value}${quote}${suffix}`
90
- }));
91
- };
92
- const asNameSuggestion = { label: "as", apply: "as ", boost: 1 };
93
- const booleanJoinSuggestions = [
94
- { label: "and", apply: "and ", boost: 5 },
95
- { label: "or", apply: "or ", boost: 3 }
96
- ];
97
- const equalityOperators = [
98
- { label: "=", boost: 10, type: "operator" },
99
- { label: "!=", boost: 9, type: "operator" }
100
- ];
101
- const stringOperators = [
102
- ...equalityOperators,
103
- { label: "in", boost: 6, type: "operator" },
104
- { label: "contains", boost: 5, type: "operator" },
105
- { label: "starts", boost: 5, type: "operator" },
106
- { label: "ends", boost: 4, type: "operator" }
107
- ];
108
- const numericOperators = [
109
- ...equalityOperators,
110
- { label: ">", boost: 8, type: "operator" },
111
- { label: "<", boost: 7, type: "operator" }
112
- ];
113
- const getRelationalOperators = (column) => {
114
- if (column === void 0 || isNumericColumn(column)) {
115
- return numericOperators;
116
- } else {
117
- return equalityOperators;
118
- }
119
- };
120
- const getNamePrompt = (entity) => {
121
- const label = entity ? `enter name for this ${entity}` : "enter name";
122
- return [{ label, boost: 5 }];
123
- };
124
-
125
- export { asNameSuggestion, booleanJoinSuggestions, equalityOperators, getNamePrompt, getNamedParentNode, getNodeByName, getPreviousNamedNode, getPreviousNode, getRelationalOperators, getValue, minimalSetup, numericOperators, stringOperators, toSuggestions };
8
+ export { minimalSetup } from './codemirror-basic-setup.js';
9
+ export { getNamedParentNode, getNodeByName, getPreviousNamedNode, getPreviousNode, getValue } from './parser-utils.js';
10
+ export { asNameSuggestion, booleanJoinSuggestions, equalityOperators, getNamePrompt, getRelationalOperators, numericOperators, stringOperators, toSuggestions } from './suggestion-utils.js';
126
11
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/codemirror-basic-setup.ts","../src/parser-utils.ts","../src/suggestion-utils.ts"],"sourcesContent":["import { closeBrackets } from \"@codemirror/autocomplete\";\nimport { defaultKeymap, history, historyKeymap } from \"@codemirror/commands\";\nimport {\n defaultHighlightStyle,\n syntaxHighlighting,\n} from \"@codemirror/language\";\nimport { Extension } from \"@codemirror/state\";\nimport {\n drawSelection,\n highlightSpecialChars,\n KeyBinding,\n keymap,\n} from \"@codemirror/view\";\n\nconst keyBindings = [\n ...defaultKeymap,\n ...historyKeymap,\n] as ReadonlyArray<KeyBinding>;\n\nexport const minimalSetup: Extension = (() => [\n highlightSpecialChars(),\n history(),\n drawSelection(),\n closeBrackets(),\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n keymap.of(keyBindings),\n])();\n","import { EditorState } from \"@codemirror/state\";\nimport type { SyntaxNode } from \"@lezer/common\";\n\nexport const getValue = (node: SyntaxNode, state: EditorState) =>\n state.doc.sliceString(node.from, node.to);\n\nexport const getNodeByName = (\n node: SyntaxNode,\n state: EditorState,\n nodeName = \"Column\"\n) => {\n if (node.firstChild?.name === nodeName) {\n return getValue(node.firstChild, state);\n } else {\n let maybeColumnNode = node.prevSibling || node.parent;\n while (maybeColumnNode && maybeColumnNode.name !== nodeName) {\n maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;\n }\n if (maybeColumnNode) {\n return getValue(maybeColumnNode, state);\n }\n }\n};\n\nexport const getPreviousNode = (node: SyntaxNode) => {\n const prevNode = node.prevSibling;\n console.log(`prevNode ${prevNode?.name}`);\n return prevNode;\n};\n\nexport const getNamedParentNode = (node: SyntaxNode) => {\n let maybeParent = node.parent;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.parent;\n }\n return maybeParent;\n};\n\nexport const getPreviousNamedNode = (node: SyntaxNode) => {\n let maybeParent = node.prevSibling;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.prevSibling;\n }\n return maybeParent;\n};\n","import { Completion } from \"@codemirror/autocomplete\";\nimport { AnnotationType } from \"@codemirror/state\";\nimport { EditorView } from \"@codemirror/view\";\nimport type { ColumnDescriptor } from \"@vuu-ui/vuu-table-types\";\nimport { isNumericColumn } from \"@vuu-ui/vuu-utils\";\n\nexport interface VuuCompletion extends Completion {\n isIllustration?: boolean;\n}\n\nexport type CompletionOptions = {\n moveCursorToEnd?: boolean;\n prefix?: string;\n quoted?: boolean;\n suffix?: string;\n isIllustration?: boolean;\n};\n\nconst NO_OPTIONS: CompletionOptions = {};\n\nconst applyWithCursorMove =\n () => (view: EditorView, completion: Completion, from: number) => {\n const annotation = new AnnotationType<Completion>();\n view.dispatch(\n {\n changes: { from, insert: completion.label },\n annotations: annotation.of(completion),\n },\n {\n changes: { from: from + 1, insert: \" \" },\n selection: { anchor: from + 2, head: from + 2 },\n annotations: annotation.of(completion),\n },\n );\n };\n\nexport const toSuggestions = (\n values: string[],\n options = NO_OPTIONS,\n): VuuCompletion[] => {\n const {\n moveCursorToEnd = false,\n prefix = \"\",\n quoted = false,\n suffix = \" \",\n isIllustration = false,\n } = options;\n const quote = quoted ? '\"' : \"\";\n return values.map((value) => ({\n isIllustration,\n label: value,\n apply: moveCursorToEnd\n ? applyWithCursorMove()\n : isIllustration\n ? `${quote}${prefix}${quote}`\n : `${prefix}${quote}${value}${quote}${suffix}`,\n }));\n};\n\nexport const asNameSuggestion = { label: \"as\", apply: \"as \", boost: 1 };\n\nexport const booleanJoinSuggestions: Completion[] = [\n { label: \"and\", apply: \"and \", boost: 5 },\n { label: \"or\", apply: \"or \", boost: 3 },\n];\n\nexport const equalityOperators: Completion[] = [\n { label: \"=\", boost: 10, type: \"operator\" },\n { label: \"!=\", boost: 9, type: \"operator\" },\n];\n\nexport const stringOperators: Completion[] = [\n ...equalityOperators,\n { label: \"in\", boost: 6, type: \"operator\" },\n { label: \"contains\", boost: 5, type: \"operator\" },\n { label: \"starts\", boost: 5, type: \"operator\" },\n { label: \"ends\", boost: 4, type: \"operator\" },\n];\n\nexport const numericOperators: Completion[] = [\n ...equalityOperators,\n { label: \">\", boost: 8, type: \"operator\" },\n { label: \"<\", boost: 7, type: \"operator\" },\n];\n\nexport const getRelationalOperators = (column?: ColumnDescriptor) => {\n if (column === undefined || isNumericColumn(column)) {\n return numericOperators;\n } else {\n return equalityOperators;\n }\n};\n\nexport const getNamePrompt = (entity?: string) => {\n const label = entity ? `enter name for this ${entity}` : \"enter name\";\n return [{ label, boost: 5 }];\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,WAAc,GAAA;AAAA,EAClB,GAAG,aAAA;AAAA,EACH,GAAG;AACL,CAAA;AAEO,MAAM,gBAA2B,MAAM;AAAA,EAC5C,qBAAsB,EAAA;AAAA,EACtB,OAAQ,EAAA;AAAA,EACR,aAAc,EAAA;AAAA,EACd,aAAc,EAAA;AAAA,EACd,kBAAmB,CAAA,qBAAA,EAAuB,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EAC5D,MAAA,CAAO,GAAG,WAAW;AACvB,CAAG;;ACvBU,MAAA,QAAA,GAAW,CAAC,IAAA,EAAkB,KACzC,KAAA,KAAA,CAAM,IAAI,WAAY,CAAA,IAAA,CAAK,IAAM,EAAA,IAAA,CAAK,EAAE;AAEnC,MAAM,aAAgB,GAAA,CAC3B,IACA,EAAA,KAAA,EACA,WAAW,QACR,KAAA;AACH,EAAI,IAAA,IAAA,CAAK,UAAY,EAAA,IAAA,KAAS,QAAU,EAAA;AACtC,IAAO,OAAA,QAAA,CAAS,IA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K,CAAA,GAAA,YAAA;AACzD,EAAA,OAAO,CAAC,EAAE,KAAO,EAAA,KAAA,EAAO,GAAG,CAAA;AAC7B;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,36 @@
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) {
4
+ return getValue(node.firstChild, state);
5
+ } else {
6
+ let maybeColumnNode = node.prevSibling || node.parent;
7
+ while (maybeColumnNode && maybeColumnNode.name !== nodeName) {
8
+ maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;
9
+ }
10
+ if (maybeColumnNode) {
11
+ return getValue(maybeColumnNode, state);
12
+ }
13
+ }
14
+ };
15
+ const getPreviousNode = (node) => {
16
+ const prevNode = node.prevSibling;
17
+ console.log(`prevNode ${prevNode?.name}`);
18
+ return prevNode;
19
+ };
20
+ const getNamedParentNode = (node) => {
21
+ let maybeParent = node.parent;
22
+ while (maybeParent && maybeParent.name === "\u26A0") {
23
+ maybeParent = maybeParent.parent;
24
+ }
25
+ return maybeParent;
26
+ };
27
+ const getPreviousNamedNode = (node) => {
28
+ let maybeParent = node.prevSibling;
29
+ while (maybeParent && maybeParent.name === "\u26A0") {
30
+ maybeParent = maybeParent.prevSibling;
31
+ }
32
+ return maybeParent;
33
+ };
34
+
35
+ export { getNamedParentNode, getNodeByName, getPreviousNamedNode, getPreviousNode, getValue };
36
+ //# sourceMappingURL=parser-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser-utils.js","sources":["../src/parser-utils.ts"],"sourcesContent":["import { EditorState } from \"@codemirror/state\";\nimport type { SyntaxNode } from \"@lezer/common\";\n\nexport const getValue = (node: SyntaxNode, state: EditorState) =>\n state.doc.sliceString(node.from, node.to);\n\nexport const getNodeByName = (\n node: SyntaxNode,\n state: EditorState,\n nodeName = \"Column\"\n) => {\n if (node.firstChild?.name === nodeName) {\n return getValue(node.firstChild, state);\n } else {\n let maybeColumnNode = node.prevSibling || node.parent;\n while (maybeColumnNode && maybeColumnNode.name !== nodeName) {\n maybeColumnNode = maybeColumnNode.prevSibling || maybeColumnNode.parent;\n }\n if (maybeColumnNode) {\n return getValue(maybeColumnNode, state);\n }\n }\n};\n\nexport const getPreviousNode = (node: SyntaxNode) => {\n const prevNode = node.prevSibling;\n console.log(`prevNode ${prevNode?.name}`);\n return prevNode;\n};\n\nexport const getNamedParentNode = (node: SyntaxNode) => {\n let maybeParent = node.parent;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.parent;\n }\n return maybeParent;\n};\n\nexport const getPreviousNamedNode = (node: SyntaxNode) => {\n let maybeParent = node.prevSibling;\n while (maybeParent && maybeParent.name === \"⚠\") {\n maybeParent = maybeParent.prevSibling;\n }\n return maybeParent;\n};\n"],"names":[],"mappings":"AAGa,MAAA,QAAA,GAAW,CAAC,IAAA,EAAkB,KACzC,KAAA,KAAA,CAAM,IAAI,WAAY,CAAA,IAAA,CAAK,IAAM,EAAA,IAAA,CAAK,EAAE;AAEnC,MAAM,aAAgB,GAAA,CAC3B,IACA,EAAA,KAAA,EACA,WAAW,QACR,KAAA;AACH,EAAI,IAAA,IAAA,CAAK,UAAY,EAAA,IAAA,KAAS,QAAU,EAAA;AACtC,IAAO,OAAA,QAAA,CAAS,IAAK,CAAA,UAAA,EAAY,KAAK,CAAA;AAAA,GACjC,MAAA;AACL,IAAI,IAAA,eAAA,GAAkB,IAAK,CAAA,WAAA,IAAe,IAAK,CAAA,MAAA;AAC/C,IAAO,OAAA,eAAA,IAAmB,eAAgB,CAAA,IAAA,KAAS,QAAU,EAAA;AAC3D,MAAkB,eAAA,GAAA,eAAA,CAAgB,eAAe,eAAgB,CAAA,MAAA;AAAA;AAEnE,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAO,OAAA,QAAA,CAAS,iBAAiB,KAAK,CAAA;AAAA;AACxC;AAEJ;AAEa,MAAA,eAAA,GAAkB,CAAC,IAAqB,KAAA;AACnD,EAAA,MAAM,WAAW,IAAK,CAAA,WAAA;AACtB,EAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,SAAA,EAAY,QAAU,EAAA,IAAI,CAAE,CAAA,CAAA;AACxC,EAAO,OAAA,QAAA;AACT;AAEa,MAAA,kBAAA,GAAqB,CAAC,IAAqB,KAAA;AACtD,EAAA,IAAI,cAAc,IAAK,CAAA,MAAA;AACvB,EAAO,OAAA,WAAA,IAAe,WAAY,CAAA,IAAA,KAAS,QAAK,EAAA;AAC9C,IAAA,WAAA,GAAc,WAAY,CAAA,MAAA;AAAA;AAE5B,EAAO,OAAA,WAAA;AACT;AAEa,MAAA,oBAAA,GAAuB,CAAC,IAAqB,KAAA;AACxD,EAAA,IAAI,cAAc,IAAK,CAAA,WAAA;AACvB,EAAO,OAAA,WAAA,IAAe,WAAY,CAAA,IAAA,KAAS,QAAK,EAAA;AAC9C,IAAA,WAAA,GAAc,WAAY,CAAA,WAAA;AAAA;AAE5B,EAAO,OAAA,WAAA;AACT;;;;"}
@@ -0,0 +1,68 @@
1
+ import { AnnotationType } from '@codemirror/state';
2
+ import { isNumericColumn } from '@vuu-ui/vuu-utils';
3
+
4
+ const NO_OPTIONS = {};
5
+ const applyWithCursorMove = () => (view, completion, from) => {
6
+ const annotation = new AnnotationType();
7
+ view.dispatch(
8
+ {
9
+ changes: { from, insert: completion.label },
10
+ annotations: annotation.of(completion)
11
+ },
12
+ {
13
+ changes: { from: from + 1, insert: " " },
14
+ selection: { anchor: from + 2, head: from + 2 },
15
+ annotations: annotation.of(completion)
16
+ }
17
+ );
18
+ };
19
+ const toSuggestions = (values, options = NO_OPTIONS) => {
20
+ const {
21
+ moveCursorToEnd = false,
22
+ prefix = "",
23
+ quoted = false,
24
+ suffix = " ",
25
+ isIllustration = false
26
+ } = options;
27
+ const quote = quoted ? '"' : "";
28
+ return values.map((value) => ({
29
+ isIllustration,
30
+ label: value,
31
+ apply: moveCursorToEnd ? applyWithCursorMove() : isIllustration ? `${quote}${prefix}${quote}` : `${prefix}${quote}${value}${quote}${suffix}`
32
+ }));
33
+ };
34
+ const asNameSuggestion = { label: "as", apply: "as ", boost: 1 };
35
+ const booleanJoinSuggestions = [
36
+ { label: "and", apply: "and ", boost: 5 },
37
+ { label: "or", apply: "or ", boost: 3 }
38
+ ];
39
+ const equalityOperators = [
40
+ { label: "=", boost: 10, type: "operator" },
41
+ { label: "!=", boost: 9, type: "operator" }
42
+ ];
43
+ const stringOperators = [
44
+ ...equalityOperators,
45
+ { label: "in", boost: 6, type: "operator" },
46
+ { label: "contains", boost: 5, type: "operator" },
47
+ { label: "starts", boost: 5, type: "operator" },
48
+ { label: "ends", boost: 4, type: "operator" }
49
+ ];
50
+ const numericOperators = [
51
+ ...equalityOperators,
52
+ { label: ">", boost: 8, type: "operator" },
53
+ { label: "<", boost: 7, type: "operator" }
54
+ ];
55
+ const getRelationalOperators = (column) => {
56
+ if (column === void 0 || isNumericColumn(column)) {
57
+ return numericOperators;
58
+ } else {
59
+ return equalityOperators;
60
+ }
61
+ };
62
+ const getNamePrompt = (entity) => {
63
+ const label = entity ? `enter name for this ${entity}` : "enter name";
64
+ return [{ label, boost: 5 }];
65
+ };
66
+
67
+ export { asNameSuggestion, booleanJoinSuggestions, equalityOperators, getNamePrompt, getRelationalOperators, numericOperators, stringOperators, toSuggestions };
68
+ //# sourceMappingURL=suggestion-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestion-utils.js","sources":["../src/suggestion-utils.ts"],"sourcesContent":["import { Completion } from \"@codemirror/autocomplete\";\nimport { AnnotationType } from \"@codemirror/state\";\nimport { EditorView } from \"@codemirror/view\";\nimport type { ColumnDescriptor } from \"@vuu-ui/vuu-table-types\";\nimport { isNumericColumn } from \"@vuu-ui/vuu-utils\";\n\nexport interface VuuCompletion extends Completion {\n isIllustration?: boolean;\n}\n\nexport type CompletionOptions = {\n moveCursorToEnd?: boolean;\n prefix?: string;\n quoted?: boolean;\n suffix?: string;\n isIllustration?: boolean;\n};\n\nconst NO_OPTIONS: CompletionOptions = {};\n\nconst applyWithCursorMove =\n () => (view: EditorView, completion: Completion, from: number) => {\n const annotation = new AnnotationType<Completion>();\n view.dispatch(\n {\n changes: { from, insert: completion.label },\n annotations: annotation.of(completion),\n },\n {\n changes: { from: from + 1, insert: \" \" },\n selection: { anchor: from + 2, head: from + 2 },\n annotations: annotation.of(completion),\n },\n );\n };\n\nexport const toSuggestions = (\n values: string[],\n options = NO_OPTIONS,\n): VuuCompletion[] => {\n const {\n moveCursorToEnd = false,\n prefix = \"\",\n quoted = false,\n suffix = \" \",\n isIllustration = false,\n } = options;\n const quote = quoted ? '\"' : \"\";\n return values.map((value) => ({\n isIllustration,\n label: value,\n apply: moveCursorToEnd\n ? applyWithCursorMove()\n : isIllustration\n ? `${quote}${prefix}${quote}`\n : `${prefix}${quote}${value}${quote}${suffix}`,\n }));\n};\n\nexport const asNameSuggestion = { label: \"as\", apply: \"as \", boost: 1 };\n\nexport const booleanJoinSuggestions: Completion[] = [\n { label: \"and\", apply: \"and \", boost: 5 },\n { label: \"or\", apply: \"or \", boost: 3 },\n];\n\nexport const equalityOperators: Completion[] = [\n { label: \"=\", boost: 10, type: \"operator\" },\n { label: \"!=\", boost: 9, type: \"operator\" },\n];\n\nexport const stringOperators: Completion[] = [\n ...equalityOperators,\n { label: \"in\", boost: 6, type: \"operator\" },\n { label: \"contains\", boost: 5, type: \"operator\" },\n { label: \"starts\", boost: 5, type: \"operator\" },\n { label: \"ends\", boost: 4, type: \"operator\" },\n];\n\nexport const numericOperators: Completion[] = [\n ...equalityOperators,\n { label: \">\", boost: 8, type: \"operator\" },\n { label: \"<\", boost: 7, type: \"operator\" },\n];\n\nexport const getRelationalOperators = (column?: ColumnDescriptor) => {\n if (column === undefined || isNumericColumn(column)) {\n return numericOperators;\n } else {\n return equalityOperators;\n }\n};\n\nexport const getNamePrompt = (entity?: string) => {\n const label = entity ? `enter name for this ${entity}` : \"enter name\";\n return [{ label, boost: 5 }];\n};\n"],"names":[],"mappings":";;;AAkBA,MAAM,aAAgC,EAAC;AAEvC,MAAM,mBACJ,GAAA,MAAM,CAAC,IAAA,EAAkB,YAAwB,IAAiB,KAAA;AAChE,EAAM,MAAA,UAAA,GAAa,IAAI,cAA2B,EAAA;AAClD,EAAK,IAAA,CAAA,QAAA;AAAA,IACH;AAAA,MACE,OAAS,EAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,WAAW,KAAM,EAAA;AAAA,MAC1C,WAAA,EAAa,UAAW,CAAA,EAAA,CAAG,UAAU;AAAA,KACvC;AAAA,IACA;AAAA,MACE,SAAS,EAAE,IAAA,EAAM,IAAO,GAAA,CAAA,EAAG,QAAQ,GAAI,EAAA;AAAA,MACvC,WAAW,EAAE,MAAA,EAAQ,OAAO,CAAG,EAAA,IAAA,EAAM,OAAO,CAAE,EAAA;AAAA,MAC9C,WAAA,EAAa,UAAW,CAAA,EAAA,CAAG,UAAU;AAAA;AACvC,GACF;AACF,CAAA;AAEK,MAAM,aAAgB,GAAA,CAC3B,MACA,EAAA,OAAA,GAAU,UACU,KAAA;AACpB,EAAM,MAAA;AAAA,IACJ,eAAkB,GAAA,KAAA;AAAA,IAClB,MAAS,GAAA,EAAA;AAAA,IACT,MAAS,GAAA,KAAA;AAAA,IACT,MAAS,GAAA,GAAA;AAAA,IACT,cAAiB,GAAA;AAAA,GACf,GAAA,OAAA;AACJ,EAAM,MAAA,KAAA,GAAQ,SAAS,GAAM,GAAA,EAAA;AAC7B,EAAO,OAAA,MAAA,CAAO,GAAI,CAAA,CAAC,KAAW,MAAA;AAAA,IAC5B,cAAA;AAAA,IACA,KAAO,EAAA,KAAA;AAAA,IACP,KAAA,EAAO,kBACH,mBAAoB,EAAA,GACpB,iBACE,CAAG,EAAA,KAAK,GAAG,MAAM,CAAA,EAAG,KAAK,CACzB,CAAA,GAAA,CAAA,EAAG,MAAM,CAAG,E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ACnE,EAAA,IAAI,MAAW,KAAA,KAAA,CAAA,IAAa,eAAgB,CAAA,MAAM,CAAG,EAAA;AACnD,IAAO,OAAA,gBAAA;AAAA,GACF,MAAA;AACL,IAAO,OAAA,iBAAA;AAAA;AAEX;AAEa,MAAA,aAAA,GAAgB,CAAC,MAAoB,KAAA;AAChD,EAAA,MAAM,KAAQ,GAAA,MAAA,GAAS,CAAuB,oBAAA,EAAA,MAAM,CAAK,CAAA,GAAA,YAAA;AACzD,EAAA,OAAO,CAAC,EAAE,KAAO,EAAA,KAAA,EAAO,GAAG,CAAA;AAC7B;;;;"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "0.13.9",
2
+ "version": "0.13.11",
3
3
  "author": "heswell",
4
4
  "license": "Apache-2.0",
5
5
  "devDependencies": {
6
- "@vuu-ui/vuu-table-types": "0.13.9"
6
+ "@vuu-ui/vuu-table-types": "0.13.11"
7
7
  },
8
8
  "dependencies": {
9
9
  "@codemirror/autocomplete": "^6.4.2",
@@ -11,7 +11,7 @@
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": "0.13.9",
14
+ "@vuu-ui/vuu-utils": "0.13.11",
15
15
  "@lezer/common": "1.2.3",
16
16
  "@lezer/highlight": "^1.1.3"
17
17
  },