@neo4j-cypher/react-codemirror 2.0.0-next.24 → 2.0.0-next.25
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 +15 -0
- package/dist/src/CypherEditor.d.ts +0 -1
- package/dist/src/CypherEditor.js +7 -4
- package/dist/src/CypherEditor.js.map +1 -1
- package/dist/src/CypherEditor.test.js +3 -0
- package/dist/src/CypherEditor.test.js.map +1 -1
- package/dist/src/e2e_tests/autoCompletion.spec.js +15 -1
- package/dist/src/e2e_tests/autoCompletion.spec.js.map +1 -1
- package/dist/src/e2e_tests/e2eUtils.js +1 -1
- package/dist/src/e2e_tests/e2eUtils.js.map +1 -1
- package/dist/src/e2e_tests/signatureHelp.spec.js +1 -1
- package/dist/src/e2e_tests/signatureHelp.spec.js.map +1 -1
- package/dist/src/e2e_tests/syntaxValidation.spec.js +2 -2
- package/dist/src/e2e_tests/syntaxValidation.spec.js.map +1 -1
- package/dist/src/lang-cypher/langCypher.d.ts +0 -1
- package/dist/src/lang-cypher/langCypher.js.map +1 -1
- package/dist/src/lang-cypher/lintWorker.mjs +146 -140
- package/dist/src/lang-cypher/syntaxValidation.js +8 -1
- package/dist/src/lang-cypher/syntaxValidation.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/CypherEditor.test.tsx +4 -0
- package/src/CypherEditor.tsx +28 -28
- package/src/e2e_tests/autoCompletion.spec.tsx +26 -1
- package/src/e2e_tests/e2eUtils.ts +1 -1
- package/src/e2e_tests/signatureHelp.spec.tsx +0 -1
- package/src/e2e_tests/syntaxValidation.spec.tsx +1 -3
- package/src/lang-cypher/langCypher.ts +0 -1
- package/src/lang-cypher/lintWorker.mjs +146 -140
- package/src/lang-cypher/syntaxValidation.ts +9 -1
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"codemirror",
|
|
18
18
|
"codemirror 6"
|
|
19
19
|
],
|
|
20
|
-
"version": "2.0.0-next.
|
|
20
|
+
"version": "2.0.0-next.25",
|
|
21
21
|
"main": "./dist/src/index.js",
|
|
22
22
|
"types": "./dist/src/index.d.ts",
|
|
23
23
|
"type": "module",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"style-mod": "^4.1.2",
|
|
52
52
|
"vscode-languageserver-types": "^3.17.3",
|
|
53
53
|
"workerpool": "^9.0.4",
|
|
54
|
-
"@neo4j-cypher/language-support": "2.0.0-next.
|
|
55
|
-
"@neo4j-cypher/lint-worker": "
|
|
54
|
+
"@neo4j-cypher/language-support": "2.0.0-next.22",
|
|
55
|
+
"@neo4j-cypher/lint-worker": "0.1.0-next.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@neo4j-ndl/base": "^3.2.10",
|
|
@@ -198,3 +198,7 @@ test('rerender with prior external update should not cancel onChange', async ()
|
|
|
198
198
|
expect(getEditorValue()).toBe('internal update');
|
|
199
199
|
expect(value).toBe('internal update');
|
|
200
200
|
});
|
|
201
|
+
|
|
202
|
+
test('setValueAndFocus should handle CRLF newline characters', () => {
|
|
203
|
+
expect(() => ref.current.setValueAndFocus('new value\r\nnew line')).not.toThrow();
|
|
204
|
+
});
|
package/src/CypherEditor.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
} from '@codemirror/view';
|
|
16
16
|
import {
|
|
17
17
|
formatQuery,
|
|
18
|
-
_internalFeatureFlags,
|
|
19
18
|
type DbSchema,
|
|
20
19
|
} from '@neo4j-cypher/language-support';
|
|
21
20
|
import debounce from 'lodash.debounce';
|
|
@@ -103,7 +102,6 @@ export interface CypherEditorProps {
|
|
|
103
102
|
*/
|
|
104
103
|
featureFlags?: {
|
|
105
104
|
consoleCommands?: boolean;
|
|
106
|
-
cypher25?: boolean;
|
|
107
105
|
};
|
|
108
106
|
/**
|
|
109
107
|
* The schema to use for autocompletion and linting.
|
|
@@ -183,7 +181,7 @@ export interface CypherEditorProps {
|
|
|
183
181
|
const format = (view: EditorView): void => {
|
|
184
182
|
try {
|
|
185
183
|
const doc = view.state.doc.toString();
|
|
186
|
-
const { formattedQuery, newCursorPos } = formatQuery(doc, {cursorPosition: view.state.selection.main.anchor});
|
|
184
|
+
const { formattedQuery, newCursorPos } = formatQuery(doc, { cursorPosition: view.state.selection.main.anchor });
|
|
187
185
|
view.dispatch({
|
|
188
186
|
changes: {
|
|
189
187
|
from: 0,
|
|
@@ -325,13 +323,17 @@ export class CypherEditor extends Component<
|
|
|
325
323
|
*/
|
|
326
324
|
setValueAndFocus(value = '') {
|
|
327
325
|
const currentCmValue = this.editorView.current.state?.doc.toString() ?? '';
|
|
326
|
+
// Normalize line endings to LF that CM expects.
|
|
327
|
+
// Prevents issues with inserted values that contain CRLF line endings.
|
|
328
|
+
// https://codemirror.net/docs/ref/?utm_source=chatgpt.com#state.EditorState^lineSeparator
|
|
329
|
+
const normalizedValue = value.replace(/\r\n/g, '\n');
|
|
328
330
|
this.editorView.current.dispatch({
|
|
329
331
|
changes: {
|
|
330
332
|
from: 0,
|
|
331
333
|
to: currentCmValue.length,
|
|
332
|
-
insert:
|
|
334
|
+
insert: normalizedValue,
|
|
333
335
|
},
|
|
334
|
-
selection: { anchor:
|
|
336
|
+
selection: { anchor: normalizedValue.length, head: normalizedValue.length },
|
|
335
337
|
});
|
|
336
338
|
this.editorView.current?.focus();
|
|
337
339
|
}
|
|
@@ -352,11 +354,11 @@ export class CypherEditor extends Component<
|
|
|
352
354
|
|
|
353
355
|
private debouncedOnChange = this.props.onChange
|
|
354
356
|
? debounce(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
357
|
+
((value, viewUpdate) => {
|
|
358
|
+
this.props.onChange(value, viewUpdate);
|
|
359
|
+
}) satisfies CypherEditorProps['onChange'],
|
|
360
|
+
DEBOUNCE_TIME,
|
|
361
|
+
)
|
|
360
362
|
: undefined;
|
|
361
363
|
|
|
362
364
|
componentDidMount(): void {
|
|
@@ -373,8 +375,6 @@ export class CypherEditor extends Component<
|
|
|
373
375
|
newLineOnEnter,
|
|
374
376
|
} = this.props;
|
|
375
377
|
|
|
376
|
-
_internalFeatureFlags.cypher25 = featureFlags?.cypher25 ?? false;
|
|
377
|
-
|
|
378
378
|
this.schemaRef.current = {
|
|
379
379
|
schema,
|
|
380
380
|
lint,
|
|
@@ -398,20 +398,20 @@ export class CypherEditor extends Component<
|
|
|
398
398
|
|
|
399
399
|
const changeListener = this.debouncedOnChange
|
|
400
400
|
? [
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
401
|
+
EditorView.updateListener.of((upt: ViewUpdate) => {
|
|
402
|
+
const wasUserEdit = !upt.transactions.some((tr) =>
|
|
403
|
+
tr.annotation(ExternalEdit),
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
if (upt.docChanged && wasUserEdit) {
|
|
407
|
+
const doc = upt.state.doc;
|
|
408
|
+
const value = doc.toString();
|
|
409
|
+
this.debouncedOnChange(value, upt);
|
|
410
|
+
}
|
|
411
|
+
}),
|
|
412
|
+
]
|
|
413
413
|
: [];
|
|
414
|
-
|
|
414
|
+
|
|
415
415
|
this.editorState.current = EditorState.create({
|
|
416
416
|
extensions: [
|
|
417
417
|
keyBindingCompartment.of(
|
|
@@ -445,8 +445,8 @@ export class CypherEditor extends Component<
|
|
|
445
445
|
),
|
|
446
446
|
this.props.ariaLabel
|
|
447
447
|
? EditorView.contentAttributes.of({
|
|
448
|
-
|
|
449
|
-
|
|
448
|
+
'aria-label': this.props.ariaLabel,
|
|
449
|
+
})
|
|
450
450
|
: [],
|
|
451
451
|
],
|
|
452
452
|
doc: this.props.value,
|
|
@@ -494,7 +494,7 @@ export class CypherEditor extends Component<
|
|
|
494
494
|
const didChangeTheme =
|
|
495
495
|
prevProps.theme !== this.props.theme ||
|
|
496
496
|
prevProps.overrideThemeBackgroundColor !==
|
|
497
|
-
|
|
497
|
+
this.props.overrideThemeBackgroundColor;
|
|
498
498
|
|
|
499
499
|
if (didChangeTheme) {
|
|
500
500
|
this.editorView.current.dispatch({
|
|
@@ -526,7 +526,6 @@ test('completions depend on the Cypher version', async ({ page, mount }) => {
|
|
|
526
526
|
},
|
|
527
527
|
},
|
|
528
528
|
}}
|
|
529
|
-
featureFlags={{ cypher25: true }}
|
|
530
529
|
/>,
|
|
531
530
|
);
|
|
532
531
|
|
|
@@ -544,3 +543,29 @@ test('completions depend on the Cypher version', async ({ page, mount }) => {
|
|
|
544
543
|
page.locator('.cm-tooltip-autocomplete').getByText('cypher25Function'),
|
|
545
544
|
).toBeVisible();
|
|
546
545
|
});
|
|
546
|
+
|
|
547
|
+
test('does not complete properties for non node / relationship variables', async ({ page, mount }) => {
|
|
548
|
+
await mount(
|
|
549
|
+
<CypherEditor
|
|
550
|
+
schema={{
|
|
551
|
+
propertyKeys: ["nodeProperty"]
|
|
552
|
+
}}
|
|
553
|
+
/>
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
const textField = page.getByRole('textbox');
|
|
557
|
+
await textField.fill('MATCH (n) RETURN n.');
|
|
558
|
+
|
|
559
|
+
await expect(
|
|
560
|
+
page.locator('.cm-tooltip-autocomplete').getByText('nodeProperty'),
|
|
561
|
+
).toBeVisible();
|
|
562
|
+
|
|
563
|
+
await textField.fill('WITH 1 AS x RETURN x.');
|
|
564
|
+
// This could be flaky if the semantic analysis takes too long
|
|
565
|
+
await page.waitForTimeout(500)
|
|
566
|
+
await textField.press('Escape');
|
|
567
|
+
await textField.press('Control+ ');
|
|
568
|
+
await expect(
|
|
569
|
+
page.locator('.cm-tooltip-autocomplete').getByText('nodeProperty')
|
|
570
|
+
).not.toBeVisible();
|
|
571
|
+
});
|
|
@@ -89,7 +89,7 @@ export class CypherEditorPage {
|
|
|
89
89
|
the second interaction on, we won't be able to see that second element
|
|
90
90
|
*/
|
|
91
91
|
await this.page.mouse.move(0, 0);
|
|
92
|
-
// Make
|
|
92
|
+
// Make sure the tooltip closed
|
|
93
93
|
await expect(
|
|
94
94
|
this.page.locator('.cm-tooltip-hover').last(),
|
|
95
95
|
).not.toBeVisible();
|
|
@@ -194,8 +194,7 @@ test('Syntax highlighting works as expected with multiple separate linting messa
|
|
|
194
194
|
editorPage.page.locator('.cm-deprecated-element').last(),
|
|
195
195
|
).toBeVisible({ timeout: 10000 });
|
|
196
196
|
await editorPage.checkWarningMessage('id', 'Function id is deprecated.');
|
|
197
|
-
await editorPage.checkWarningMessage('id', `The query used a deprecated function. ('id' has been replaced by 'elementId or an application-generated id')`);
|
|
198
|
-
|
|
197
|
+
await editorPage.checkWarningMessage('id', `The query used a deprecated function. ('id' has been replaced by 'elementId or consider using an application-generated id')`);
|
|
199
198
|
await editorPage.checkWarningMessage('apoc.create.uuid', 'Function apoc.create.uuid is deprecated. Alternative: Neo4j randomUUID() function');
|
|
200
199
|
await editorPage.checkErrorMessage('a', 'Variable `a` not defined');
|
|
201
200
|
})
|
|
@@ -240,7 +239,6 @@ test('Syntax validation depends on the Cypher version', async ({
|
|
|
240
239
|
await mount(
|
|
241
240
|
<CypherEditor
|
|
242
241
|
schema={testData.mockSchema}
|
|
243
|
-
featureFlags={{ cypher25: true }}
|
|
244
242
|
/>,
|
|
245
243
|
);
|
|
246
244
|
|