@neo4j-cypher/react-codemirror 1.0.0-next.2 → 1.0.0-next.20

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.
@@ -29,8 +29,7 @@ class CypherEditor extends Component {
29
29
  this.editorRef = ref;
30
30
  });
31
31
  _defineProperty(this, "valueChanged", (value, changes) => {
32
- this.innerValue = value;
33
- this.value = value;
32
+ this.lastValue = value;
34
33
  const {
35
34
  onValueChanged
36
35
  } = this.props;
@@ -52,16 +51,25 @@ class CypherEditor extends Component {
52
51
  onScrollChanged && onScrollChanged(scrollInfo);
53
52
  });
54
53
  _defineProperty(this, "positionChanged", positionObject => {
54
+ this.lastPosition = (positionObject || {
55
+ position: null
56
+ }).position;
55
57
  const {
56
58
  onPositionChanged
57
59
  } = this.props;
58
60
  onPositionChanged && onPositionChanged(positionObject);
59
61
  });
60
- _defineProperty(this, "autocompleteChanged", (autocompleteOpen, from, options) => {
62
+ _defineProperty(this, "autocompleteChanged", (autocompleteOpen, options, option) => {
61
63
  const {
62
64
  onAutocompleteChanged
63
65
  } = this.props;
64
- onAutocompleteChanged && onAutocompleteChanged(autocompleteOpen, from, options);
66
+ onAutocompleteChanged && onAutocompleteChanged(autocompleteOpen, options, option);
67
+ });
68
+ _defineProperty(this, "searchChanged", (searchOpen, text, matches) => {
69
+ const {
70
+ onSearchChanged
71
+ } = this.props;
72
+ onSearchChanged && onSearchChanged(searchOpen, text, matches);
65
73
  });
66
74
  _defineProperty(this, "lineNumberClick", (line, event) => {
67
75
  const {
@@ -78,6 +86,8 @@ class CypherEditor extends Component {
78
86
  this.state = {
79
87
  focused: false
80
88
  };
89
+ this.lastValue = null;
90
+ this.lastPosition = null;
81
91
  }
82
92
  componentDidMount() {
83
93
  const {
@@ -86,7 +96,12 @@ class CypherEditor extends Component {
86
96
  autocompleteOpen,
87
97
  autocompleteTriggerStrings,
88
98
  autofocus,
99
+ bracketMatching,
100
+ closeBrackets,
101
+ cursorWide,
102
+ cypherLanguage,
89
103
  history,
104
+ indentUnit,
90
105
  lineNumberFormatter,
91
106
  lineNumbers,
92
107
  lineWrapping,
@@ -96,12 +111,21 @@ class CypherEditor extends Component {
96
111
  readOnly,
97
112
  readOnlyCursor,
98
113
  schema,
114
+ search,
115
+ searchMatches,
116
+ searchOpen,
117
+ searchText,
118
+ searchTop,
119
+ tabKey,
99
120
  theme,
121
+ tooltipAbsolute,
100
122
  parseOnSetValue,
101
123
  value,
102
- onEditorCreated
124
+ onEditorCreated,
125
+ preExtensions,
126
+ postExtensions
103
127
  } = this.props;
104
- this.value = this.innerValue = value;
128
+ this.value = value;
105
129
  const {
106
130
  editor
107
131
  } = createCypherEditor(this.editorRef, {
@@ -110,7 +134,12 @@ class CypherEditor extends Component {
110
134
  autocompleteOpen,
111
135
  autocompleteTriggerStrings,
112
136
  autofocus,
137
+ bracketMatching,
138
+ closeBrackets,
139
+ cursorWide,
140
+ cypherLanguage,
113
141
  history,
142
+ indentUnit,
114
143
  lineNumberFormatter,
115
144
  lineNumbers,
116
145
  lineWrapping,
@@ -120,9 +149,18 @@ class CypherEditor extends Component {
120
149
  readOnly,
121
150
  readOnlyCursor,
122
151
  schema,
152
+ search,
153
+ searchMatches,
154
+ searchOpen,
155
+ searchText,
156
+ searchTop,
157
+ tabKey,
123
158
  theme,
159
+ tooltipAbsolute,
124
160
  parseOnSetValue,
125
- value
161
+ value,
162
+ preExtensions,
163
+ postExtensions
126
164
  });
127
165
  this.cypherEditor = editor;
128
166
  this.cypherEditor.onValueChanged(this.valueChanged);
@@ -130,6 +168,7 @@ class CypherEditor extends Component {
130
168
  this.cypherEditor.onScrollChanged(this.scrollChanged);
131
169
  this.cypherEditor.onPositionChanged(this.positionChanged);
132
170
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
171
+ this.cypherEditor.onSearchChanged(this.searchChanged);
133
172
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
134
173
  this.cypherEditor.onKeyDown(this.keyDown);
135
174
  onEditorCreated && onEditorCreated(this.cypherEditor);
@@ -141,6 +180,7 @@ class CypherEditor extends Component {
141
180
  this.cypherEditor.offScrollChanged(this.scrollChanged);
142
181
  this.cypherEditor.offPositionChanged(this.positionChanged);
143
182
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
183
+ this.cypherEditor.offSearchChanged(this.searchChanged);
144
184
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
145
185
  this.cypherEditor.offKeyDown(this.keyDown);
146
186
  this.cypherEditor.destroy();
@@ -163,12 +203,25 @@ class CypherEditor extends Component {
163
203
  return;
164
204
  }
165
205
  const key = Object.keys(prop).pop();
166
-
167
- // Call setValue only if the change comes from the outside
168
- if (key === "value" && this.innerValue === this.value) {
169
- return; // TODO - this probably isn't needed for React (only needed for bind:value in Svelte?)
206
+ if (key === "value") {
207
+ if (prop[key] === this.lastValue) {
208
+ return;
209
+ } else {
210
+ this.lastValue = prop[key];
211
+ }
212
+ }
213
+ if (key === "position") {
214
+ const {
215
+ position
216
+ } = this.cypherEditor.getPositionForValue(prop[key]) || {
217
+ position: null
218
+ };
219
+ if (position === this.lastPosition) {
220
+ return;
221
+ } else {
222
+ this.lastPosition = position;
223
+ }
170
224
  }
171
-
172
225
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
173
226
  if (this.cypherEditor[methodName]) {
174
227
  this.cypherEditor[methodName](prop[key]);
@@ -177,6 +230,10 @@ class CypherEditor extends Component {
177
230
  if (autofocusProps.includes(key)) {
178
231
  this.cypherEditor.focus();
179
232
  }
233
+ const clearHistoryProps = this.props.clearHistoryProps !== undefined ? this.props.clearHistoryProps : defaultOptions.clearHistoryProps;
234
+ if (clearHistoryProps.includes(key)) {
235
+ this.cypherEditor.clearHistory();
236
+ }
180
237
  }
181
238
  render() {
182
239
  const {
@@ -18,5 +18,4 @@
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
20
 
21
- export { default as UnstyledCypherEditor } from "./CypherEditor";
22
- export { default as CypherEditor } from "./CypherEditorStyled";
21
+ export { default as CypherEditor } from "./CypherEditor";
@@ -38,8 +38,7 @@ class CypherEditor extends _react.Component {
38
38
  this.editorRef = ref;
39
39
  });
40
40
  (0, _defineProperty2.default)(this, "valueChanged", (value, changes) => {
41
- this.innerValue = value;
42
- this.value = value;
41
+ this.lastValue = value;
43
42
  const {
44
43
  onValueChanged
45
44
  } = this.props;
@@ -61,16 +60,25 @@ class CypherEditor extends _react.Component {
61
60
  onScrollChanged && onScrollChanged(scrollInfo);
62
61
  });
63
62
  (0, _defineProperty2.default)(this, "positionChanged", positionObject => {
63
+ this.lastPosition = (positionObject || {
64
+ position: null
65
+ }).position;
64
66
  const {
65
67
  onPositionChanged
66
68
  } = this.props;
67
69
  onPositionChanged && onPositionChanged(positionObject);
68
70
  });
69
- (0, _defineProperty2.default)(this, "autocompleteChanged", (autocompleteOpen, from, options) => {
71
+ (0, _defineProperty2.default)(this, "autocompleteChanged", (autocompleteOpen, options, option) => {
70
72
  const {
71
73
  onAutocompleteChanged
72
74
  } = this.props;
73
- onAutocompleteChanged && onAutocompleteChanged(autocompleteOpen, from, options);
75
+ onAutocompleteChanged && onAutocompleteChanged(autocompleteOpen, options, option);
76
+ });
77
+ (0, _defineProperty2.default)(this, "searchChanged", (searchOpen, text, matches) => {
78
+ const {
79
+ onSearchChanged
80
+ } = this.props;
81
+ onSearchChanged && onSearchChanged(searchOpen, text, matches);
74
82
  });
75
83
  (0, _defineProperty2.default)(this, "lineNumberClick", (line, event) => {
76
84
  const {
@@ -87,6 +95,8 @@ class CypherEditor extends _react.Component {
87
95
  this.state = {
88
96
  focused: false
89
97
  };
98
+ this.lastValue = null;
99
+ this.lastPosition = null;
90
100
  }
91
101
  componentDidMount() {
92
102
  const {
@@ -95,7 +105,12 @@ class CypherEditor extends _react.Component {
95
105
  autocompleteOpen,
96
106
  autocompleteTriggerStrings,
97
107
  autofocus,
108
+ bracketMatching,
109
+ closeBrackets,
110
+ cursorWide,
111
+ cypherLanguage,
98
112
  history,
113
+ indentUnit,
99
114
  lineNumberFormatter,
100
115
  lineNumbers,
101
116
  lineWrapping,
@@ -105,12 +120,21 @@ class CypherEditor extends _react.Component {
105
120
  readOnly,
106
121
  readOnlyCursor,
107
122
  schema,
123
+ search,
124
+ searchMatches,
125
+ searchOpen,
126
+ searchText,
127
+ searchTop,
128
+ tabKey,
108
129
  theme,
130
+ tooltipAbsolute,
109
131
  parseOnSetValue,
110
132
  value,
111
- onEditorCreated
133
+ onEditorCreated,
134
+ preExtensions,
135
+ postExtensions
112
136
  } = this.props;
113
- this.value = this.innerValue = value;
137
+ this.value = value;
114
138
  const {
115
139
  editor
116
140
  } = (0, _codemirror.createCypherEditor)(this.editorRef, {
@@ -119,7 +143,12 @@ class CypherEditor extends _react.Component {
119
143
  autocompleteOpen,
120
144
  autocompleteTriggerStrings,
121
145
  autofocus,
146
+ bracketMatching,
147
+ closeBrackets,
148
+ cursorWide,
149
+ cypherLanguage,
122
150
  history,
151
+ indentUnit,
123
152
  lineNumberFormatter,
124
153
  lineNumbers,
125
154
  lineWrapping,
@@ -129,9 +158,18 @@ class CypherEditor extends _react.Component {
129
158
  readOnly,
130
159
  readOnlyCursor,
131
160
  schema,
161
+ search,
162
+ searchMatches,
163
+ searchOpen,
164
+ searchText,
165
+ searchTop,
166
+ tabKey,
132
167
  theme,
168
+ tooltipAbsolute,
133
169
  parseOnSetValue,
134
- value
170
+ value,
171
+ preExtensions,
172
+ postExtensions
135
173
  });
136
174
  this.cypherEditor = editor;
137
175
  this.cypherEditor.onValueChanged(this.valueChanged);
@@ -139,6 +177,7 @@ class CypherEditor extends _react.Component {
139
177
  this.cypherEditor.onScrollChanged(this.scrollChanged);
140
178
  this.cypherEditor.onPositionChanged(this.positionChanged);
141
179
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
180
+ this.cypherEditor.onSearchChanged(this.searchChanged);
142
181
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
143
182
  this.cypherEditor.onKeyDown(this.keyDown);
144
183
  onEditorCreated && onEditorCreated(this.cypherEditor);
@@ -150,6 +189,7 @@ class CypherEditor extends _react.Component {
150
189
  this.cypherEditor.offScrollChanged(this.scrollChanged);
151
190
  this.cypherEditor.offPositionChanged(this.positionChanged);
152
191
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
192
+ this.cypherEditor.offSearchChanged(this.searchChanged);
153
193
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
154
194
  this.cypherEditor.offKeyDown(this.keyDown);
155
195
  this.cypherEditor.destroy();
@@ -172,12 +212,25 @@ class CypherEditor extends _react.Component {
172
212
  return;
173
213
  }
174
214
  const key = Object.keys(prop).pop();
175
-
176
- // Call setValue only if the change comes from the outside
177
- if (key === "value" && this.innerValue === this.value) {
178
- return; // TODO - this probably isn't needed for React (only needed for bind:value in Svelte?)
215
+ if (key === "value") {
216
+ if (prop[key] === this.lastValue) {
217
+ return;
218
+ } else {
219
+ this.lastValue = prop[key];
220
+ }
221
+ }
222
+ if (key === "position") {
223
+ const {
224
+ position
225
+ } = this.cypherEditor.getPositionForValue(prop[key]) || {
226
+ position: null
227
+ };
228
+ if (position === this.lastPosition) {
229
+ return;
230
+ } else {
231
+ this.lastPosition = position;
232
+ }
179
233
  }
180
-
181
234
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
182
235
  if (this.cypherEditor[methodName]) {
183
236
  this.cypherEditor[methodName](prop[key]);
@@ -186,6 +239,10 @@ class CypherEditor extends _react.Component {
186
239
  if (autofocusProps.includes(key)) {
187
240
  this.cypherEditor.focus();
188
241
  }
242
+ const clearHistoryProps = this.props.clearHistoryProps !== undefined ? this.props.clearHistoryProps : _codemirror.defaultOptions.clearHistoryProps;
243
+ if (clearHistoryProps.includes(key)) {
244
+ this.cypherEditor.clearHistory();
245
+ }
189
246
  }
190
247
  render() {
191
248
  const {
@@ -5,16 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  Object.defineProperty(exports, "CypherEditor", {
8
- enumerable: true,
9
- get: function () {
10
- return _CypherEditorStyled.default;
11
- }
12
- });
13
- Object.defineProperty(exports, "UnstyledCypherEditor", {
14
8
  enumerable: true,
15
9
  get: function () {
16
10
  return _CypherEditor.default;
17
11
  }
18
12
  });
19
- var _CypherEditor = _interopRequireDefault(require("./CypherEditor"));
20
- var _CypherEditorStyled = _interopRequireDefault(require("./CypherEditorStyled"));
13
+ var _CypherEditor = _interopRequireDefault(require("./CypherEditor"));
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "codemirror",
8
8
  "codemirror 6"
9
9
  ],
10
- "version": "1.0.0-next.2",
10
+ "version": "1.0.0-next.20",
11
11
  "author": "Neo4j Inc.",
12
12
  "license": "GPL-3.0",
13
13
  "main": "./lib/react-codemirror.js",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@babel/runtime": "^7.20.6",
41
- "@neo4j-cypher/codemirror": "1.0.0-next.2",
41
+ "@neo4j-cypher/codemirror": "1.0.0-next.19",
42
42
  "codemirror": "^6.0.1"
43
43
  },
44
44
  "peerDependencies": {
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- // import type { Extension } from "@codemirror/state";
2
+ import type { Extension } from "@codemirror/state";
3
3
  import type { EditorSupportSchema } from "@neo4j-cypher/editor-support";
4
4
  import type {
5
5
  PositionAny,
@@ -10,6 +10,7 @@ import type {
10
10
  PositionChangedListener,
11
11
  FocusChangedListener,
12
12
  ScrollChangedListener,
13
+ SearchChangedListener,
13
14
  ValueChangedListener,
14
15
  KeyDownListener,
15
16
  LineNumberClickListener,
@@ -33,7 +34,7 @@ export interface CypherEditorProps {
33
34
  */
34
35
  autocompleteCloseOnBlur?: boolean;
35
36
  /**
36
- * Whether the autocomplete window is open
37
+ * Whether the autocomplete panel is open
37
38
  *
38
39
  * @remarks
39
40
  *
@@ -60,12 +61,48 @@ export interface CypherEditorProps {
60
61
  * @defaultValue ["position", "readOnly", "value"]
61
62
  */
62
63
  autofocusProps?: AutofocusProp[];
64
+ /**
65
+ * Whether to show matching brackets in the editor view
66
+ *
67
+ * @defaultValue true
68
+ */
69
+ bracketMatching?: boolean;
70
+ /**
71
+ * Setting any of these props will trigger the editor to clear its undo/redo history
72
+ *
73
+ * @defaultValue ["cypherLanguage"]
74
+ */
75
+ clearHistoryProps?: AutofocusProp[];
76
+ /**
77
+ * Whether to automatically close brackets or wrap selected text with quotes on quote press
78
+ *
79
+ * @defaultValue true
80
+ */
81
+ closeBrackets?: boolean;
82
+ /**
83
+ * Whether the wide cursor should be shown
84
+ *
85
+ * @defaultValue true
86
+ */
87
+ cursorWide?: boolean;
88
+ /**
89
+ * Whether or not cypher language extensions are enabled
90
+ *
91
+ * @defaultValue true
92
+ */
93
+ cypherLanguage?: boolean;
63
94
  /**
64
95
  * Whether the editor maintains an undo/redo history
65
96
  *
66
97
  * @defaultValue true
67
98
  */
68
99
  history?: boolean;
100
+ /**
101
+ * The indent text to use when tabKey is enabled
102
+ *
103
+ * @defaultValue " "
104
+ */
105
+ indentUnit?: string;
69
106
  /**
70
107
  * The formatter for the line numbers of the editor
71
108
  *
@@ -120,12 +157,66 @@ export interface CypherEditorProps {
120
157
  * The schema making the editor aware of things such as node labels & relationship types & procedures in the current graph database
121
158
  */
122
159
  schema?: EditorSupportSchema;
160
+ /**
161
+ * Whether search is enabled
162
+ *
163
+ * @defaultValue true
164
+ */
165
+ search?: boolean;
166
+ /**
167
+ * The max number of search matches to be included with search changed callbacks
168
+ *
169
+ * @remarks
170
+ *
171
+ * Must be between 0 and 1000, 0 means no searching for matches (better for performance)
172
+ *
173
+ * @defaultValue 0
174
+ */
175
+ searchMatches?: number;
176
+ /**
177
+ * Whether the search panel is open
178
+ *
179
+ * @remarks
180
+ *
181
+ * Changing this can be used to manually control the search open state
182
+ *
183
+ * @defaultValue `false`
184
+ */
185
+ searchOpen?: boolean;
186
+ /**
187
+ * The search text for the search panel
188
+ *
189
+ * @remarks
190
+ *
191
+ * Changing this can be used to manually control the search panel text
192
+ *
193
+ * @defaultValue ""
194
+ */
195
+ searchText?: string;
196
+ /**
197
+ * Whether search is shown at the top of the editor window
198
+ *
199
+ * @defaultValue false
200
+ */
201
+ searchTop?: boolean;
202
+ /**
203
+ * Whether the tab key is enabled
204
+ *
205
+ * @defaultValue true
206
+ */
207
+ tabKey?: boolean;
123
208
  /**
124
209
  * Whether to use the light or dark theme for the editor
125
210
  *
126
211
  * @defaultValue "light"
127
212
  */
128
213
  theme?: Theme;
214
+ /**
215
+ * Whether or not the tooltips use simple absolute position styling (vs trying to stay within bounds)
216
+ *
217
+ * @defaultValue true
218
+ */
219
+ tooltipAbsolute?: boolean;
129
220
  /**
130
221
  * The editor text value
131
222
  *
@@ -165,6 +256,10 @@ export interface CypherEditorProps {
165
256
  * A listener for when the editor autocompletion state changes
166
257
  */
167
258
  onAutocompleteChanged?: AutocompleteChangedListener;
259
+ /**
260
+ * A listener for when the editor search state changes
261
+ */
262
+ onSearchChanged?: SearchChangedListener;
168
263
  /**
169
264
  * A listener for when the user clicks an editor line number
170
265
  */
@@ -174,9 +269,18 @@ export interface CypherEditorProps {
174
269
  */
175
270
  onKeyDown?: KeyDownListener;
176
271
 
177
- // TODO - add these props
178
- // preExtensions?: Extension[],
179
- // postExtensions?: Extension[]
272
+ /**
273
+ * The codemirror 6 extensions that should be added to the editor before the cypher language support extensions.
274
+ *
275
+ * @defaultValue undefined
276
+ */
277
+ preExtensions?: Extension[];
278
+ /**
279
+ * The codemirror 6 extensions that should be added to the editor after the cypher language support extensions.
280
+ *
281
+ * @defaultValue undefined
282
+ */
283
+ postExtensions?: Extension[];
180
284
  }
181
285
 
182
286
  /**
@@ -15,8 +15,4 @@
15
15
  *
16
16
  * @packageDocumentation
17
17
  */
18
- export {
19
- default as UnstyledCypherEditor,
20
- CypherEditorProps
21
- } from "./CypherEditor";
22
- export { default as CypherEditor } from "./CypherEditorStyled";
18
+ export { default as CypherEditor, CypherEditorProps } from "./CypherEditor";
@@ -1,22 +0,0 @@
1
- /*
2
- * Copyright (c) "Neo4j"
3
- * Neo4j Sweden AB [http://neo4j.com]
4
- *
5
- * This file is part of Neo4j.
6
- *
7
- * Neo4j is free software: you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation, either version 3 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
- */
20
-
21
- import "@neo4j-cypher/codemirror/css/cypher-codemirror.css";
22
- export { default } from "./CypherEditor";
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- Object.defineProperty(exports, "default", {
8
- enumerable: true,
9
- get: function () {
10
- return _CypherEditor.default;
11
- }
12
- });
13
- require("@neo4j-cypher/codemirror/css/cypher-codemirror.css");
14
- var _CypherEditor = _interopRequireDefault(require("./CypherEditor"));
@@ -1,10 +0,0 @@
1
- import * as React from "react";
2
- import type { CypherEditorProps } from "./CypherEditor";
3
-
4
- /**
5
- * Cypher Editor React Component (with css styles included)
6
- */
7
- export default class CypherEditorStyled extends React.Component<
8
- CypherEditorProps,
9
- any
10
- > {}