Skip to content

Commit 4f9986f

Browse files
committed
update api of cypher editor to expose resizeable prop
1 parent 2a7d533 commit 4f9986f

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

packages/react-codemirror-playground/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ export function App() {
8888
<button
8989
key={demoName}
9090
className={`hover:bg-blue-600 text-white font-bold py-1 px-3 rounded
91-
${
92-
selectedDemoName === demoName ? 'bg-blue-600' : 'bg-blue-400'
93-
}`}
91+
${selectedDemoName === demoName ? 'bg-blue-600' : 'bg-blue-400'
92+
}`}
9493
onClick={() => {
9594
setSelectedDemoName(demoName);
9695
setValue(demos[demoName]);
@@ -114,6 +113,7 @@ export function App() {
114113
schema={schema}
115114
featureFlags={{ signatureInfoOnAutoCompletions: true }}
116115
ariaLabel="Cypher Editor"
116+
resizeable={true}
117117
/>
118118

119119
{commandRanCount > 0 && (

packages/react-codemirror/src/CypherEditor.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ export interface CypherEditorProps {
174174
* @default false
175175
*/
176176
moveFocusOnTab?: boolean;
177+
178+
/**
179+
* Whether the editor should be resizable.
180+
*
181+
* true will initialize the editor with the resizable editor extension,
182+
* enabling the editor to be resized dynamically.
183+
*
184+
* @default false
185+
*/
186+
resizeable?: boolean;
177187
}
178188

179189
const executeKeybinding = (
@@ -321,15 +331,16 @@ export class CypherEditor extends Component<
321331
lineNumbers: true,
322332
newLineOnEnter: false,
323333
moveFocusOnTab: false,
334+
resizeable: false,
324335
};
325336

326337
private debouncedOnChange = this.props.onChange
327338
? debounce(
328-
((value, viewUpdate) => {
329-
this.props.onChange(value, viewUpdate);
330-
}) satisfies CypherEditorProps['onChange'],
331-
DEBOUNCE_TIME,
332-
)
339+
((value, viewUpdate) => {
340+
this.props.onChange(value, viewUpdate);
341+
}) satisfies CypherEditorProps['onChange'],
342+
DEBOUNCE_TIME,
343+
)
333344
: undefined;
334345

335346
componentDidMount(): void {
@@ -369,18 +380,18 @@ export class CypherEditor extends Component<
369380

370381
const changeListener = this.debouncedOnChange
371382
? [
372-
EditorView.updateListener.of((upt: ViewUpdate) => {
373-
const wasUserEdit = !upt.transactions.some((tr) =>
374-
tr.annotation(ExternalEdit),
375-
);
376-
377-
if (upt.docChanged && wasUserEdit) {
378-
const doc = upt.state.doc;
379-
const value = doc.toString();
380-
this.debouncedOnChange(value, upt);
381-
}
382-
}),
383-
]
383+
EditorView.updateListener.of((upt: ViewUpdate) => {
384+
const wasUserEdit = !upt.transactions.some((tr) =>
385+
tr.annotation(ExternalEdit),
386+
);
387+
388+
if (upt.docChanged && wasUserEdit) {
389+
const doc = upt.state.doc;
390+
const value = doc.toString();
391+
this.debouncedOnChange(value, upt);
392+
}
393+
}),
394+
]
384395
: [];
385396

386397
this.editorState.current = EditorState.create({
@@ -416,8 +427,8 @@ export class CypherEditor extends Component<
416427
),
417428
this.props.ariaLabel
418429
? EditorView.contentAttributes.of({
419-
'aria-label': this.props.ariaLabel,
420-
})
430+
'aria-label': this.props.ariaLabel,
431+
})
421432
: [],
422433
],
423434
doc: this.props.value,
@@ -465,7 +476,7 @@ export class CypherEditor extends Component<
465476
const didChangeTheme =
466477
prevProps.theme !== this.props.theme ||
467478
prevProps.overrideThemeBackgroundColor !==
468-
this.props.overrideThemeBackgroundColor;
479+
this.props.overrideThemeBackgroundColor;
469480

470481
if (didChangeTheme) {
471482
this.editorView.current.dispatch({

packages/react-codemirror/src/neo4jSetup.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ const insertTab: StateCommand = (cmd) => {
6464

6565
type SetupProps = {
6666
moveFocusOnTab?: boolean;
67+
resizeable?: boolean;
6768
};
6869

6970
export const basicNeo4jSetup = ({
7071
moveFocusOnTab = false,
72+
resizeable = false
7173
}: SetupProps): Extension[] => {
7274
const keymaps: KeyBinding[] = [
7375
closeBracketsKeymap,
@@ -155,7 +157,9 @@ export const basicNeo4jSetup = ({
155157
]),
156158
);
157159

158-
extensions.push(resizableEditor())
160+
if (resizeable) {
161+
extensions.push(resizableEditor())
162+
}
159163

160164
return extensions;
161165
};

0 commit comments

Comments
 (0)