@neo4j-cypher/react-codemirror 2.0.0-next.4 → 2.0.0-next.40

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 (181) hide show
  1. package/CHANGELOG.md +350 -0
  2. package/README.md +3 -2
  3. package/dist/src/CypherEditor.d.ts +243 -0
  4. package/dist/src/CypherEditor.js +513 -0
  5. package/dist/src/CypherEditor.js.map +1 -0
  6. package/dist/src/CypherEditor.test.js +154 -0
  7. package/dist/src/CypherEditor.test.js.map +1 -0
  8. package/dist/src/constants.d.ts +1 -0
  9. package/dist/src/constants.js +2 -0
  10. package/dist/src/constants.js.map +1 -0
  11. package/dist/src/diffView.d.ts +13 -0
  12. package/dist/src/diffView.js +11 -0
  13. package/dist/src/diffView.js.map +1 -0
  14. package/dist/src/e2e_tests/autoCompletion.spec.js +335 -0
  15. package/dist/src/e2e_tests/autoCompletion.spec.js.map +1 -0
  16. package/dist/src/e2e_tests/configuration.spec.js +83 -0
  17. package/dist/src/e2e_tests/configuration.spec.js.map +1 -0
  18. package/dist/src/e2e_tests/debounce.spec.js +66 -0
  19. package/dist/src/e2e_tests/debounce.spec.js.map +1 -0
  20. package/dist/{types/e2e_tests/e2e-utils.d.ts → src/e2e_tests/e2eUtils.d.ts} +2 -0
  21. package/dist/src/e2e_tests/e2eUtils.js +79 -0
  22. package/dist/src/e2e_tests/e2eUtils.js.map +1 -0
  23. package/dist/src/e2e_tests/extraKeybindings.spec.js +43 -0
  24. package/dist/src/e2e_tests/extraKeybindings.spec.js.map +1 -0
  25. package/dist/src/e2e_tests/historyNavigation.spec.js +227 -0
  26. package/dist/src/e2e_tests/historyNavigation.spec.js.map +1 -0
  27. package/dist/src/e2e_tests/performanceTest.spec.d.ts +6 -0
  28. package/dist/src/e2e_tests/performanceTest.spec.js +97 -0
  29. package/dist/src/e2e_tests/performanceTest.spec.js.map +1 -0
  30. package/dist/src/e2e_tests/sanityChecks.spec.js +64 -0
  31. package/dist/src/e2e_tests/sanityChecks.spec.js.map +1 -0
  32. package/dist/src/e2e_tests/signatureHelp.spec.js +227 -0
  33. package/dist/src/e2e_tests/signatureHelp.spec.js.map +1 -0
  34. package/dist/src/e2e_tests/snippets.spec.js +14 -0
  35. package/dist/src/e2e_tests/snippets.spec.js.map +1 -0
  36. package/dist/src/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
  37. package/dist/src/e2e_tests/syntaxHighlighting.spec.js +90 -0
  38. package/dist/src/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
  39. package/dist/src/e2e_tests/syntaxValidation.spec.d.ts +1 -0
  40. package/dist/src/e2e_tests/syntaxValidation.spec.js +129 -0
  41. package/dist/src/e2e_tests/syntaxValidation.spec.js.map +1 -0
  42. package/dist/src/editorActions.d.ts +17 -0
  43. package/dist/src/editorActions.js +194 -0
  44. package/dist/src/editorActions.js.map +1 -0
  45. package/dist/src/historyNavigation.js +163 -0
  46. package/dist/src/historyNavigation.js.map +1 -0
  47. package/dist/src/hostCallbacks.d.ts +9 -0
  48. package/dist/src/hostCallbacks.js +2 -0
  49. package/dist/src/hostCallbacks.js.map +1 -0
  50. package/dist/{types → src}/icons.d.ts +1 -1
  51. package/dist/src/icons.js +62 -0
  52. package/dist/src/icons.js.map +1 -0
  53. package/dist/src/index.d.ts +6 -0
  54. package/dist/src/index.js +5 -0
  55. package/dist/src/index.js.map +1 -0
  56. package/dist/src/inlinePanel.d.ts +27 -0
  57. package/dist/src/inlinePanel.js +86 -0
  58. package/dist/src/inlinePanel.js.map +1 -0
  59. package/dist/src/lang-cypher/autocomplete.d.ts +6 -0
  60. package/dist/src/lang-cypher/autocomplete.js +116 -0
  61. package/dist/src/lang-cypher/autocomplete.js.map +1 -0
  62. package/dist/{types → src}/lang-cypher/constants.d.ts +13 -0
  63. package/dist/src/lang-cypher/constants.js +74 -0
  64. package/dist/src/lang-cypher/constants.js.map +1 -0
  65. package/dist/src/lang-cypher/contants.test.d.ts +1 -0
  66. package/dist/src/lang-cypher/contants.test.js +103 -0
  67. package/dist/src/lang-cypher/contants.test.js.map +1 -0
  68. package/dist/{types/lang-cypher/create-cypher-theme.d.ts → src/lang-cypher/createCypherTheme.d.ts} +12 -1
  69. package/dist/src/lang-cypher/createCypherTheme.js +202 -0
  70. package/dist/src/lang-cypher/createCypherTheme.js.map +1 -0
  71. package/dist/src/lang-cypher/langCypher.d.ts +14 -0
  72. package/dist/src/lang-cypher/langCypher.js +23 -0
  73. package/dist/src/lang-cypher/langCypher.js.map +1 -0
  74. package/dist/src/lang-cypher/lintWorker.mjs +2035 -0
  75. package/dist/src/lang-cypher/parser-adapter.d.ts +19 -0
  76. package/dist/src/lang-cypher/parser-adapter.js +112 -0
  77. package/dist/src/lang-cypher/parser-adapter.js.map +1 -0
  78. package/dist/src/lang-cypher/signatureHelp.d.ts +4 -0
  79. package/dist/src/lang-cypher/signatureHelp.js +108 -0
  80. package/dist/src/lang-cypher/signatureHelp.js.map +1 -0
  81. package/dist/{types/lang-cypher/syntax-validation.d.ts → src/lang-cypher/syntaxValidation.d.ts} +2 -1
  82. package/dist/src/lang-cypher/syntaxValidation.js +60 -0
  83. package/dist/src/lang-cypher/syntaxValidation.js.map +1 -0
  84. package/dist/src/lang-cypher/themeIcons.js +22 -0
  85. package/dist/src/lang-cypher/themeIcons.js.map +1 -0
  86. package/dist/src/lang-cypher/utils.d.ts +2 -0
  87. package/dist/src/lang-cypher/utils.js +10 -0
  88. package/dist/src/lang-cypher/utils.js.map +1 -0
  89. package/dist/src/ndlTokensCopy.d.ts +570 -0
  90. package/dist/src/ndlTokensCopy.js +571 -0
  91. package/dist/src/ndlTokensCopy.js.map +1 -0
  92. package/dist/src/ndlTokensCopy.test.d.ts +1 -0
  93. package/dist/src/ndlTokensCopy.test.js +12 -0
  94. package/dist/src/ndlTokensCopy.test.js.map +1 -0
  95. package/dist/src/neo4jSetup.d.ts +6 -0
  96. package/dist/src/neo4jSetup.js +120 -0
  97. package/dist/src/neo4jSetup.js.map +1 -0
  98. package/dist/src/richClipboardCopier.d.ts +4 -0
  99. package/dist/src/richClipboardCopier.js +78 -0
  100. package/dist/src/richClipboardCopier.js.map +1 -0
  101. package/dist/src/richClipboardCopier.test.d.ts +1 -0
  102. package/dist/src/richClipboardCopier.test.js +53 -0
  103. package/dist/src/richClipboardCopier.test.js.map +1 -0
  104. package/dist/src/themes.d.ts +5 -0
  105. package/dist/src/themes.js +107 -0
  106. package/dist/src/themes.js.map +1 -0
  107. package/dist/tsconfig.tsbuildinfo +1 -0
  108. package/package.json +62 -62
  109. package/src/CypherEditor.test.tsx +203 -0
  110. package/src/CypherEditor.tsx +584 -48
  111. package/src/constants.ts +1 -0
  112. package/src/diffView.ts +24 -0
  113. package/src/e2e_tests/autoCompletion.spec.tsx +577 -0
  114. package/src/e2e_tests/configuration.spec.tsx +111 -0
  115. package/src/e2e_tests/debounce.spec.tsx +102 -0
  116. package/src/e2e_tests/{e2e-utils.ts → e2eUtils.ts} +41 -3
  117. package/src/e2e_tests/{extra-keybindings.spec.tsx → extraKeybindings.spec.tsx} +1 -3
  118. package/src/e2e_tests/{history-navigation.spec.tsx → historyNavigation.spec.tsx} +137 -18
  119. package/src/e2e_tests/performanceTest.spec.tsx +163 -0
  120. package/src/e2e_tests/{sanity-checks.spec.tsx → sanityChecks.spec.tsx} +28 -20
  121. package/src/e2e_tests/signatureHelp.spec.tsx +443 -0
  122. package/src/e2e_tests/snippets.spec.tsx +19 -0
  123. package/src/e2e_tests/{syntax-highlighting.spec.tsx → syntaxHighlighting.spec.tsx} +26 -24
  124. package/src/e2e_tests/syntaxValidation.spec.tsx +252 -0
  125. package/src/editorActions.ts +253 -0
  126. package/src/{history-navigation.ts → historyNavigation.ts} +1 -1
  127. package/src/hostCallbacks.ts +9 -0
  128. package/src/icons.ts +3 -0
  129. package/src/index.ts +4 -2
  130. package/src/inlinePanel.ts +140 -0
  131. package/src/lang-cypher/autocomplete.ts +98 -18
  132. package/src/lang-cypher/constants.ts +32 -0
  133. package/src/lang-cypher/contants.test.ts +7 -3
  134. package/src/lang-cypher/{create-cypher-theme.ts → createCypherTheme.ts} +85 -23
  135. package/src/lang-cypher/langCypher.ts +46 -0
  136. package/src/lang-cypher/lintWorker.mjs +2035 -0
  137. package/src/lang-cypher/parser-adapter.ts +145 -0
  138. package/src/lang-cypher/signatureHelp.ts +154 -0
  139. package/src/lang-cypher/syntaxValidation.ts +76 -0
  140. package/src/lang-cypher/utils.ts +9 -0
  141. package/src/{ndl-tokens-copy.test.ts → ndlTokensCopy.test.ts} +2 -1
  142. package/src/ndlTokensCopy.ts +570 -0
  143. package/src/{neo4j-setup.tsx → neo4jSetup.tsx} +78 -17
  144. package/src/richClipboardCopier.test.ts +65 -0
  145. package/src/richClipboardCopier.ts +99 -0
  146. package/src/themes.ts +61 -69
  147. package/src/viteEnv.d.ts +1 -0
  148. package/dist/cjs/index.cjs +0 -1441
  149. package/dist/cjs/index.cjs.map +0 -7
  150. package/dist/esm/index.mjs +0 -1464
  151. package/dist/esm/index.mjs.map +0 -7
  152. package/dist/types/CypherEditor.d.ts +0 -113
  153. package/dist/types/e2e_tests/mock-data.d.ts +0 -3779
  154. package/dist/types/index.d.ts +0 -4
  155. package/dist/types/lang-cypher/ParserAdapter.d.ts +0 -14
  156. package/dist/types/lang-cypher/autocomplete.d.ts +0 -3
  157. package/dist/types/lang-cypher/lang-cypher.d.ts +0 -7
  158. package/dist/types/ndl-tokens-copy.d.ts +0 -379
  159. package/dist/types/neo4j-setup.d.ts +0 -2
  160. package/dist/types/themes.d.ts +0 -11
  161. package/dist/types/tsconfig.tsbuildinfo +0 -1
  162. package/src/e2e_tests/auto-completion.spec.tsx +0 -232
  163. package/src/e2e_tests/mock-data.ts +0 -4310
  164. package/src/e2e_tests/performance-test.spec.tsx +0 -71
  165. package/src/e2e_tests/syntax-validation.spec.tsx +0 -156
  166. package/src/lang-cypher/ParserAdapter.ts +0 -92
  167. package/src/lang-cypher/lang-cypher.ts +0 -32
  168. package/src/lang-cypher/syntax-validation.ts +0 -24
  169. package/src/ndl-tokens-copy.ts +0 -379
  170. /package/dist/{types/e2e_tests/auto-completion.spec.d.ts → src/CypherEditor.test.d.ts} +0 -0
  171. /package/dist/{types/e2e_tests/extra-keybindings.spec.d.ts → src/e2e_tests/autoCompletion.spec.d.ts} +0 -0
  172. /package/dist/{types/e2e_tests/history-navigation.spec.d.ts → src/e2e_tests/configuration.spec.d.ts} +0 -0
  173. /package/dist/{types/e2e_tests/performance-test.spec.d.ts → src/e2e_tests/debounce.spec.d.ts} +0 -0
  174. /package/dist/{types/e2e_tests/sanity-checks.spec.d.ts → src/e2e_tests/extraKeybindings.spec.d.ts} +0 -0
  175. /package/dist/{types/e2e_tests/syntax-highlighting.spec.d.ts → src/e2e_tests/historyNavigation.spec.d.ts} +0 -0
  176. /package/dist/{types/e2e_tests/syntax-validation.spec.d.ts → src/e2e_tests/sanityChecks.spec.d.ts} +0 -0
  177. /package/dist/{types/lang-cypher/contants.test.d.ts → src/e2e_tests/signatureHelp.spec.d.ts} +0 -0
  178. /package/dist/{types/ndl-tokens-copy.test.d.ts → src/e2e_tests/snippets.spec.d.ts} +0 -0
  179. /package/dist/{types/history-navigation.d.ts → src/historyNavigation.d.ts} +0 -0
  180. /package/dist/{types/lang-cypher/theme-icons.d.ts → src/lang-cypher/themeIcons.d.ts} +0 -0
  181. /package/src/lang-cypher/{theme-icons.ts → themeIcons.ts} +0 -0
@@ -0,0 +1,203 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { EditorView } from '@codemirror/view';
4
+ import { createRef } from 'react';
5
+ import { createRoot } from 'react-dom/client';
6
+ import { act } from 'react-dom/test-utils';
7
+ import { afterEach, beforeEach, expect, test, vi } from 'vitest';
8
+ import { DEBOUNCE_TIME } from './constants';
9
+ import { CypherEditor } from './CypherEditor';
10
+
11
+ const container = document.createElement('div');
12
+ let root: ReturnType<typeof createRoot>;
13
+
14
+ const ref = createRef<CypherEditor>();
15
+ let value = '';
16
+ const onChange = vi.fn((v: string) => {
17
+ value = v;
18
+ rerender();
19
+ });
20
+
21
+ global.IS_REACT_ACT_ENVIRONMENT = true;
22
+ const DEBOUNCE_TIME_WITH_MARGIN = DEBOUNCE_TIME + 100;
23
+
24
+ /** Avoids crash in test environment */
25
+ function mockEditorView(editorView: EditorView) {
26
+ editorView.coordsAtPos = vi.fn().mockReturnValue({
27
+ left: 0,
28
+ top: 0,
29
+ right: 0,
30
+ bottom: 0,
31
+ });
32
+ }
33
+
34
+ async function debounce() {
35
+ await new Promise((resolve) =>
36
+ setTimeout(resolve, DEBOUNCE_TIME_WITH_MARGIN),
37
+ );
38
+ }
39
+
40
+ function getEditorValue() {
41
+ return ref.current.editorView.current.state.doc.toString();
42
+ }
43
+
44
+ function rerender() {
45
+ act(() => {
46
+ root.render(<CypherEditor value={value} onChange={onChange} ref={ref} />);
47
+ });
48
+ }
49
+
50
+ beforeEach(() => {
51
+ root = createRoot(container);
52
+ act(() => {
53
+ root.render(<CypherEditor value={value} onChange={onChange} ref={ref} />);
54
+ });
55
+ mockEditorView(ref.current.editorView.current);
56
+ });
57
+
58
+ afterEach(() => {
59
+ act(() => {
60
+ root.unmount();
61
+ });
62
+ value = '';
63
+ vi.clearAllMocks();
64
+ });
65
+
66
+ test('editorValue updates props.value after debounce', async () => {
67
+ ref.current.setValueAndFocus('new value');
68
+ expect(onChange).not.toHaveBeenCalled();
69
+ expect(getEditorValue()).toBe('new value');
70
+ expect(value).toBe('');
71
+ await debounce();
72
+
73
+ expect(onChange).toHaveBeenCalledOnce();
74
+ expect(getEditorValue()).toBe('new value');
75
+ expect(value).toBe('new value');
76
+ });
77
+
78
+ test('editorValue updates should not be applied twice', async () => {
79
+ const dispatch = vi.spyOn(ref.current.editorView.current, 'dispatch');
80
+
81
+ ref.current.setValueAndFocus('new value');
82
+ await debounce();
83
+
84
+ expect(onChange).toHaveBeenCalledOnce();
85
+ expect(dispatch).toHaveBeenCalledOnce(); // it gets called once for the initial setValueAndFocus
86
+ });
87
+
88
+ test('props.value updates editorValue', () => {
89
+ value = 'external value';
90
+ rerender();
91
+
92
+ expect(getEditorValue()).toBe('external value');
93
+ expect(value).toBe('external value');
94
+ });
95
+
96
+ test('props.value set to undefined preserves editorValue', () => {
97
+ // 1. value is set initially
98
+ value = 'initial';
99
+ rerender();
100
+
101
+ // 2. value is set to undefined
102
+ value = undefined;
103
+ rerender();
104
+
105
+ expect(onChange).not.toHaveBeenCalled();
106
+ expect(value).toBeUndefined();
107
+ expect(getEditorValue()).toBe('initial');
108
+ });
109
+
110
+ // value updates from outside onExecute are overwritten by pending updates
111
+ test.fails('new props.value should cancel onChange', async () => {
112
+ // 1. value is updated internally
113
+ ref.current.setValueAndFocus('update');
114
+
115
+ // 2. editor is rerendered with a new value while a value update is still pending
116
+ value = 'new external value';
117
+ rerender();
118
+
119
+ await debounce();
120
+
121
+ // expect(onChange).not.toHaveBeenCalled();
122
+ expect(getEditorValue()).toBe('new external value');
123
+ expect(value).toBe('new external value');
124
+ });
125
+
126
+ // value updates from outside onExecute are overwritten by pending updates
127
+ test.fails('new props.value set to same value should cancel onChange', async () => {
128
+ // 1. value is set initially
129
+ value = 'same value';
130
+ rerender();
131
+
132
+ // 2. value is updated internally
133
+ ref.current.setValueAndFocus('update');
134
+
135
+ // 3. editor is rerendered with a new value while a value update is still pending
136
+ value = 'same value';
137
+ rerender();
138
+
139
+ await debounce();
140
+
141
+ // expect(onChange).not.toHaveBeenCalled();
142
+ expect(getEditorValue()).toBe('same value');
143
+ expect(value).toBe('same value');
144
+ });
145
+
146
+ test('rerender should not cancel onChange', async () => {
147
+ // 1. value is updated internally
148
+ ref.current.setValueAndFocus('changed');
149
+
150
+ // 2. editor is rerendered while a value update is still pending
151
+ rerender();
152
+
153
+ await debounce();
154
+
155
+ expect(onChange).toHaveBeenCalledOnce();
156
+ expect(getEditorValue()).toBe('changed');
157
+ expect(value).toBe('changed');
158
+ });
159
+
160
+ test('rerender with a previous update should not cancel onChange', async () => {
161
+ // 1. value is updated internally
162
+ ref.current.setValueAndFocus('changed');
163
+ await debounce();
164
+
165
+ // 2. value is updated internally again
166
+ ref.current.setValueAndFocus('new change');
167
+
168
+ // 3. editor is rerendered while a value update is still pending
169
+ rerender();
170
+
171
+ await debounce();
172
+
173
+ expect(onChange).toHaveBeenCalledTimes(2);
174
+ expect(getEditorValue()).toBe('new change');
175
+ expect(value).toBe('new change');
176
+ });
177
+
178
+ test('rerender with prior external update should not cancel onChange', async () => {
179
+ // 1. value is set initially
180
+ ref.current.setValueAndFocus('initial');
181
+ await debounce();
182
+
183
+ // 2. value is updated externally
184
+ value = 'external update';
185
+ rerender();
186
+
187
+ // 3. value is updated internally
188
+ ref.current.setValueAndFocus('internal update');
189
+
190
+ // 4. editor is rerendered while a value update is still pending
191
+ rerender();
192
+
193
+ await debounce();
194
+
195
+ expect(getEditorValue()).toBe('internal update');
196
+ expect(value).toBe('internal update');
197
+ });
198
+
199
+ test('setValueAndFocus should handle CRLF newline characters', () => {
200
+ expect(() =>
201
+ ref.current.setValueAndFocus('new value\r\nnew line'),
202
+ ).not.toThrow();
203
+ });