@neo4j-cypher/react-codemirror 1.0.4 → 2.0.0-canary-a1ed8f3
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/CHANGELOG.md +68 -0
- package/LICENSE.md +201 -0
- package/README.md +29 -27
- package/dist/CypherEditor.d.ts +153 -0
- package/dist/CypherEditor.js +242 -0
- package/dist/CypherEditor.js.map +1 -0
- package/dist/e2e_tests/autoCompletion.spec.d.ts +1 -0
- package/dist/e2e_tests/autoCompletion.spec.js +133 -0
- package/dist/e2e_tests/autoCompletion.spec.js.map +1 -0
- package/dist/e2e_tests/configuration.spec.d.ts +1 -0
- package/dist/e2e_tests/configuration.spec.js +73 -0
- package/dist/e2e_tests/configuration.spec.js.map +1 -0
- package/dist/e2e_tests/e2eUtils.d.ts +12 -0
- package/dist/e2e_tests/e2eUtils.js +60 -0
- package/dist/e2e_tests/e2eUtils.js.map +1 -0
- package/dist/e2e_tests/extraKeybindings.spec.d.ts +1 -0
- package/dist/e2e_tests/extraKeybindings.spec.js +44 -0
- package/dist/e2e_tests/extraKeybindings.spec.js.map +1 -0
- package/dist/e2e_tests/historyNavigation.spec.d.ts +1 -0
- package/dist/e2e_tests/historyNavigation.spec.js +136 -0
- package/dist/e2e_tests/historyNavigation.spec.js.map +1 -0
- package/dist/e2e_tests/performanceTest.spec.d.ts +6 -0
- package/dist/e2e_tests/performanceTest.spec.js +96 -0
- package/dist/e2e_tests/performanceTest.spec.js.map +1 -0
- package/dist/e2e_tests/sanityChecks.spec.d.ts +1 -0
- package/dist/e2e_tests/sanityChecks.spec.js +56 -0
- package/dist/e2e_tests/sanityChecks.spec.js.map +1 -0
- package/dist/e2e_tests/signatureHelp.spec.d.ts +1 -0
- package/dist/e2e_tests/signatureHelp.spec.js +152 -0
- package/dist/e2e_tests/signatureHelp.spec.js.map +1 -0
- package/dist/e2e_tests/snippets.spec.d.ts +1 -0
- package/dist/e2e_tests/snippets.spec.js +63 -0
- package/dist/e2e_tests/snippets.spec.js.map +1 -0
- package/dist/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
- package/dist/e2e_tests/syntaxHighlighting.spec.js +91 -0
- package/dist/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
- package/dist/e2e_tests/syntaxValidation.spec.d.ts +1 -0
- package/dist/e2e_tests/syntaxValidation.spec.js +79 -0
- package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -0
- package/dist/historyNavigation.d.ts +7 -0
- package/dist/historyNavigation.js +163 -0
- package/dist/historyNavigation.js.map +1 -0
- package/dist/icons.d.ts +2 -0
- package/dist/icons.js +62 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lang-cypher/autocomplete.d.ts +3 -0
- package/dist/lang-cypher/autocomplete.js +62 -0
- package/dist/lang-cypher/autocomplete.js.map +1 -0
- package/dist/lang-cypher/constants.d.ts +40 -0
- package/dist/lang-cypher/constants.js +65 -0
- package/dist/lang-cypher/constants.js.map +1 -0
- package/dist/lang-cypher/contants.test.d.ts +1 -0
- package/dist/lang-cypher/contants.test.js +102 -0
- package/dist/lang-cypher/contants.test.js.map +1 -0
- package/dist/lang-cypher/createCypherTheme.d.ts +26 -0
- package/dist/lang-cypher/createCypherTheme.js +172 -0
- package/dist/lang-cypher/createCypherTheme.js.map +1 -0
- package/dist/lang-cypher/langCypher.d.ts +9 -0
- package/dist/lang-cypher/langCypher.js +24 -0
- package/dist/lang-cypher/langCypher.js.map +1 -0
- package/dist/lang-cypher/lintWorker.d.ts +8 -0
- package/dist/lang-cypher/lintWorker.js +4 -0
- package/dist/lang-cypher/lintWorker.js.map +1 -0
- package/dist/lang-cypher/parser-adapter.d.ts +19 -0
- package/dist/lang-cypher/parser-adapter.js +113 -0
- package/dist/lang-cypher/parser-adapter.js.map +1 -0
- package/dist/lang-cypher/signatureHelp.d.ts +4 -0
- package/dist/lang-cypher/signatureHelp.js +93 -0
- package/dist/lang-cypher/signatureHelp.js.map +1 -0
- package/dist/lang-cypher/syntaxValidation.d.ts +5 -0
- package/dist/lang-cypher/syntaxValidation.js +71 -0
- package/dist/lang-cypher/syntaxValidation.js.map +1 -0
- package/dist/lang-cypher/themeIcons.d.ts +7 -0
- package/dist/lang-cypher/themeIcons.js +22 -0
- package/dist/lang-cypher/themeIcons.js.map +1 -0
- package/dist/ndlTokensCopy.d.ts +379 -0
- package/dist/ndlTokensCopy.js +380 -0
- package/dist/ndlTokensCopy.js.map +1 -0
- package/dist/ndlTokensCopy.test.d.ts +1 -0
- package/dist/ndlTokensCopy.test.js +11 -0
- package/dist/ndlTokensCopy.test.js.map +1 -0
- package/dist/neo4jSetup.d.ts +2 -0
- package/dist/neo4jSetup.js +120 -0
- package/dist/neo4jSetup.js.map +1 -0
- package/dist/themes.d.ts +11 -0
- package/dist/themes.js +114 -0
- package/dist/themes.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +60 -37
- package/src/CypherEditor.tsx +461 -0
- package/src/e2e_tests/autoCompletion.spec.tsx +236 -0
- package/src/e2e_tests/configuration.spec.tsx +97 -0
- package/src/e2e_tests/e2eUtils.ts +85 -0
- package/src/e2e_tests/extraKeybindings.spec.tsx +57 -0
- package/src/e2e_tests/historyNavigation.spec.tsx +196 -0
- package/src/e2e_tests/performanceTest.spec.tsx +158 -0
- package/src/e2e_tests/sanityChecks.spec.tsx +78 -0
- package/src/e2e_tests/signatureHelp.spec.tsx +309 -0
- package/src/e2e_tests/snippets.spec.tsx +94 -0
- package/src/e2e_tests/syntaxHighlighting.spec.tsx +198 -0
- package/src/e2e_tests/syntaxValidation.spec.tsx +156 -0
- package/src/historyNavigation.ts +191 -0
- package/src/icons.ts +90 -0
- package/src/index.ts +4 -0
- package/src/lang-cypher/autocomplete.ts +81 -0
- package/src/lang-cypher/constants.ts +84 -0
- package/src/lang-cypher/contants.test.ts +104 -0
- package/src/lang-cypher/createCypherTheme.ts +240 -0
- package/src/lang-cypher/langCypher.ts +41 -0
- package/src/lang-cypher/lintWorker.ts +14 -0
- package/src/lang-cypher/parser-adapter.ts +145 -0
- package/src/lang-cypher/signatureHelp.ts +131 -0
- package/src/lang-cypher/syntaxValidation.ts +99 -0
- package/src/lang-cypher/themeIcons.ts +27 -0
- package/src/ndlTokensCopy.test.ts +11 -0
- package/src/ndlTokensCopy.ts +379 -0
- package/src/neo4jSetup.tsx +179 -0
- package/src/themes.ts +132 -0
- package/es/CypherEditor.js +0 -262
- package/es/react-codemirror.js +0 -1
- package/lib/CypherEditor.js +0 -272
- package/lib/react-codemirror.js +0 -13
- package/src/CypherEditor.d.ts +0 -310
- package/src/react-codemirror.d.ts +0 -18
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
acceptCompletion,
|
|
3
|
+
autocompletion,
|
|
4
|
+
clearSnippet,
|
|
5
|
+
closeBrackets,
|
|
6
|
+
closeBracketsKeymap,
|
|
7
|
+
closeCompletion,
|
|
8
|
+
completionKeymap,
|
|
9
|
+
nextSnippetField,
|
|
10
|
+
prevSnippetField,
|
|
11
|
+
snippetKeymap,
|
|
12
|
+
} from '@codemirror/autocomplete';
|
|
13
|
+
import {
|
|
14
|
+
defaultKeymap,
|
|
15
|
+
history,
|
|
16
|
+
historyKeymap,
|
|
17
|
+
indentLess,
|
|
18
|
+
indentMore,
|
|
19
|
+
} from '@codemirror/commands';
|
|
20
|
+
import {
|
|
21
|
+
bracketMatching,
|
|
22
|
+
defaultHighlightStyle,
|
|
23
|
+
foldKeymap,
|
|
24
|
+
indentOnInput,
|
|
25
|
+
syntaxHighlighting,
|
|
26
|
+
} from '@codemirror/language';
|
|
27
|
+
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
|
|
28
|
+
import { EditorState, Extension, StateCommand } from '@codemirror/state';
|
|
29
|
+
import {
|
|
30
|
+
Command,
|
|
31
|
+
crosshairCursor,
|
|
32
|
+
drawSelection,
|
|
33
|
+
dropCursor,
|
|
34
|
+
EditorView,
|
|
35
|
+
highlightSpecialChars,
|
|
36
|
+
KeyBinding,
|
|
37
|
+
keymap,
|
|
38
|
+
rectangularSelection,
|
|
39
|
+
} from '@codemirror/view';
|
|
40
|
+
|
|
41
|
+
import { lintKeymap } from '@codemirror/lint';
|
|
42
|
+
import { getIconForType } from './icons';
|
|
43
|
+
|
|
44
|
+
const insertTab: StateCommand = (cmd) => {
|
|
45
|
+
// if there is a selection we should indent the selected text, but if not insert
|
|
46
|
+
// two spaces as per the cypher style guide
|
|
47
|
+
if (cmd.state.selection.main.from === cmd.state.selection.main.to) {
|
|
48
|
+
cmd.dispatch(
|
|
49
|
+
cmd.state.update({
|
|
50
|
+
changes: {
|
|
51
|
+
from: cmd.state.selection.main.to,
|
|
52
|
+
to: cmd.state.selection.main.to,
|
|
53
|
+
insert: ' ',
|
|
54
|
+
},
|
|
55
|
+
selection: { anchor: cmd.state.selection.main.to + 2 },
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
} else {
|
|
59
|
+
indentMore(cmd);
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const basicNeo4jSetup = (): Extension[] => {
|
|
65
|
+
const keymaps: KeyBinding[] = [
|
|
66
|
+
closeBracketsKeymap,
|
|
67
|
+
defaultKeymap,
|
|
68
|
+
searchKeymap,
|
|
69
|
+
historyKeymap,
|
|
70
|
+
foldKeymap,
|
|
71
|
+
completionKeymap,
|
|
72
|
+
lintKeymap,
|
|
73
|
+
{
|
|
74
|
+
key: 'Tab',
|
|
75
|
+
preventDefault: true,
|
|
76
|
+
run: acceptCompletion,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: 'Tab',
|
|
80
|
+
preventDefault: true,
|
|
81
|
+
run: insertTab,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: 'Shift-Tab',
|
|
85
|
+
preventDefault: true,
|
|
86
|
+
run: indentLess,
|
|
87
|
+
},
|
|
88
|
+
].flat();
|
|
89
|
+
|
|
90
|
+
const extensions: Extension[] = [];
|
|
91
|
+
|
|
92
|
+
extensions.push(highlightSpecialChars());
|
|
93
|
+
extensions.push(history());
|
|
94
|
+
|
|
95
|
+
extensions.push(drawSelection());
|
|
96
|
+
extensions.push(dropCursor());
|
|
97
|
+
extensions.push(EditorState.allowMultipleSelections.of(true));
|
|
98
|
+
extensions.push(indentOnInput());
|
|
99
|
+
extensions.push(
|
|
100
|
+
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
extensions.push(bracketMatching());
|
|
104
|
+
extensions.push(closeBrackets());
|
|
105
|
+
extensions.push(
|
|
106
|
+
autocompletion({
|
|
107
|
+
icons: false,
|
|
108
|
+
interactionDelay: 5,
|
|
109
|
+
addToOptions: [
|
|
110
|
+
{
|
|
111
|
+
render(completion, state) {
|
|
112
|
+
const isDarkTheme = state.facet(EditorView.darkTheme);
|
|
113
|
+
const icon = document.createElement('span');
|
|
114
|
+
|
|
115
|
+
icon.innerHTML = getIconForType(completion.type, isDarkTheme);
|
|
116
|
+
|
|
117
|
+
const svgElement = icon.children[0] as SVGElement;
|
|
118
|
+
|
|
119
|
+
svgElement.style.display = 'inline';
|
|
120
|
+
svgElement.style.marginRight = '5px';
|
|
121
|
+
return icon;
|
|
122
|
+
},
|
|
123
|
+
position: 20,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
extensions.push(rectangularSelection());
|
|
130
|
+
extensions.push(crosshairCursor());
|
|
131
|
+
extensions.push(highlightSelectionMatches());
|
|
132
|
+
|
|
133
|
+
extensions.push(keymap.of(keymaps));
|
|
134
|
+
|
|
135
|
+
extensions.push(
|
|
136
|
+
snippetKeymap.of([
|
|
137
|
+
{
|
|
138
|
+
key: 'Tab',
|
|
139
|
+
run: acceptCompletionOrGotoNextSnippet,
|
|
140
|
+
shift: acceptCompletionOrGotoPrevSnippet,
|
|
141
|
+
},
|
|
142
|
+
{ key: 'Escape', run: closeCompletionsOrClearSnippets },
|
|
143
|
+
]),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return extensions;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// The logic to check if there's a completion open is surprisingly complex
|
|
150
|
+
// https://github.com/codemirror/autocomplete/blob/5ad2ebc861f2f61cdc943fc087a5bfb756a7d0fa/src/view.ts#L31
|
|
151
|
+
// For example it respects an interaction delay, so we can't just check if the completion is open
|
|
152
|
+
// instead we just run the acceptCompletion command which returns true if a completion was accepted
|
|
153
|
+
// in that case we know that we shouldn't move to the next snippet field
|
|
154
|
+
const acceptCompletionOrGotoNextSnippet: Command = (view: EditorView) => {
|
|
155
|
+
const didCompletion = acceptCompletion(view);
|
|
156
|
+
if (didCompletion) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return nextSnippetField(view);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const acceptCompletionOrGotoPrevSnippet: Command = (view: EditorView) => {
|
|
164
|
+
const didCompletion = acceptCompletion(view);
|
|
165
|
+
if (didCompletion) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return prevSnippetField(view);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const closeCompletionsOrClearSnippets: Command = (view: EditorView) => {
|
|
173
|
+
const closedCompletions = closeCompletion(view);
|
|
174
|
+
if (closedCompletions) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return clearSnippet(view);
|
|
179
|
+
};
|
package/src/themes.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { light, mirage } from 'ayu';
|
|
3
|
+
import {
|
|
4
|
+
createCypherTheme,
|
|
5
|
+
ThemeOptions,
|
|
6
|
+
} from './lang-cypher/createCypherTheme';
|
|
7
|
+
import { tokens } from './ndlTokensCopy';
|
|
8
|
+
|
|
9
|
+
/* ndl exports most tokens as hex colors but some tokens are exported as rgb colors, in the form of "10, 20, 30"
|
|
10
|
+
This should be fixed in version 2 of ndl.
|
|
11
|
+
Meanwhile we can use this function */
|
|
12
|
+
const convertToHex = (color: string) => {
|
|
13
|
+
if (color.startsWith('#')) {
|
|
14
|
+
return color;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rgb = color.match(/\d+/g);
|
|
18
|
+
if (!rgb) {
|
|
19
|
+
return color;
|
|
20
|
+
}
|
|
21
|
+
const [r, g, b] = rgb;
|
|
22
|
+
return `#${Number(r).toString(16)}${Number(g).toString(16)}${Number(
|
|
23
|
+
b,
|
|
24
|
+
).toString(16)}`;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const lightThemeConstants: ThemeOptions = {
|
|
28
|
+
dark: false,
|
|
29
|
+
editorSettings: {
|
|
30
|
+
background: light.editor.bg.hex(),
|
|
31
|
+
foreground: light.editor.fg.hex(),
|
|
32
|
+
gutterForeground: light.editor.gutter.normal.hex(),
|
|
33
|
+
selection: light.editor.selection.active.hex(),
|
|
34
|
+
textMatchingSelection: light.editor.findMatch.active.hex(),
|
|
35
|
+
cursor: '#000000',
|
|
36
|
+
autoCompletionPanel: {
|
|
37
|
+
selectedColor: '#cce2ff',
|
|
38
|
+
matchingTextColor: '#0066bf',
|
|
39
|
+
backgroundColor: '#F3F4F5',
|
|
40
|
+
},
|
|
41
|
+
searchPanel: {
|
|
42
|
+
background: tokens.palette.light.neutral.bg.default,
|
|
43
|
+
text: tokens.palette.light.neutral.text.default,
|
|
44
|
+
buttonHoverBackground: tokens.palette.light.neutral.bg.strong,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
highlightStyles: {
|
|
48
|
+
comment: light.syntax.comment.hex(),
|
|
49
|
+
keyword: light.syntax.keyword.hex(),
|
|
50
|
+
keywordLiteral: light.syntax.keyword.hex(),
|
|
51
|
+
label: light.syntax.markup.hex(),
|
|
52
|
+
predicateFunction: light.syntax.func.hex(),
|
|
53
|
+
function: light.syntax.func.hex(),
|
|
54
|
+
procedure: light.syntax.func.hex(),
|
|
55
|
+
stringLiteral: light.syntax.string.hex(),
|
|
56
|
+
numberLiteral: light.syntax.constant.hex(),
|
|
57
|
+
booleanLiteral: light.syntax.constant.hex(),
|
|
58
|
+
operator: light.syntax.operator.hex(),
|
|
59
|
+
property: light.syntax.tag.hex(),
|
|
60
|
+
paramDollar: light.syntax.regexp.hex(),
|
|
61
|
+
paramValue: light.syntax.regexp.hex(),
|
|
62
|
+
namespace: light.syntax.special.hex(),
|
|
63
|
+
consoleCommand: light.editor.fg.hex(),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const darkThemeConstants: ThemeOptions = {
|
|
68
|
+
dark: true,
|
|
69
|
+
editorSettings: {
|
|
70
|
+
background: mirage.editor.bg.hex(),
|
|
71
|
+
foreground: mirage.editor.fg.hex(),
|
|
72
|
+
gutterForeground: mirage.editor.gutter.normal.hex(),
|
|
73
|
+
selection: mirage.editor.selection.active.hex(),
|
|
74
|
+
textMatchingSelection: mirage.editor.findMatch.active.hex(),
|
|
75
|
+
cursor: '#ffffff',
|
|
76
|
+
autoCompletionPanel: {
|
|
77
|
+
selectedColor: '#062f4a',
|
|
78
|
+
matchingTextColor: '#0097fb',
|
|
79
|
+
backgroundColor: '#1C212B',
|
|
80
|
+
},
|
|
81
|
+
searchPanel: {
|
|
82
|
+
background: convertToHex(tokens.palette.dark.neutral.bg.default),
|
|
83
|
+
text: convertToHex(tokens.palette.dark.neutral.text.default),
|
|
84
|
+
buttonHoverBackground: convertToHex(
|
|
85
|
+
tokens.palette.dark.neutral.bg.strong,
|
|
86
|
+
),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
highlightStyles: {
|
|
90
|
+
comment: mirage.syntax.comment.hex(),
|
|
91
|
+
keyword: mirage.syntax.keyword.hex(),
|
|
92
|
+
keywordLiteral: mirage.syntax.keyword.hex(),
|
|
93
|
+
label: mirage.syntax.markup.hex(),
|
|
94
|
+
predicateFunction: mirage.syntax.func.hex(),
|
|
95
|
+
function: mirage.syntax.func.hex(),
|
|
96
|
+
procedure: mirage.syntax.func.hex(),
|
|
97
|
+
stringLiteral: mirage.syntax.string.hex(),
|
|
98
|
+
numberLiteral: mirage.syntax.constant.hex(),
|
|
99
|
+
booleanLiteral: mirage.syntax.constant.hex(),
|
|
100
|
+
operator: mirage.syntax.operator.hex(),
|
|
101
|
+
property: mirage.syntax.tag.hex(),
|
|
102
|
+
paramDollar: mirage.syntax.regexp.hex(),
|
|
103
|
+
paramValue: mirage.syntax.regexp.hex(),
|
|
104
|
+
namespace: mirage.syntax.special.hex(),
|
|
105
|
+
consoleCommand: mirage.editor.fg.hex(),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type ExtraThemeOptions = { inheritBgColor?: boolean };
|
|
110
|
+
export const ayuLightTheme = ({ inheritBgColor }: ExtraThemeOptions) => {
|
|
111
|
+
return createCypherTheme({ ...lightThemeConstants, inheritBgColor });
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const ayuDarkTheme = ({ inheritBgColor }: ExtraThemeOptions) => {
|
|
115
|
+
return createCypherTheme({ ...darkThemeConstants, inheritBgColor });
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export function getThemeExtension(
|
|
119
|
+
theme: 'light' | 'dark' | 'none' | Extension,
|
|
120
|
+
inheritBgColor?: boolean,
|
|
121
|
+
): Extension | Extension[] {
|
|
122
|
+
switch (theme) {
|
|
123
|
+
case 'light':
|
|
124
|
+
return ayuLightTheme({ inheritBgColor });
|
|
125
|
+
case 'dark':
|
|
126
|
+
return ayuDarkTheme({ inheritBgColor });
|
|
127
|
+
case 'none':
|
|
128
|
+
return [];
|
|
129
|
+
default:
|
|
130
|
+
return theme;
|
|
131
|
+
}
|
|
132
|
+
}
|
package/es/CypherEditor.js
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import React, { Component } from "react";
|
|
3
|
-
import { createCypherEditor, reactiveOptionKeys, defaultOptions } from "@neo4j-cypher/codemirror";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
class CypherEditor extends Component {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props);
|
|
8
|
-
_defineProperty(this, "setEditorRef", ref => {
|
|
9
|
-
this.editorRef = ref;
|
|
10
|
-
});
|
|
11
|
-
_defineProperty(this, "valueChanged", (value, changes) => {
|
|
12
|
-
this.lastValue = value;
|
|
13
|
-
const {
|
|
14
|
-
onValueChanged
|
|
15
|
-
} = this.props;
|
|
16
|
-
onValueChanged && onValueChanged(value, changes);
|
|
17
|
-
});
|
|
18
|
-
_defineProperty(this, "focusChanged", focused => {
|
|
19
|
-
const {
|
|
20
|
-
onFocusChanged
|
|
21
|
-
} = this.props;
|
|
22
|
-
this.setState({
|
|
23
|
-
focused
|
|
24
|
-
});
|
|
25
|
-
onFocusChanged && onFocusChanged(focused);
|
|
26
|
-
});
|
|
27
|
-
_defineProperty(this, "scrollChanged", scrollInfo => {
|
|
28
|
-
const {
|
|
29
|
-
onScrollChanged
|
|
30
|
-
} = this.props;
|
|
31
|
-
onScrollChanged && onScrollChanged(scrollInfo);
|
|
32
|
-
});
|
|
33
|
-
_defineProperty(this, "positionChanged", positionObject => {
|
|
34
|
-
this.lastPosition = (positionObject || {
|
|
35
|
-
position: null
|
|
36
|
-
}).position;
|
|
37
|
-
const {
|
|
38
|
-
onPositionChanged
|
|
39
|
-
} = this.props;
|
|
40
|
-
onPositionChanged && onPositionChanged(positionObject);
|
|
41
|
-
});
|
|
42
|
-
_defineProperty(this, "selectionChanged", selection => {
|
|
43
|
-
this.lastSelection = selection;
|
|
44
|
-
const {
|
|
45
|
-
onSelectionChanged
|
|
46
|
-
} = this.props;
|
|
47
|
-
onSelectionChanged && onSelectionChanged(selection);
|
|
48
|
-
});
|
|
49
|
-
_defineProperty(this, "autocompleteChanged", (autocompleteOpen, options, option) => {
|
|
50
|
-
const {
|
|
51
|
-
onAutocompleteChanged
|
|
52
|
-
} = this.props;
|
|
53
|
-
onAutocompleteChanged && onAutocompleteChanged(autocompleteOpen, options, option);
|
|
54
|
-
});
|
|
55
|
-
_defineProperty(this, "searchChanged", (searchOpen, text, matches) => {
|
|
56
|
-
const {
|
|
57
|
-
onSearchChanged
|
|
58
|
-
} = this.props;
|
|
59
|
-
onSearchChanged && onSearchChanged(searchOpen, text, matches);
|
|
60
|
-
});
|
|
61
|
-
_defineProperty(this, "lineNumberClick", (line, event) => {
|
|
62
|
-
const {
|
|
63
|
-
onLineNumberClick
|
|
64
|
-
} = this.props;
|
|
65
|
-
onLineNumberClick && onLineNumberClick(line, event);
|
|
66
|
-
});
|
|
67
|
-
_defineProperty(this, "keyDown", event => {
|
|
68
|
-
const {
|
|
69
|
-
onKeyDown
|
|
70
|
-
} = this.props;
|
|
71
|
-
onKeyDown && onKeyDown(event);
|
|
72
|
-
});
|
|
73
|
-
_defineProperty(this, "keyUp", event => {
|
|
74
|
-
const {
|
|
75
|
-
onKeyUp
|
|
76
|
-
} = this.props;
|
|
77
|
-
onKeyUp && onKeyUp(event);
|
|
78
|
-
});
|
|
79
|
-
this.state = {
|
|
80
|
-
focused: false
|
|
81
|
-
};
|
|
82
|
-
this.lastValue = null;
|
|
83
|
-
this.lastPosition = null;
|
|
84
|
-
this.lastSelection = null;
|
|
85
|
-
}
|
|
86
|
-
componentDidMount() {
|
|
87
|
-
const {
|
|
88
|
-
autocomplete,
|
|
89
|
-
autocompleteCloseOnBlur,
|
|
90
|
-
autocompleteOpen,
|
|
91
|
-
autocompleteTriggerStrings,
|
|
92
|
-
autofocus,
|
|
93
|
-
bracketMatching,
|
|
94
|
-
closeBrackets,
|
|
95
|
-
cursorWide,
|
|
96
|
-
cypherLanguage,
|
|
97
|
-
history,
|
|
98
|
-
indentUnit,
|
|
99
|
-
lineNumberFormatter,
|
|
100
|
-
lineNumbers,
|
|
101
|
-
lineWrapping,
|
|
102
|
-
lint,
|
|
103
|
-
placeholder,
|
|
104
|
-
position,
|
|
105
|
-
readOnly,
|
|
106
|
-
readOnlyCursor,
|
|
107
|
-
schema,
|
|
108
|
-
search,
|
|
109
|
-
searchMatches,
|
|
110
|
-
searchOpen,
|
|
111
|
-
searchText,
|
|
112
|
-
searchTop,
|
|
113
|
-
selection,
|
|
114
|
-
tabKey,
|
|
115
|
-
theme,
|
|
116
|
-
tooltipAbsolute,
|
|
117
|
-
parseOnSetValue,
|
|
118
|
-
value,
|
|
119
|
-
onEditorCreated,
|
|
120
|
-
preExtensions,
|
|
121
|
-
postExtensions
|
|
122
|
-
} = this.props;
|
|
123
|
-
this.value = value;
|
|
124
|
-
const {
|
|
125
|
-
editor
|
|
126
|
-
} = createCypherEditor(this.editorRef, {
|
|
127
|
-
autocomplete,
|
|
128
|
-
autocompleteCloseOnBlur,
|
|
129
|
-
autocompleteOpen,
|
|
130
|
-
autocompleteTriggerStrings,
|
|
131
|
-
autofocus,
|
|
132
|
-
bracketMatching,
|
|
133
|
-
closeBrackets,
|
|
134
|
-
cursorWide,
|
|
135
|
-
cypherLanguage,
|
|
136
|
-
history,
|
|
137
|
-
indentUnit,
|
|
138
|
-
lineNumberFormatter,
|
|
139
|
-
lineNumbers,
|
|
140
|
-
lineWrapping,
|
|
141
|
-
lint,
|
|
142
|
-
placeholder,
|
|
143
|
-
position,
|
|
144
|
-
readOnly,
|
|
145
|
-
readOnlyCursor,
|
|
146
|
-
schema,
|
|
147
|
-
search,
|
|
148
|
-
searchMatches,
|
|
149
|
-
searchOpen,
|
|
150
|
-
searchText,
|
|
151
|
-
searchTop,
|
|
152
|
-
selection,
|
|
153
|
-
tabKey,
|
|
154
|
-
theme,
|
|
155
|
-
tooltipAbsolute,
|
|
156
|
-
parseOnSetValue,
|
|
157
|
-
value,
|
|
158
|
-
preExtensions,
|
|
159
|
-
postExtensions
|
|
160
|
-
});
|
|
161
|
-
this.cypherEditor = editor;
|
|
162
|
-
this.cypherEditor.onValueChanged(this.valueChanged);
|
|
163
|
-
this.cypherEditor.onFocusChanged(this.focusChanged);
|
|
164
|
-
this.cypherEditor.onScrollChanged(this.scrollChanged);
|
|
165
|
-
this.cypherEditor.onPositionChanged(this.positionChanged);
|
|
166
|
-
this.cypherEditor.onSelectionChanged(this.selectionChanged);
|
|
167
|
-
this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
|
|
168
|
-
this.cypherEditor.onSearchChanged(this.searchChanged);
|
|
169
|
-
this.cypherEditor.onLineNumberClick(this.lineNumberClick);
|
|
170
|
-
this.cypherEditor.onKeyDown(this.keyDown);
|
|
171
|
-
this.cypherEditor.onKeyUp(this.keyUp);
|
|
172
|
-
onEditorCreated && onEditorCreated(this.cypherEditor);
|
|
173
|
-
}
|
|
174
|
-
componentWillUnmount() {
|
|
175
|
-
if (this.cypherEditor) {
|
|
176
|
-
this.cypherEditor.offValueChanged(this.valueChanged);
|
|
177
|
-
this.cypherEditor.offFocusChanged(this.focusChanged);
|
|
178
|
-
this.cypherEditor.offScrollChanged(this.scrollChanged);
|
|
179
|
-
this.cypherEditor.offPositionChanged(this.positionChanged);
|
|
180
|
-
this.cypherEditor.offSelectionChanged(this.selectionChanged);
|
|
181
|
-
this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
|
|
182
|
-
this.cypherEditor.offSearchChanged(this.searchChanged);
|
|
183
|
-
this.cypherEditor.offLineNumberClick(this.lineNumberClick);
|
|
184
|
-
this.cypherEditor.offKeyDown(this.keyDown);
|
|
185
|
-
this.cypherEditor.offKeyUp(this.keyUp);
|
|
186
|
-
this.cypherEditor.destroy();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
componentDidUpdate(prevProps) {
|
|
190
|
-
if (prevProps.value !== this.props.value) {
|
|
191
|
-
this.value = this.props.value;
|
|
192
|
-
}
|
|
193
|
-
for (let key of reactiveOptionKeys) {
|
|
194
|
-
if (prevProps[key] !== this.props[key]) {
|
|
195
|
-
this.updateOption({
|
|
196
|
-
[key]: this.props[key]
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
updateOption(prop) {
|
|
202
|
-
if (!this.cypherEditor) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
const key = Object.keys(prop).pop();
|
|
206
|
-
if (key === "value") {
|
|
207
|
-
if (prop[key] === this.lastValue) {
|
|
208
|
-
return;
|
|
209
|
-
} else {
|
|
210
|
-
this.lastValue = prop[key];
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
if (key === "position") {
|
|
214
|
-
const {
|
|
215
|
-
position
|
|
216
|
-
} = this.cypherEditor.getPositionForValue(prop[key]) || {
|
|
217
|
-
position: null
|
|
218
|
-
};
|
|
219
|
-
if (position === this.lastPosition) {
|
|
220
|
-
return;
|
|
221
|
-
} else {
|
|
222
|
-
this.lastPosition = position;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (key === "selection") {
|
|
226
|
-
if (prop[key] === this.lastSelection) {
|
|
227
|
-
return;
|
|
228
|
-
} else {
|
|
229
|
-
this.lastSelection = prop[key];
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const methodName = "set" + key[0].toUpperCase() + key.slice(1);
|
|
233
|
-
if (this.cypherEditor[methodName]) {
|
|
234
|
-
this.cypherEditor[methodName](prop[key]);
|
|
235
|
-
}
|
|
236
|
-
const autofocusProps = this.props.autofocusProps !== undefined ? this.props.autofocusProps : defaultOptions.autofocusProps;
|
|
237
|
-
if (autofocusProps.includes(key)) {
|
|
238
|
-
this.cypherEditor.focus();
|
|
239
|
-
}
|
|
240
|
-
const clearHistoryProps = this.props.clearHistoryProps !== undefined ? this.props.clearHistoryProps : defaultOptions.clearHistoryProps;
|
|
241
|
-
if (clearHistoryProps.includes(key)) {
|
|
242
|
-
this.cypherEditor.clearHistory();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
render() {
|
|
246
|
-
const {
|
|
247
|
-
className,
|
|
248
|
-
focusedClassName,
|
|
249
|
-
style
|
|
250
|
-
} = this.props;
|
|
251
|
-
const {
|
|
252
|
-
focused
|
|
253
|
-
} = this.state;
|
|
254
|
-
const editorClassName = (className ? className + " " : "") + (focused && focusedClassName ? focusedClassName : "");
|
|
255
|
-
return /*#__PURE__*/_jsx("div", {
|
|
256
|
-
className: editorClassName,
|
|
257
|
-
style: style,
|
|
258
|
-
ref: this.setEditorRef
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
export default CypherEditor;
|
package/es/react-codemirror.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as CypherEditor } from "./CypherEditor";
|