@neo4j-cypher/react-codemirror 2.0.0-alpha.0 → 2.0.0-next.1

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE.md +201 -0
  3. package/README.md +24 -4
  4. package/dist/{index.cjs → cjs/index.cjs} +187 -74
  5. package/dist/cjs/index.cjs.map +7 -0
  6. package/{esm → dist/esm}/index.mjs +196 -66
  7. package/dist/esm/index.mjs.map +7 -0
  8. package/dist/types/CypherEditor.d.ts +118 -0
  9. package/dist/types/e2e_tests/auto-completion.spec.d.ts +1 -0
  10. package/dist/types/e2e_tests/e2e-utils.d.ts +12 -0
  11. package/dist/types/e2e_tests/extra-keybindings.spec.d.ts +1 -0
  12. package/dist/types/e2e_tests/history-navigation.spec.d.ts +1 -0
  13. package/dist/types/e2e_tests/mock-data.d.ts +3779 -0
  14. package/dist/types/e2e_tests/performance-test.spec.d.ts +1 -0
  15. package/dist/types/e2e_tests/sanity-checks.spec.d.ts +1 -0
  16. package/dist/types/e2e_tests/syntax-highlighting.spec.d.ts +1 -0
  17. package/dist/types/e2e_tests/syntax-validation.spec.d.ts +1 -0
  18. package/dist/types/icons.d.ts +2 -0
  19. package/dist/types/index.d.ts +4 -0
  20. package/dist/types/lang-cypher/ParserAdapter.d.ts +14 -0
  21. package/dist/types/lang-cypher/autocomplete.d.ts +3 -0
  22. package/dist/types/lang-cypher/constants.d.ts +31 -0
  23. package/dist/types/lang-cypher/contants.test.d.ts +1 -0
  24. package/dist/types/lang-cypher/create-cypher-theme.d.ts +26 -0
  25. package/dist/types/lang-cypher/lang-cypher.d.ts +7 -0
  26. package/dist/types/lang-cypher/syntax-validation.d.ts +3 -0
  27. package/dist/types/lang-cypher/theme-icons.d.ts +7 -0
  28. package/dist/types/ndl-tokens-copy.d.ts +379 -0
  29. package/dist/types/ndl-tokens-copy.test.d.ts +1 -0
  30. package/dist/types/neo4j-setup.d.ts +2 -0
  31. package/dist/types/repl-mode.d.ts +8 -0
  32. package/dist/types/themes.d.ts +11 -0
  33. package/dist/types/tsconfig.tsbuildinfo +1 -0
  34. package/package.json +48 -15
  35. package/src/CypherEditor.tsx +316 -0
  36. package/src/e2e_tests/auto-completion.spec.tsx +232 -0
  37. package/src/e2e_tests/e2e-utils.ts +75 -0
  38. package/src/e2e_tests/extra-keybindings.spec.tsx +57 -0
  39. package/src/e2e_tests/history-navigation.spec.tsx +144 -0
  40. package/src/e2e_tests/mock-data.ts +4310 -0
  41. package/src/e2e_tests/performance-test.spec.tsx +71 -0
  42. package/src/e2e_tests/sanity-checks.spec.tsx +87 -0
  43. package/src/e2e_tests/syntax-highlighting.spec.tsx +198 -0
  44. package/src/e2e_tests/syntax-validation.spec.tsx +157 -0
  45. package/src/icons.ts +87 -0
  46. package/src/index.ts +4 -0
  47. package/src/lang-cypher/ParserAdapter.ts +92 -0
  48. package/src/lang-cypher/autocomplete.ts +65 -0
  49. package/src/lang-cypher/constants.ts +61 -0
  50. package/src/lang-cypher/contants.test.ts +104 -0
  51. package/src/lang-cypher/create-cypher-theme.ts +207 -0
  52. package/src/lang-cypher/lang-cypher.ts +32 -0
  53. package/src/lang-cypher/syntax-validation.ts +24 -0
  54. package/src/lang-cypher/theme-icons.ts +27 -0
  55. package/src/ndl-tokens-copy.test.ts +11 -0
  56. package/src/ndl-tokens-copy.ts +379 -0
  57. package/src/neo4j-setup.tsx +129 -0
  58. package/src/repl-mode.ts +214 -0
  59. package/src/themes.ts +130 -0
@@ -0,0 +1,71 @@
1
+ import { expect, test } from '@playwright/experimental-ct-react';
2
+ import { CypherEditor } from '../CypherEditor';
3
+ import { CypherEditorPage } from './e2e-utils';
4
+ import { largeQuery, mockSchema } from './mock-data';
5
+
6
+ test.use({ viewport: { width: 1000, height: 500 } });
7
+
8
+ test('performance test session ', async ({ mount, page }) => {
9
+ test.setTimeout(30 * 1000);
10
+ const editorPage = new CypherEditorPage(page);
11
+ const component = await mount(
12
+ <CypherEditor prompt="neo4j>" theme="dark" lint schema={mockSchema} />,
13
+ );
14
+
15
+ // pressSequentially is less efficient -> we want to test the performance of the editor
16
+ await editorPage.getEditor().pressSequentially(`
17
+ MATCH (n:Person) RETURN m;`);
18
+
19
+ await editorPage.checkErrorMessage('m', 'Variable `m` not defined');
20
+
21
+ // set and unset large query a few times
22
+ await component.update(
23
+ <CypherEditor value={largeQuery} schema={mockSchema} />,
24
+ );
25
+ await component.update(<CypherEditor value="" schema={mockSchema} />);
26
+
27
+ await component.update(
28
+ <CypherEditor value={largeQuery} schema={mockSchema} />,
29
+ );
30
+ await component.update(<CypherEditor value="" />);
31
+
32
+ await component.update(
33
+ <CypherEditor value={largeQuery} schema={mockSchema} />,
34
+ );
35
+ await component.update(<CypherEditor value="" schema={mockSchema} />);
36
+
37
+ await component.update(
38
+ <CypherEditor value={largeQuery} schema={mockSchema} />,
39
+ );
40
+ await component.update(<CypherEditor value="" schema={mockSchema} />);
41
+
42
+ await component.update(
43
+ <CypherEditor value={largeQuery} schema={mockSchema} />,
44
+ );
45
+
46
+ await editorPage.getEditor().pressSequentially(`
47
+ MATCH (n:P`);
48
+
49
+ await expect(
50
+ page.locator('.cm-tooltip-autocomplete').getByText('Person'),
51
+ ).toBeVisible();
52
+
53
+ await page.locator('.cm-tooltip-autocomplete').getByText('Person').click();
54
+
55
+ await expect(page.locator('.cm-tooltip-autocomplete')).not.toBeVisible();
56
+
57
+ await expect(component).toContainText('MATCH (n:Person');
58
+
59
+ await editorPage.getEditor().pressSequentially(') RETRN my');
60
+
61
+ await expect(component).toContainText('MATCH (n:Person) RETRN m');
62
+
63
+ await editorPage.checkErrorMessage(
64
+ 'RETRN',
65
+ 'Unexpected token. Did you mean RETURN?',
66
+ );
67
+
68
+ await editorPage
69
+ .getEditor()
70
+ .pressSequentially('veryveryveryverylongvariable');
71
+ });
@@ -0,0 +1,87 @@
1
+ import { expect, test } from '@playwright/experimental-ct-react';
2
+ import { CypherEditor } from '../CypherEditor';
3
+
4
+ test.use({ viewport: { width: 500, height: 500 } });
5
+
6
+ test('can mount the editor with text', async ({ mount }) => {
7
+ const component = await mount(<CypherEditor value="MATCH (n) RETURN n;" />);
8
+
9
+ await expect(component).toContainText('MATCH (n) RETURN n;');
10
+ });
11
+
12
+ test('the editors text can be externally controlled ', async ({ mount }) => {
13
+ const intitialValue = 'MATCH (n) RETURN n;';
14
+
15
+ const component = await mount(<CypherEditor value={intitialValue} />);
16
+
17
+ await expect(component).toContainText(intitialValue);
18
+
19
+ const newValue = 'RETURN 123';
20
+ await component.update(<CypherEditor value={newValue} />);
21
+
22
+ await expect(component).toContainText(newValue);
23
+ });
24
+
25
+ test('the editors can report changes to the text ', async ({ mount, page }) => {
26
+ const intitialValue = 'MATCH (n) ';
27
+
28
+ let editorValueCopy = intitialValue;
29
+ const onChange = (val: string) => {
30
+ editorValueCopy = val;
31
+ };
32
+
33
+ await mount(<CypherEditor value={intitialValue} onChange={onChange} />);
34
+
35
+ const textField = page.getByRole('textbox');
36
+
37
+ await textField.fill('RETURN 12');
38
+
39
+ expect(editorValueCopy).toBe('RETURN 12');
40
+
41
+ await page.keyboard.type('34');
42
+
43
+ expect(editorValueCopy).toBe('RETURN 1234');
44
+ });
45
+
46
+ test('can complete RETURN', async ({ page, mount }) => {
47
+ await mount(<CypherEditor />);
48
+ const textField = page.getByRole('textbox');
49
+
50
+ await textField.fill('RETU');
51
+
52
+ await page.getByText('RETURN').click();
53
+ await expect(textField).toHaveText('RETURN');
54
+ });
55
+
56
+ test('can complete CALL/CREATE', async ({ page, mount }) => {
57
+ await mount(<CypherEditor />);
58
+ const textField = page.getByRole('textbox');
59
+
60
+ await textField.fill('C');
61
+ await expect(page.getByText('CALL')).toBeVisible();
62
+ await expect(page.getByText('CREATE')).toBeVisible();
63
+
64
+ await textField.fill('CA');
65
+ await expect(page.getByText('CALL')).toBeVisible();
66
+ await expect(page.getByText('CREATE')).not.toBeVisible();
67
+
68
+ // wait for the autocomplete interactivity
69
+ await page.waitForTimeout(500);
70
+ await textField.press('Enter');
71
+
72
+ await expect(textField).toHaveText('CALL');
73
+ });
74
+
75
+ test('prompt shows up', async ({ mount, page }) => {
76
+ const component = await mount(<CypherEditor prompt="neo4j>" />);
77
+
78
+ await expect(component).toContainText('neo4j>');
79
+
80
+ await component.update(<CypherEditor prompt="test>" />);
81
+ await expect(component).toContainText('test>');
82
+
83
+ const textField = page.getByRole('textbox');
84
+ await textField.press('a');
85
+
86
+ await expect(textField).toHaveText('a');
87
+ });
@@ -0,0 +1,198 @@
1
+ import { expect, test } from '@playwright/experimental-ct-react';
2
+ import { CypherEditor } from '../CypherEditor';
3
+ import { darkThemeConstants, lightThemeConstants } from '../themes';
4
+ import { CypherEditorPage } from './e2e-utils';
5
+
6
+ test.use({ viewport: { width: 500, height: 500 } });
7
+
8
+ test('light theme highlighting', async ({ page, mount }) => {
9
+ const editorPage = new CypherEditorPage(page);
10
+ const query = `
11
+ MATCH (variable :Label)-[:REL_TYPE]->()
12
+ WHERE variable.property = "String"
13
+ OR namespaced.function() = false
14
+ // comment
15
+ OR $parameter > 1234
16
+ RETURN variable;`;
17
+
18
+ await mount(<CypherEditor value={query} theme="light" />);
19
+
20
+ const keywordcolors = await Promise.all(
21
+ ['MATCH', 'WHERE', 'RETURN'].map((kw) =>
22
+ editorPage.getHexColorOfLocator(page.getByText(kw)),
23
+ ),
24
+ );
25
+ keywordcolors.every((kw) =>
26
+ expect(kw).toEqual(lightThemeConstants.highlightStyles.keyword),
27
+ );
28
+
29
+ const labelReltype = await Promise.all(
30
+ ['Label', 'REL_TYPE'].map((kw) =>
31
+ editorPage.getHexColorOfLocator(page.getByText(kw)),
32
+ ),
33
+ );
34
+ labelReltype.every((kw) =>
35
+ expect(kw).toEqual(lightThemeConstants.highlightStyles.label),
36
+ );
37
+
38
+ expect(
39
+ await editorPage.getHexColorOfLocator(page.getByText('parameter')),
40
+ ).toEqual(lightThemeConstants.highlightStyles.paramValue);
41
+
42
+ expect(
43
+ await editorPage.getHexColorOfLocator(page.getByText('property')),
44
+ ).toEqual(lightThemeConstants.highlightStyles.property);
45
+
46
+ expect(
47
+ await editorPage.getHexColorOfLocator(page.getByText('false')),
48
+ ).toEqual(lightThemeConstants.highlightStyles.booleanLiteral);
49
+
50
+ expect(
51
+ await editorPage.getHexColorOfLocator(page.getByText('String')),
52
+ ).toEqual(lightThemeConstants.highlightStyles.stringLiteral);
53
+
54
+ expect(
55
+ await editorPage.getHexColorOfLocator(page.getByText('comment')),
56
+ ).toEqual(lightThemeConstants.highlightStyles.comment);
57
+
58
+ expect(
59
+ await editorPage.getHexColorOfLocator(
60
+ page.getByText('1234', { exact: true }),
61
+ ),
62
+ ).toEqual(lightThemeConstants.highlightStyles.numberLiteral);
63
+
64
+ expect(await editorPage.editorBackgroundIsUnset()).toEqual(false);
65
+ });
66
+
67
+ test('dark theme highlighting', async ({ page, mount }) => {
68
+ const editorPage = new CypherEditorPage(page);
69
+ const query = `
70
+ MATCH (variable :Label)-[:REL_TYPE]->()
71
+ WHERE variable.property = "String"
72
+ OR namespaced.function() = false
73
+ // comment
74
+ OR $parameter > 1234
75
+ RETURN variable;`;
76
+
77
+ await mount(<CypherEditor value={query} theme="dark" />);
78
+
79
+ const keywordcolors = await Promise.all(
80
+ ['MATCH', 'WHERE', 'RETURN'].map((kw) =>
81
+ editorPage.getHexColorOfLocator(page.getByText(kw)),
82
+ ),
83
+ );
84
+ keywordcolors.every((kw) =>
85
+ expect(kw).toEqual(darkThemeConstants.highlightStyles.keyword),
86
+ );
87
+
88
+ const labelReltype = await Promise.all(
89
+ ['Label', 'REL_TYPE'].map((kw) =>
90
+ editorPage.getHexColorOfLocator(page.getByText(kw)),
91
+ ),
92
+ );
93
+ labelReltype.every((kw) =>
94
+ expect(kw).toEqual(darkThemeConstants.highlightStyles.label),
95
+ );
96
+
97
+ expect(
98
+ await editorPage.getHexColorOfLocator(page.getByText('parameter')),
99
+ ).toEqual(darkThemeConstants.highlightStyles.paramValue);
100
+
101
+ expect(
102
+ await editorPage.getHexColorOfLocator(page.getByText('property')),
103
+ ).toEqual(darkThemeConstants.highlightStyles.property);
104
+
105
+ expect(
106
+ await editorPage.getHexColorOfLocator(page.getByText('false')),
107
+ ).toEqual(darkThemeConstants.highlightStyles.booleanLiteral);
108
+
109
+ expect(
110
+ await editorPage.getHexColorOfLocator(page.getByText('String')),
111
+ ).toEqual(darkThemeConstants.highlightStyles.stringLiteral);
112
+
113
+ expect(
114
+ await editorPage.getHexColorOfLocator(page.getByText('comment')),
115
+ ).toEqual(darkThemeConstants.highlightStyles.comment);
116
+
117
+ expect(
118
+ await editorPage.getHexColorOfLocator(
119
+ page.getByText('1234', { exact: true }),
120
+ ),
121
+ ).toEqual(darkThemeConstants.highlightStyles.numberLiteral);
122
+
123
+ expect(await editorPage.editorBackgroundIsUnset()).toEqual(false);
124
+ });
125
+
126
+ test('can live switch theme ', async ({ page, mount }) => {
127
+ const editorPage = new CypherEditorPage(page);
128
+ const component = await mount(<CypherEditor theme="light" value="RETURN" />);
129
+
130
+ expect(
131
+ await editorPage.getHexColorOfLocator(
132
+ page.getByText('RETURN', { exact: true }),
133
+ ),
134
+ ).toEqual(lightThemeConstants.highlightStyles.keyword);
135
+
136
+ await component.update(<CypherEditor theme="dark" value="RETURN" />);
137
+
138
+ expect(
139
+ await editorPage.getHexColorOfLocator(
140
+ page.getByText('RETURN', { exact: true }),
141
+ ),
142
+ ).toEqual(darkThemeConstants.highlightStyles.keyword);
143
+ });
144
+
145
+ test('respects prop to allow overriding bkg color', async ({ page, mount }) => {
146
+ const editorPage = new CypherEditorPage(page);
147
+ await mount(
148
+ <CypherEditor theme="light" value="text" overrideThemeBackgroundColor />,
149
+ );
150
+
151
+ expect(await editorPage.editorBackgroundIsUnset()).toEqual(true);
152
+ });
153
+
154
+ test('highlights multiline string literal correctly', async ({
155
+ page,
156
+ mount,
157
+ }) => {
158
+ const editorPage = new CypherEditorPage(page);
159
+ const query = `
160
+ RETURN "
161
+ multilinestring";`;
162
+
163
+ await mount(<CypherEditor theme="light" value={query} />);
164
+
165
+ expect(
166
+ await editorPage.getHexColorOfLocator(page.getByText('multilinestring')),
167
+ ).toEqual(lightThemeConstants.highlightStyles.stringLiteral);
168
+ });
169
+
170
+ test('highlights multiline label correctly', async ({ page, mount }) => {
171
+ const editorPage = new CypherEditorPage(page);
172
+ const query = `
173
+ MATCH (v:\`
174
+
175
+ Label\`)
176
+ `;
177
+
178
+ await mount(<CypherEditor theme="light" value={query} />);
179
+
180
+ expect(
181
+ await editorPage.getHexColorOfLocator(page.getByText('Label')),
182
+ ).toEqual(lightThemeConstants.highlightStyles.label);
183
+ });
184
+
185
+ test('highlights multiline comment correctly', async ({ page, mount }) => {
186
+ const editorPage = new CypherEditorPage(page);
187
+ const query = `
188
+ /*
189
+
190
+ comment
191
+ */";`;
192
+
193
+ await mount(<CypherEditor theme="light" value={query} />);
194
+
195
+ expect(
196
+ await editorPage.getHexColorOfLocator(page.getByText('comment')),
197
+ ).toEqual(lightThemeConstants.highlightStyles.comment);
198
+ });
@@ -0,0 +1,157 @@
1
+ import { expect, test } from '@playwright/experimental-ct-react';
2
+ import { CypherEditor } from '../CypherEditor';
3
+ import { CypherEditorPage } from './e2e-utils';
4
+
5
+ test.use({ viewport: { width: 1000, height: 500 } });
6
+ test('Prop lint set to false disables syntax validation', async ({
7
+ page,
8
+ mount,
9
+ }) => {
10
+ const query = 'METCH (n) RETURN n';
11
+
12
+ await mount(<CypherEditor value={query} lint={false} />);
13
+
14
+ await expect(page.locator('.cm-lintRange-error').last()).not.toBeVisible({
15
+ timeout: 2000,
16
+ });
17
+ });
18
+
19
+ // TODO
20
+ test.skip('Can turn linting back on', async ({ page, mount }) => {
21
+ const editorPage = new CypherEditorPage(page);
22
+ const query = 'METCH (n) RETURN n';
23
+
24
+ const component = await mount(<CypherEditor value={query} lint={false} />);
25
+
26
+ await expect(page.locator('.cm-lintRange-error').last()).not.toBeVisible({
27
+ timeout: 2000,
28
+ });
29
+
30
+ await component.update(<CypherEditor value={query} lint />);
31
+
32
+ await editorPage.getEditor().fill('METCH (n) RETURN n');
33
+
34
+ await editorPage.checkErrorMessage(
35
+ 'METCH',
36
+ 'Unrecognized keyword. Did you mean MATCH?',
37
+ );
38
+ });
39
+
40
+ test('Syntactic errors are surfaced', async ({ page, mount }) => {
41
+ const editorPage = new CypherEditorPage(page);
42
+ const query = 'METCH (n) RETURN n';
43
+
44
+ await mount(<CypherEditor value={query} />);
45
+
46
+ await editorPage.checkErrorMessage(
47
+ 'METCH',
48
+ 'Unrecognized keyword. Did you mean MATCH?',
49
+ );
50
+ });
51
+
52
+ test('Errors for undefined labels are surfaced', async ({ page, mount }) => {
53
+ const editorPage = new CypherEditorPage(page);
54
+ const query = 'MATCH (n: Person) RETURN n';
55
+
56
+ await mount(
57
+ <CypherEditor
58
+ value={query}
59
+ schema={{ labels: ['Movie'], relationshipTypes: [] }}
60
+ />,
61
+ );
62
+
63
+ await editorPage.checkWarningMessage(
64
+ 'Person',
65
+ "Label Person is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application",
66
+ );
67
+ });
68
+
69
+ test('Errors for multiline undefined labels are highlighted correctly', async ({
70
+ page,
71
+ mount,
72
+ }) => {
73
+ const editorPage = new CypherEditorPage(page);
74
+ const query = `MATCH (n:\`Foo
75
+ Bar\`) RETURN n`;
76
+ const expectedMsg = `Label \`Foo
77
+ Bar\` is not present in the database. Make sure you didn't misspell it or that it is available when you run this statement in your application`;
78
+
79
+ await mount(
80
+ <CypherEditor
81
+ value={query}
82
+ schema={{ labels: ['Movie'], relationshipTypes: [] }}
83
+ />,
84
+ );
85
+
86
+ await editorPage.checkWarningMessage('`Foo', expectedMsg);
87
+ await editorPage.checkWarningMessage('Bar`', expectedMsg);
88
+ });
89
+
90
+ test('Semantic errors are surfaced when there are no syntactic errors', async ({
91
+ page,
92
+ mount,
93
+ }) => {
94
+ const editorPage = new CypherEditorPage(page);
95
+ const query = 'MATCH (n) RETURN m';
96
+
97
+ await mount(<CypherEditor value={query} />);
98
+
99
+ await editorPage.checkErrorMessage('m', 'Variable `m` not defined');
100
+ });
101
+
102
+ test('Semantic errors are correctly accumulated', async ({ page, mount }) => {
103
+ const editorPage = new CypherEditorPage(page);
104
+ const query = 'CALL { MATCH (n) } IN TRANSACTIONS OF -1 ROWS';
105
+
106
+ await mount(<CypherEditor value={query} />);
107
+
108
+ await editorPage.checkErrorMessage(
109
+ 'MATCH (n)',
110
+ 'Query cannot conclude with MATCH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
111
+ );
112
+
113
+ await editorPage.checkErrorMessage(
114
+ '-1',
115
+ "Invalid input. '-1' is not a valid value. Must be a positive integer",
116
+ );
117
+ });
118
+
119
+ test('Multiline errors are correctly placed', async ({ page, mount }) => {
120
+ const editorPage = new CypherEditorPage(page);
121
+ const query = `CALL {
122
+ MATCH (n)
123
+ } IN TRANSACTIONS
124
+ OF -1 ROWS`;
125
+
126
+ await mount(<CypherEditor value={query} />);
127
+
128
+ await editorPage.checkErrorMessage(
129
+ 'MATCH (n)',
130
+ 'Query cannot conclude with MATCH (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
131
+ );
132
+
133
+ await editorPage.checkErrorMessage(
134
+ '-1',
135
+ "Invalid input. '-1' is not a valid value. Must be a positive integer",
136
+ );
137
+ });
138
+
139
+ test('Validation errors are correctly overlapped', async ({ page, mount }) => {
140
+ const editorPage = new CypherEditorPage(page);
141
+ const query = `CALL { MATCH (n)
142
+ RETURN n
143
+ } IN TRANSACTIONS
144
+ OF -1 ROWS`;
145
+
146
+ await mount(<CypherEditor value={query} />);
147
+
148
+ await editorPage.checkErrorMessage(
149
+ '-1',
150
+ 'Query cannot conclude with CALL (must be a RETURN clause, an update clause, a unit subquery call, or a procedure call with no YIELD)',
151
+ );
152
+
153
+ await editorPage.checkErrorMessage(
154
+ '-1',
155
+ "Invalid input. '-1' is not a valid value. Must be a positive integer",
156
+ );
157
+ });