@neo4j-cypher/react-codemirror 2.0.0-next.24 → 2.0.0-next.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "codemirror",
18
18
  "codemirror 6"
19
19
  ],
20
- "version": "2.0.0-next.24",
20
+ "version": "2.0.0-next.26",
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.21",
55
- "@neo4j-cypher/lint-worker": "2025.4.1-next.0"
54
+ "@neo4j-cypher/language-support": "2.0.0-next.23",
55
+ "@neo4j-cypher/lint-worker": "1.10.1-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
+ });
@@ -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: value,
334
+ insert: normalizedValue,
333
335
  },
334
- selection: { anchor: value.length, head: value.length },
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
- ((value, viewUpdate) => {
356
- this.props.onChange(value, viewUpdate);
357
- }) satisfies CypherEditorProps['onChange'],
358
- DEBOUNCE_TIME,
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
- 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
- ]
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
- 'aria-label': this.props.ariaLabel,
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
- this.props.overrideThemeBackgroundColor;
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 the sure the tooltip closed
92
+ // Make sure the tooltip closed
93
93
  await expect(
94
94
  this.page.locator('.cm-tooltip-hover').last(),
95
95
  ).not.toBeVisible();
@@ -425,7 +425,6 @@ test('Signature help depends on the Cypher version', async ({
425
425
  },
426
426
  },
427
427
  }}
428
- featureFlags={{ cypher25: true }}
429
428
  />,
430
429
  );
431
430
 
@@ -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
 
@@ -20,7 +20,6 @@ export type CypherConfig = {
20
20
  showSignatureTooltipBelow?: boolean;
21
21
  featureFlags?: {
22
22
  consoleCommands?: boolean;
23
- cypher25?: boolean;
24
23
  };
25
24
  schema?: DbSchema;
26
25
  useLightVersion: boolean;