@neo4j-cypher/react-codemirror 2.0.0-next.1 → 2.0.0-next.3
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 +14 -0
- package/README.md +4 -1
- package/dist/cjs/index.cjs +202 -205
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.mjs +196 -199
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/CypherEditor.d.ts +3 -8
- package/dist/types/history-navigation.d.ts +7 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/CypherEditor.tsx +46 -25
- package/src/e2e_tests/history-navigation.spec.tsx +63 -11
- package/src/e2e_tests/syntax-validation.spec.tsx +0 -1
- package/src/{repl-mode.ts → history-navigation.ts} +6 -29
- package/dist/types/repl-mode.d.ts +0 -8
|
@@ -12,7 +12,7 @@ test('respects preloaded history', async ({ page, mount }) => {
|
|
|
12
12
|
await mount(
|
|
13
13
|
<CypherEditor
|
|
14
14
|
value={initialValue}
|
|
15
|
-
|
|
15
|
+
history={['first', 'second']}
|
|
16
16
|
onExecute={() => {
|
|
17
17
|
/* needed to turn on history movements */
|
|
18
18
|
}}
|
|
@@ -39,23 +39,29 @@ test('can execute queries and see them in history', async ({ page, mount }) => {
|
|
|
39
39
|
const initialValue = `MATCH (n)
|
|
40
40
|
RETURN n;`;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
const onExecute = () => {
|
|
44
|
-
|
|
42
|
+
const history: string[] = [];
|
|
43
|
+
const onExecute = (cmd: string) => {
|
|
44
|
+
history.unshift(cmd);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const editor = await mount(
|
|
48
|
+
<CypherEditor
|
|
49
|
+
value={initialValue}
|
|
50
|
+
history={history}
|
|
51
|
+
onExecute={onExecute}
|
|
52
|
+
/>,
|
|
53
|
+
);
|
|
48
54
|
|
|
49
55
|
// Execute initial query
|
|
50
56
|
await editorPage.getEditor().press('Control+Enter');
|
|
51
57
|
await editorPage.getEditor().press('Meta+Enter');
|
|
52
|
-
expect(
|
|
58
|
+
expect(history.length).toBe(1);
|
|
53
59
|
|
|
54
60
|
// Ensure query execution doesn't fire if the query is only whitespace
|
|
55
61
|
await editorPage.getEditor().fill(' ');
|
|
56
62
|
await editorPage.getEditor().press('Control+Enter');
|
|
57
63
|
await editorPage.getEditor().press('Meta+Enter');
|
|
58
|
-
expect(
|
|
64
|
+
expect(history.length).toBe(1);
|
|
59
65
|
|
|
60
66
|
// Ensure only enter doesn't execute query
|
|
61
67
|
await editorPage.getEditor().fill('multiline');
|
|
@@ -64,15 +70,25 @@ RETURN n;`;
|
|
|
64
70
|
await editorPage.getEditor().press('Enter');
|
|
65
71
|
await editorPage.getEditor().press('Enter');
|
|
66
72
|
await page.keyboard.type('entry');
|
|
67
|
-
expect(
|
|
73
|
+
expect(history.length).toBe(1);
|
|
74
|
+
|
|
68
75
|
await editorPage.getEditor().press('Control+Enter');
|
|
69
76
|
await editorPage.getEditor().press('Meta+Enter');
|
|
70
|
-
expect(
|
|
77
|
+
expect(history.length).toBe(2);
|
|
78
|
+
|
|
79
|
+
// rerender with new history
|
|
80
|
+
await editor.update(
|
|
81
|
+
<CypherEditor
|
|
82
|
+
value={initialValue}
|
|
83
|
+
history={history}
|
|
84
|
+
onExecute={onExecute}
|
|
85
|
+
/>,
|
|
86
|
+
);
|
|
71
87
|
|
|
72
88
|
// type a new query and make sure it's not lost when navigating history
|
|
73
89
|
await editorPage.getEditor().fill('draft');
|
|
74
90
|
await expect(page.getByText('draft')).toBeVisible();
|
|
75
|
-
expect(
|
|
91
|
+
expect(history.length).toBe(2);
|
|
76
92
|
|
|
77
93
|
// Navigate to the top of the editor before navigating history
|
|
78
94
|
await editorPage.getEditor().press('ArrowLeft');
|
|
@@ -110,7 +126,7 @@ test('can navigate with cmd+up as well', async ({ page, mount }) => {
|
|
|
110
126
|
await mount(
|
|
111
127
|
<CypherEditor
|
|
112
128
|
value={initialValue}
|
|
113
|
-
|
|
129
|
+
history={[
|
|
114
130
|
`one
|
|
115
131
|
multiline
|
|
116
132
|
entry
|
|
@@ -142,3 +158,39 @@ entry
|
|
|
142
158
|
await editorPage.getEditor().press(metaDown);
|
|
143
159
|
await expect(page.getByText('multiline')).toBeVisible();
|
|
144
160
|
});
|
|
161
|
+
|
|
162
|
+
test('test onExecute', async ({ page, mount }) => {
|
|
163
|
+
const editorPage = new CypherEditorPage(page);
|
|
164
|
+
const isMac = process.platform === 'darwin';
|
|
165
|
+
const execButton = isMac ? 'Meta+Enter' : 'Control+Enter';
|
|
166
|
+
|
|
167
|
+
const initialValue = 'MATCH (n) RETURN n;';
|
|
168
|
+
const history = [];
|
|
169
|
+
|
|
170
|
+
const onExecute = (cmd: string) => {
|
|
171
|
+
history.unshift(cmd);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const cypherEditor = await mount(
|
|
175
|
+
<CypherEditor value={initialValue} onExecute={onExecute} />,
|
|
176
|
+
);
|
|
177
|
+
await editorPage.getEditor().press(execButton);
|
|
178
|
+
expect(history).toEqual([initialValue]);
|
|
179
|
+
|
|
180
|
+
await editorPage.getEditor().press(execButton);
|
|
181
|
+
expect(history).toEqual([initialValue, initialValue]);
|
|
182
|
+
|
|
183
|
+
// can update onExecute
|
|
184
|
+
let newExecRan = false;
|
|
185
|
+
const newOnExecute = () => {
|
|
186
|
+
newExecRan = true;
|
|
187
|
+
};
|
|
188
|
+
await cypherEditor.update(
|
|
189
|
+
<CypherEditor value={initialValue} onExecute={newOnExecute} />,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
await editorPage.getEditor().press(execButton);
|
|
193
|
+
expect(newExecRan).toEqual(true);
|
|
194
|
+
// old value should still be only 2
|
|
195
|
+
expect(history).toEqual([initialValue, initialValue]);
|
|
196
|
+
});
|
|
@@ -77,11 +77,11 @@ const historyState = StateField.define<HistoryState>({
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
} else if (effect.is(
|
|
80
|
+
} else if (effect.is(replaceHistory)) {
|
|
81
81
|
return {
|
|
82
82
|
...value,
|
|
83
83
|
index: DRAFT_ENTRY_INDEX,
|
|
84
|
-
history:
|
|
84
|
+
history: effect.value,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -91,7 +91,7 @@ const historyState = StateField.define<HistoryState>({
|
|
|
91
91
|
|
|
92
92
|
type HistoryNavigation = 'BACK' | 'FORWARDS';
|
|
93
93
|
const moveInHistory = StateEffect.define<HistoryNavigation>();
|
|
94
|
-
const
|
|
94
|
+
export const replaceHistory = StateEffect.define<string[]>();
|
|
95
95
|
|
|
96
96
|
function navigateHistory(view: EditorView, direction: HistoryNavigation) {
|
|
97
97
|
view.dispatch(
|
|
@@ -116,39 +116,16 @@ function navigateHistory(view: EditorView, direction: HistoryNavigation) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
type ReplProps = {
|
|
119
|
-
|
|
120
|
-
initialHistory?: string[];
|
|
121
|
-
onNewHistoryEntry?: (historyEntry: string) => void;
|
|
119
|
+
history?: string[];
|
|
122
120
|
};
|
|
123
121
|
|
|
124
|
-
export const replMode = ({
|
|
125
|
-
onExecute,
|
|
126
|
-
onNewHistoryEntry,
|
|
127
|
-
initialHistory,
|
|
128
|
-
}: ReplProps): Extension[] => {
|
|
122
|
+
export const replMode = ({ history }: ReplProps): Extension[] => {
|
|
129
123
|
return [
|
|
130
124
|
historyState.init(() => ({
|
|
131
125
|
...historyInitialState,
|
|
132
|
-
history
|
|
126
|
+
history,
|
|
133
127
|
})),
|
|
134
128
|
keymap.of([
|
|
135
|
-
{
|
|
136
|
-
key: 'Ctrl-Enter',
|
|
137
|
-
mac: 'Mod-Enter',
|
|
138
|
-
preventDefault: true,
|
|
139
|
-
run: (view) => {
|
|
140
|
-
const doc = view.state.doc.toString();
|
|
141
|
-
if (doc.trim() !== '') {
|
|
142
|
-
onExecute?.(doc);
|
|
143
|
-
onNewHistoryEntry?.(doc);
|
|
144
|
-
view.dispatch({
|
|
145
|
-
effects: pushToHistory.of(doc),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return true;
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
129
|
{
|
|
153
130
|
key: 'ArrowUp',
|
|
154
131
|
preventDefault: true,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@codemirror/state';
|
|
2
|
-
type ReplProps = {
|
|
3
|
-
onExecute: (cmd: string) => void;
|
|
4
|
-
initialHistory?: string[];
|
|
5
|
-
onNewHistoryEntry?: (historyEntry: string) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare const replMode: ({ onExecute, onNewHistoryEntry, initialHistory, }: ReplProps) => Extension[];
|
|
8
|
-
export {};
|