@neo4j-cypher/react-codemirror 2.0.0-alpha.0 → 2.0.0-canary-e8a1279

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 (122) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/LICENSE.md +201 -0
  3. package/README.md +27 -4
  4. package/dist/CypherEditor.d.ts +153 -0
  5. package/dist/CypherEditor.js +242 -0
  6. package/dist/CypherEditor.js.map +1 -0
  7. package/dist/e2e_tests/autoCompletion.spec.d.ts +1 -0
  8. package/dist/e2e_tests/autoCompletion.spec.js +133 -0
  9. package/dist/e2e_tests/autoCompletion.spec.js.map +1 -0
  10. package/dist/e2e_tests/configuration.spec.d.ts +1 -0
  11. package/dist/e2e_tests/configuration.spec.js +73 -0
  12. package/dist/e2e_tests/configuration.spec.js.map +1 -0
  13. package/dist/e2e_tests/e2eUtils.d.ts +12 -0
  14. package/dist/e2e_tests/e2eUtils.js +60 -0
  15. package/dist/e2e_tests/e2eUtils.js.map +1 -0
  16. package/dist/e2e_tests/extraKeybindings.spec.d.ts +1 -0
  17. package/dist/e2e_tests/extraKeybindings.spec.js +44 -0
  18. package/dist/e2e_tests/extraKeybindings.spec.js.map +1 -0
  19. package/dist/e2e_tests/historyNavigation.spec.d.ts +1 -0
  20. package/dist/e2e_tests/historyNavigation.spec.js +136 -0
  21. package/dist/e2e_tests/historyNavigation.spec.js.map +1 -0
  22. package/dist/e2e_tests/performanceTest.spec.d.ts +6 -0
  23. package/dist/e2e_tests/performanceTest.spec.js +96 -0
  24. package/dist/e2e_tests/performanceTest.spec.js.map +1 -0
  25. package/dist/e2e_tests/sanityChecks.spec.d.ts +1 -0
  26. package/dist/e2e_tests/sanityChecks.spec.js +56 -0
  27. package/dist/e2e_tests/sanityChecks.spec.js.map +1 -0
  28. package/dist/e2e_tests/signatureHelp.spec.d.ts +1 -0
  29. package/dist/e2e_tests/signatureHelp.spec.js +152 -0
  30. package/dist/e2e_tests/signatureHelp.spec.js.map +1 -0
  31. package/dist/e2e_tests/snippets.spec.d.ts +1 -0
  32. package/dist/e2e_tests/snippets.spec.js +63 -0
  33. package/dist/e2e_tests/snippets.spec.js.map +1 -0
  34. package/dist/e2e_tests/syntaxHighlighting.spec.d.ts +1 -0
  35. package/dist/e2e_tests/syntaxHighlighting.spec.js +91 -0
  36. package/dist/e2e_tests/syntaxHighlighting.spec.js.map +1 -0
  37. package/dist/e2e_tests/syntaxValidation.spec.d.ts +1 -0
  38. package/dist/e2e_tests/syntaxValidation.spec.js +79 -0
  39. package/dist/e2e_tests/syntaxValidation.spec.js.map +1 -0
  40. package/dist/historyNavigation.d.ts +7 -0
  41. package/dist/historyNavigation.js +163 -0
  42. package/dist/historyNavigation.js.map +1 -0
  43. package/dist/icons.d.ts +2 -0
  44. package/dist/icons.js +62 -0
  45. package/dist/icons.js.map +1 -0
  46. package/dist/index.d.ts +4 -0
  47. package/dist/index.js +5 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/lang-cypher/autocomplete.d.ts +3 -0
  50. package/dist/lang-cypher/autocomplete.js +62 -0
  51. package/dist/lang-cypher/autocomplete.js.map +1 -0
  52. package/dist/lang-cypher/constants.d.ts +40 -0
  53. package/dist/lang-cypher/constants.js +65 -0
  54. package/dist/lang-cypher/constants.js.map +1 -0
  55. package/dist/lang-cypher/contants.test.d.ts +1 -0
  56. package/dist/lang-cypher/contants.test.js +102 -0
  57. package/dist/lang-cypher/contants.test.js.map +1 -0
  58. package/dist/lang-cypher/createCypherTheme.d.ts +26 -0
  59. package/dist/lang-cypher/createCypherTheme.js +172 -0
  60. package/dist/lang-cypher/createCypherTheme.js.map +1 -0
  61. package/dist/lang-cypher/langCypher.d.ts +9 -0
  62. package/dist/lang-cypher/langCypher.js +24 -0
  63. package/dist/lang-cypher/langCypher.js.map +1 -0
  64. package/dist/lang-cypher/lintWorker.d.ts +8 -0
  65. package/dist/lang-cypher/lintWorker.js +4 -0
  66. package/dist/lang-cypher/lintWorker.js.map +1 -0
  67. package/dist/lang-cypher/parser-adapter.d.ts +19 -0
  68. package/dist/lang-cypher/parser-adapter.js +113 -0
  69. package/dist/lang-cypher/parser-adapter.js.map +1 -0
  70. package/dist/lang-cypher/signatureHelp.d.ts +4 -0
  71. package/dist/lang-cypher/signatureHelp.js +93 -0
  72. package/dist/lang-cypher/signatureHelp.js.map +1 -0
  73. package/dist/lang-cypher/syntaxValidation.d.ts +5 -0
  74. package/dist/lang-cypher/syntaxValidation.js +71 -0
  75. package/dist/lang-cypher/syntaxValidation.js.map +1 -0
  76. package/dist/lang-cypher/themeIcons.d.ts +7 -0
  77. package/dist/lang-cypher/themeIcons.js +22 -0
  78. package/dist/lang-cypher/themeIcons.js.map +1 -0
  79. package/dist/ndlTokensCopy.d.ts +379 -0
  80. package/dist/ndlTokensCopy.js +380 -0
  81. package/dist/ndlTokensCopy.js.map +1 -0
  82. package/dist/ndlTokensCopy.test.d.ts +1 -0
  83. package/dist/ndlTokensCopy.test.js +11 -0
  84. package/dist/ndlTokensCopy.test.js.map +1 -0
  85. package/dist/neo4jSetup.d.ts +2 -0
  86. package/dist/neo4jSetup.js +120 -0
  87. package/dist/neo4jSetup.js.map +1 -0
  88. package/dist/themes.d.ts +11 -0
  89. package/dist/themes.js +114 -0
  90. package/dist/themes.js.map +1 -0
  91. package/dist/tsconfig.tsbuildinfo +1 -0
  92. package/package.json +46 -16
  93. package/src/CypherEditor.tsx +461 -0
  94. package/src/e2e_tests/autoCompletion.spec.tsx +236 -0
  95. package/src/e2e_tests/configuration.spec.tsx +97 -0
  96. package/src/e2e_tests/e2eUtils.ts +85 -0
  97. package/src/e2e_tests/extraKeybindings.spec.tsx +57 -0
  98. package/src/e2e_tests/historyNavigation.spec.tsx +196 -0
  99. package/src/e2e_tests/performanceTest.spec.tsx +158 -0
  100. package/src/e2e_tests/sanityChecks.spec.tsx +78 -0
  101. package/src/e2e_tests/signatureHelp.spec.tsx +309 -0
  102. package/src/e2e_tests/snippets.spec.tsx +94 -0
  103. package/src/e2e_tests/syntaxHighlighting.spec.tsx +198 -0
  104. package/src/e2e_tests/syntaxValidation.spec.tsx +156 -0
  105. package/src/historyNavigation.ts +191 -0
  106. package/{esm/index.mjs → src/icons.ts} +37 -1283
  107. package/src/index.ts +4 -0
  108. package/src/lang-cypher/autocomplete.ts +81 -0
  109. package/src/lang-cypher/constants.ts +84 -0
  110. package/src/lang-cypher/contants.test.ts +104 -0
  111. package/src/lang-cypher/createCypherTheme.ts +240 -0
  112. package/src/lang-cypher/langCypher.ts +41 -0
  113. package/src/lang-cypher/lintWorker.ts +14 -0
  114. package/src/lang-cypher/parser-adapter.ts +145 -0
  115. package/src/lang-cypher/signatureHelp.ts +131 -0
  116. package/src/lang-cypher/syntaxValidation.ts +99 -0
  117. package/src/lang-cypher/themeIcons.ts +27 -0
  118. package/src/ndlTokensCopy.test.ts +11 -0
  119. package/src/ndlTokensCopy.ts +379 -0
  120. package/src/neo4jSetup.tsx +179 -0
  121. package/src/themes.ts +132 -0
  122. package/dist/index.cjs +0 -1330
@@ -0,0 +1,379 @@
1
+ export const tokens = {
2
+ borderRadius: {
3
+ '1xl': '12px',
4
+ '2xl': '14px',
5
+ '3xl': '16px',
6
+ '4xl': '18px',
7
+ '5xl': '20px',
8
+ full: '9999px',
9
+ lg: '8px',
10
+ md: '6px',
11
+ none: '0px',
12
+ sm: '4px',
13
+ xl: '10px',
14
+ },
15
+ boxShadow: {
16
+ l2: '0px 1px 2px 0px rgba(12, 26, 37, 0.18)',
17
+ l3: '0px 4px 8px 0px rgba(12, 26, 37, 0.04)',
18
+ l4: '0px 4px 8px 0px rgba(12, 26, 37, 0.08)',
19
+ l5: '0px 8px 20px 0px rgba(12, 26, 37, 0.12)',
20
+ },
21
+ breakpoints: {
22
+ '2xl': '1536px',
23
+ lg: '1024px',
24
+ md: '768px',
25
+ sm: '640px',
26
+ xl: '1280px',
27
+ xs: '450px',
28
+ },
29
+ colors: {
30
+ blueberry: {
31
+ '10': '#E8EBF6',
32
+ '20': '#C4CCE9',
33
+ '30': '#9DABD9',
34
+ '40': '#768ACA',
35
+ '50': '#3557B4',
36
+ '60': '#25459E',
37
+ '70': '#0B297D',
38
+ },
39
+ danger: {
40
+ '10': '#ffe6e9',
41
+ '20': '#ffb8c4',
42
+ '30': '#ff668a',
43
+ '40': '#ed1252',
44
+ '50': '#cc254b',
45
+ '60': '#a1003b',
46
+ '70': '#7a0031',
47
+ },
48
+ mint: {
49
+ '10': '#F0FFFA',
50
+ '20': '#D1FFF4',
51
+ '30': '#A8FFEE',
52
+ '40': '#55F9E2',
53
+ '50': '#3DD4C5',
54
+ '60': '#2AADA5',
55
+ '70': '#116161',
56
+ },
57
+ neutral: {
58
+ '10': '#FFFFFF',
59
+ '20': '#F5F7FA',
60
+ '30': '#EEF1F6',
61
+ '40': '#E6E9EE',
62
+ '50': '#C4C8CD',
63
+ '60': '#B2B7BD',
64
+ '70': '#717780',
65
+ '80': '#535B66',
66
+ '90': '#151E29',
67
+ },
68
+ primary: {
69
+ '10': '#e6f8ff',
70
+ '20': '#a3e2ff',
71
+ '30': '#7ad1ff',
72
+ '40': '#018bff',
73
+ '50': '#006FD6',
74
+ '60': '#0056b3',
75
+ '70': '#004092',
76
+ },
77
+ success: {
78
+ '10': '#E1FAEF',
79
+ '20': '#98EDCB',
80
+ '30': '#44D4A4',
81
+ '40': '#00BA88',
82
+ '50': '#327D60',
83
+ '60': '#006E58',
84
+ '70': '#00473B',
85
+ },
86
+ warning: {
87
+ '10': '#FFFBDE',
88
+ '20': '#FFF4B5',
89
+ '30': '#FFEA8C',
90
+ '40': '#FFDE63',
91
+ '50': '#D9B54A',
92
+ '60': '#966c2e',
93
+ '70': '#664817',
94
+ },
95
+ },
96
+ font: {
97
+ size: {
98
+ 'body-large': '1rem',
99
+ 'body-medium': '0.875rem',
100
+ 'body-small': '0.75rem',
101
+ code: '0.875rem',
102
+ h1: '3rem',
103
+ h2: '2.5rem',
104
+ h3: '1.875rem',
105
+ h4: '1.5rem',
106
+ h5: '1.25rem',
107
+ h6: '1rem',
108
+ label: '0.875rem',
109
+ 'subheading-large': '1.25rem',
110
+ 'subheading-medium': '1rem',
111
+ 'subheading-small': '0.875rem',
112
+ },
113
+ weight: {
114
+ bold: '700',
115
+ light: '300',
116
+ medium: '500',
117
+ normal: '400',
118
+ semibold: '600',
119
+ },
120
+ },
121
+ palette: {
122
+ categorical: {
123
+ '1': '#55BDC5',
124
+ '10': '#BF732D',
125
+ '11': '#478A6E',
126
+ '12': '#ADE86B',
127
+ '2': '#4D49CB',
128
+ '3': '#DC8B39',
129
+ '4': '#C9458D',
130
+ '5': '#8E8CF3',
131
+ '6': '#78DE7C',
132
+ '7': '#3F80E3',
133
+ '8': '#673FAB',
134
+ '9': '#DBBF40',
135
+ },
136
+ dark: {
137
+ danger: {
138
+ bg: {
139
+ strong: '#ffb8c4',
140
+ weak: '68, 61, 72',
141
+ },
142
+ border: {
143
+ strong: '#ffb8c4',
144
+ weak: '114, 91, 103',
145
+ },
146
+ hover: {
147
+ strong: '#ff668a',
148
+ weak: 'rgba(255, 102, 138,0.08)',
149
+ },
150
+ icon: '#ffb8c4',
151
+ pressed: {
152
+ strong: '#ff668a',
153
+ weak: 'rgba(255, 102, 138,0.12)',
154
+ },
155
+ text: '#ffb8c4',
156
+ },
157
+ neutral: {
158
+ bg: {
159
+ default: '#151E29',
160
+ strong: '45, 53, 63',
161
+ strongest: '#FFFFFF',
162
+ weak: '29, 38, 49',
163
+ },
164
+ border: {
165
+ strong: '#717780',
166
+ weak: '37, 47, 59',
167
+ },
168
+ hover: 'rgba(196, 200, 205,0.1)',
169
+ icon: '#C4C8CD',
170
+ pressed: 'rgba(196, 200, 205,0.2)',
171
+ text: {
172
+ default: '#F5F7FA',
173
+ inverse: '#151E29',
174
+ weak: '#C4C8CD',
175
+ weaker: '#B2B7BD',
176
+ weakest: '#717780',
177
+ },
178
+ },
179
+ primary: {
180
+ bg: {
181
+ strong: '#a3e2ff',
182
+ weak: '49, 69, 84',
183
+ },
184
+ border: {
185
+ strong: '#a3e2ff',
186
+ weak: '78, 108, 126',
187
+ },
188
+ focus: '#7ad1ff',
189
+ hover: {
190
+ strong: '#7ad1ff',
191
+ weak: 'rgba(122, 209, 255,0.08)',
192
+ },
193
+ icon: '#a3e2ff',
194
+ pressed: {
195
+ strong: '#7ad1ff',
196
+ weak: 'rgba(122, 209, 255,0.12)',
197
+ },
198
+ text: '#a3e2ff',
199
+ },
200
+ success: {
201
+ bg: {
202
+ strong: '#98EDCB',
203
+ weak: '47, 71, 73',
204
+ },
205
+ border: {
206
+ strong: '#98EDCB',
207
+ weak: '73, 113, 106',
208
+ },
209
+ icon: '#98EDCB',
210
+ text: '#98EDCB',
211
+ },
212
+ warning: {
213
+ bg: {
214
+ strong: '#FFEA8C',
215
+ weak: '68, 71, 60',
216
+ },
217
+ border: {
218
+ strong: '#FFEA8C',
219
+ weak: '114, 111, 80',
220
+ },
221
+ icon: '#FFEA8C',
222
+ text: '#FFEA8C',
223
+ },
224
+ },
225
+ graph: {
226
+ '1': '#FFDF81',
227
+ '10': '#FFC354',
228
+ '11': '#DA7294',
229
+ '12': '#579380',
230
+ '2': '#C990C0',
231
+ '3': '#F79767',
232
+ '4': '#56C7E4',
233
+ '5': '#F16767',
234
+ '6': '#D8C7AE',
235
+ '7': '#8DCC93',
236
+ '8': '#ECB4C9',
237
+ '9': '#4D8DDA',
238
+ },
239
+ light: {
240
+ danger: {
241
+ bg: {
242
+ strong: '#cc254b',
243
+ weak: '#ffe6e9',
244
+ },
245
+ border: {
246
+ strong: '#cc254b',
247
+ weak: '#ffb8c4',
248
+ },
249
+ hover: {
250
+ strong: '#a1003b',
251
+ weak: 'rgba(237,18,82,0.08)',
252
+ },
253
+ icon: '#cc254b',
254
+ pressed: {
255
+ strong: '#7a0031',
256
+ weak: 'rgba(237,18,82,0.12)',
257
+ },
258
+ text: '#cc254b',
259
+ },
260
+ neutral: {
261
+ bg: {
262
+ default: '#F5F7FA',
263
+ strong: '#E6E9EE',
264
+ strongest: '#535B66',
265
+ weak: '#FFFFFF',
266
+ },
267
+ border: {
268
+ strong: '#C4C8CD',
269
+ weak: '#EEF1F6',
270
+ },
271
+ hover: 'rgba(113,119,128,0.1)',
272
+ icon: '#535B66',
273
+ pressed: 'rgba(113,119,128,0.2)',
274
+ text: {
275
+ default: '#151E29',
276
+ inverse: '#FFFFFF',
277
+ weak: '#535B66',
278
+ weaker: '#717780',
279
+ weakest: '#B2B7BD',
280
+ },
281
+ },
282
+ primary: {
283
+ bg: {
284
+ strong: '#006FD6',
285
+ weak: '#e6f8ff',
286
+ },
287
+ border: {
288
+ strong: '#006FD6',
289
+ weak: '#7ad1ff',
290
+ },
291
+ focus: '#018bff',
292
+ hover: {
293
+ strong: '#0056b3',
294
+ weak: 'rgba(1,139,255,0.08)',
295
+ },
296
+ icon: '#006FD6',
297
+ pressed: {
298
+ strong: '#004092',
299
+ weak: 'rgba(1,139,255,0.12)',
300
+ },
301
+ text: '#006FD6',
302
+ },
303
+ success: {
304
+ bg: {
305
+ strong: '#327D60',
306
+ weak: '#E1FAEF',
307
+ },
308
+ border: {
309
+ strong: '#327D60',
310
+ weak: '#98EDCB',
311
+ },
312
+ icon: '#327D60',
313
+ text: '#327D60',
314
+ },
315
+ warning: {
316
+ bg: {
317
+ strong: '#966c2e',
318
+ weak: '#FFFBDE',
319
+ },
320
+ border: {
321
+ strong: '#966c2e',
322
+ weak: '#FFEA8C',
323
+ },
324
+ icon: '#966c2e',
325
+ text: '#966c2e',
326
+ },
327
+ },
328
+ },
329
+ space: {
330
+ '0': '0px',
331
+ '1': '1px',
332
+ '10': '64px',
333
+ '11': '96px',
334
+ '12': '128px',
335
+ '13': '320px',
336
+ '2': '2px',
337
+ '3': '4px',
338
+ '4': '8px',
339
+ '5': '12px',
340
+ '6': '16px',
341
+ '7': '24px',
342
+ '8': '32px',
343
+ '9': '48px',
344
+ },
345
+ transitions: {
346
+ default: 'all 100ms cubic-bezier(0.420, 0.000, 0.580, 1.000)',
347
+ stripped: '100ms cubic-bezier(0.420, 0.000, 0.580, 1.000)',
348
+ values: {
349
+ duration: {
350
+ default: '100ms',
351
+ },
352
+ properties: {
353
+ default: 'all',
354
+ },
355
+ 'timing-function': {
356
+ default: 'cubic-bezier(0.420, 0.000, 0.580, 1.000)',
357
+ },
358
+ },
359
+ },
360
+ zIndex: {
361
+ '0': 0,
362
+ '10': 10,
363
+ '20': 20,
364
+ '30': 30,
365
+ '40': 40,
366
+ '50': 50,
367
+ '60': 60,
368
+ alias: {
369
+ banner: 20,
370
+ blanket: 30,
371
+ modal: 60,
372
+ overlay: 10,
373
+ popover: 40,
374
+ tooltip: 50,
375
+ },
376
+ auto: 'auto',
377
+ deep: -999999,
378
+ },
379
+ };
@@ -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
+ }