@neo4j-cypher/react-codemirror 1.0.0-next.11 → 1.0.0-next.13

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,10 @@ class CypherEditor extends Component {
86
96
  autocompleteOpen,
87
97
  autocompleteTriggerStrings,
88
98
  autofocus,
99
+ cursorWide,
100
+ cypherLanguage,
89
101
  history,
102
+ indentUnit,
90
103
  lineNumberFormatter,
91
104
  lineNumbers,
92
105
  lineWrapping,
@@ -96,6 +109,11 @@ class CypherEditor extends Component {
96
109
  readOnly,
97
110
  readOnlyCursor,
98
111
  schema,
112
+ search,
113
+ searchMatches,
114
+ searchOpen,
115
+ searchText,
116
+ searchTop,
99
117
  tabKey,
100
118
  theme,
101
119
  tooltipAbsolute,
@@ -103,7 +121,7 @@ class CypherEditor extends Component {
103
121
  value,
104
122
  onEditorCreated
105
123
  } = this.props;
106
- this.value = this.innerValue = value;
124
+ this.value = value;
107
125
  const {
108
126
  editor
109
127
  } = createCypherEditor(this.editorRef, {
@@ -112,7 +130,10 @@ class CypherEditor extends Component {
112
130
  autocompleteOpen,
113
131
  autocompleteTriggerStrings,
114
132
  autofocus,
133
+ cursorWide,
134
+ cypherLanguage,
115
135
  history,
136
+ indentUnit,
116
137
  lineNumberFormatter,
117
138
  lineNumbers,
118
139
  lineWrapping,
@@ -122,6 +143,11 @@ class CypherEditor extends Component {
122
143
  readOnly,
123
144
  readOnlyCursor,
124
145
  schema,
146
+ search,
147
+ searchMatches,
148
+ searchOpen,
149
+ searchText,
150
+ searchTop,
125
151
  tabKey,
126
152
  theme,
127
153
  tooltipAbsolute,
@@ -134,6 +160,7 @@ class CypherEditor extends Component {
134
160
  this.cypherEditor.onScrollChanged(this.scrollChanged);
135
161
  this.cypherEditor.onPositionChanged(this.positionChanged);
136
162
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
163
+ this.cypherEditor.onSearchChanged(this.searchChanged);
137
164
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
138
165
  this.cypherEditor.onKeyDown(this.keyDown);
139
166
  onEditorCreated && onEditorCreated(this.cypherEditor);
@@ -145,6 +172,7 @@ class CypherEditor extends Component {
145
172
  this.cypherEditor.offScrollChanged(this.scrollChanged);
146
173
  this.cypherEditor.offPositionChanged(this.positionChanged);
147
174
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
175
+ this.cypherEditor.offSearchChanged(this.searchChanged);
148
176
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
149
177
  this.cypherEditor.offKeyDown(this.keyDown);
150
178
  this.cypherEditor.destroy();
@@ -167,12 +195,25 @@ class CypherEditor extends Component {
167
195
  return;
168
196
  }
169
197
  const key = Object.keys(prop).pop();
170
-
171
- // Call setValue only if the change comes from the outside
172
- if (key === "value" && this.innerValue === this.value) {
173
- return; // TODO - this probably isn't needed for React (only needed for bind:value in Svelte?)
198
+ if (key === "value") {
199
+ if (prop[key] === this.lastValue) {
200
+ return;
201
+ } else {
202
+ this.lastValue = prop[key];
203
+ }
204
+ }
205
+ if (key === "position") {
206
+ const {
207
+ position
208
+ } = this.cypherEditor.getPositionForValue(prop[key]) || {
209
+ position: null
210
+ };
211
+ if (position === this.lastPosition) {
212
+ return;
213
+ } else {
214
+ this.lastPosition = position;
215
+ }
174
216
  }
175
-
176
217
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
177
218
  if (this.cypherEditor[methodName]) {
178
219
  this.cypherEditor[methodName](prop[key]);
@@ -181,6 +222,10 @@ class CypherEditor extends Component {
181
222
  if (autofocusProps.includes(key)) {
182
223
  this.cypherEditor.focus();
183
224
  }
225
+ const clearHistoryProps = this.props.clearHistoryProps !== undefined ? this.props.clearHistoryProps : defaultOptions.clearHistoryProps;
226
+ if (clearHistoryProps.includes(key)) {
227
+ this.cypherEditor.clearHistory();
228
+ }
184
229
  }
185
230
  render() {
186
231
  const {
@@ -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,10 @@ class CypherEditor extends _react.Component {
95
105
  autocompleteOpen,
96
106
  autocompleteTriggerStrings,
97
107
  autofocus,
108
+ cursorWide,
109
+ cypherLanguage,
98
110
  history,
111
+ indentUnit,
99
112
  lineNumberFormatter,
100
113
  lineNumbers,
101
114
  lineWrapping,
@@ -105,6 +118,11 @@ class CypherEditor extends _react.Component {
105
118
  readOnly,
106
119
  readOnlyCursor,
107
120
  schema,
121
+ search,
122
+ searchMatches,
123
+ searchOpen,
124
+ searchText,
125
+ searchTop,
108
126
  tabKey,
109
127
  theme,
110
128
  tooltipAbsolute,
@@ -112,7 +130,7 @@ class CypherEditor extends _react.Component {
112
130
  value,
113
131
  onEditorCreated
114
132
  } = this.props;
115
- this.value = this.innerValue = value;
133
+ this.value = value;
116
134
  const {
117
135
  editor
118
136
  } = (0, _codemirror.createCypherEditor)(this.editorRef, {
@@ -121,7 +139,10 @@ class CypherEditor extends _react.Component {
121
139
  autocompleteOpen,
122
140
  autocompleteTriggerStrings,
123
141
  autofocus,
142
+ cursorWide,
143
+ cypherLanguage,
124
144
  history,
145
+ indentUnit,
125
146
  lineNumberFormatter,
126
147
  lineNumbers,
127
148
  lineWrapping,
@@ -131,6 +152,11 @@ class CypherEditor extends _react.Component {
131
152
  readOnly,
132
153
  readOnlyCursor,
133
154
  schema,
155
+ search,
156
+ searchMatches,
157
+ searchOpen,
158
+ searchText,
159
+ searchTop,
134
160
  tabKey,
135
161
  theme,
136
162
  tooltipAbsolute,
@@ -143,6 +169,7 @@ class CypherEditor extends _react.Component {
143
169
  this.cypherEditor.onScrollChanged(this.scrollChanged);
144
170
  this.cypherEditor.onPositionChanged(this.positionChanged);
145
171
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
172
+ this.cypherEditor.onSearchChanged(this.searchChanged);
146
173
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
147
174
  this.cypherEditor.onKeyDown(this.keyDown);
148
175
  onEditorCreated && onEditorCreated(this.cypherEditor);
@@ -154,6 +181,7 @@ class CypherEditor extends _react.Component {
154
181
  this.cypherEditor.offScrollChanged(this.scrollChanged);
155
182
  this.cypherEditor.offPositionChanged(this.positionChanged);
156
183
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
184
+ this.cypherEditor.offSearchChanged(this.searchChanged);
157
185
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
158
186
  this.cypherEditor.offKeyDown(this.keyDown);
159
187
  this.cypherEditor.destroy();
@@ -176,12 +204,25 @@ class CypherEditor extends _react.Component {
176
204
  return;
177
205
  }
178
206
  const key = Object.keys(prop).pop();
179
-
180
- // Call setValue only if the change comes from the outside
181
- if (key === "value" && this.innerValue === this.value) {
182
- return; // TODO - this probably isn't needed for React (only needed for bind:value in Svelte?)
207
+ if (key === "value") {
208
+ if (prop[key] === this.lastValue) {
209
+ return;
210
+ } else {
211
+ this.lastValue = prop[key];
212
+ }
213
+ }
214
+ if (key === "position") {
215
+ const {
216
+ position
217
+ } = this.cypherEditor.getPositionForValue(prop[key]) || {
218
+ position: null
219
+ };
220
+ if (position === this.lastPosition) {
221
+ return;
222
+ } else {
223
+ this.lastPosition = position;
224
+ }
183
225
  }
184
-
185
226
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
186
227
  if (this.cypherEditor[methodName]) {
187
228
  this.cypherEditor[methodName](prop[key]);
@@ -190,6 +231,10 @@ class CypherEditor extends _react.Component {
190
231
  if (autofocusProps.includes(key)) {
191
232
  this.cypherEditor.focus();
192
233
  }
234
+ const clearHistoryProps = this.props.clearHistoryProps !== undefined ? this.props.clearHistoryProps : _codemirror.defaultOptions.clearHistoryProps;
235
+ if (clearHistoryProps.includes(key)) {
236
+ this.cypherEditor.clearHistory();
237
+ }
193
238
  }
194
239
  render() {
195
240
  const {
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "codemirror",
8
8
  "codemirror 6"
9
9
  ],
10
- "version": "1.0.0-next.11",
10
+ "version": "1.0.0-next.13",
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.10",
41
+ "@neo4j-cypher/codemirror": "1.0.0-next.12",
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,36 @@ export interface CypherEditorProps {
60
61
  * @defaultValue ["position", "readOnly", "value"]
61
62
  */
62
63
  autofocusProps?: AutofocusProp[];
64
+ /**
65
+ * setting any of these props will trigger the editor to clear its undo/redo history
66
+ *
67
+ * @defaultValue ["cypherLanguage"]
68
+ */
69
+ clearHistoryProps?: AutofocusProp[];
70
+ /**
71
+ * Whether the wide cursor should be shown
72
+ *
73
+ * @defaultValue true
74
+ */
75
+ cursorWide?: boolean;
76
+ /**
77
+ * Whether or not cypher language extensions are enabled
78
+ *
79
+ * @defaultValue true
80
+ */
81
+ cypherLanguage?: boolean;
63
82
  /**
64
83
  * Whether the editor maintains an undo/redo history
65
84
  *
66
85
  * @defaultValue true
67
86
  */
68
87
  history?: boolean;
88
+ /**
89
+ * The indent text to use when tabKey is enabled
90
+ *
91
+ * @defaultValue " "
92
+ */
93
+ indentUnit?: string;
69
94
  /**
70
95
  * The formatter for the line numbers of the editor
71
96
  *
@@ -120,6 +145,48 @@ export interface CypherEditorProps {
120
145
  * The schema making the editor aware of things such as node labels & relationship types & procedures in the current graph database
121
146
  */
122
147
  schema?: EditorSupportSchema;
148
+ /**
149
+ * Whether search is enabled
150
+ *
151
+ * @defaultValue true
152
+ */
153
+ search?: boolean;
154
+ /**
155
+ * The max number of search matches to be included with search changed callbacks
156
+ *
157
+ * @remarks
158
+ *
159
+ * Must be between 0 and 1000, 0 means no searching for matches (better for performance)
160
+ *
161
+ * @defaultValue 0
162
+ */
163
+ searchMatches?: number;
164
+ /**
165
+ * Whether the search panel is open
166
+ *
167
+ * @remarks
168
+ *
169
+ * Changing this can be used to manually control the search open state
170
+ *
171
+ * @defaultValue `false`
172
+ */
173
+ searchOpen?: boolean;
174
+ /**
175
+ * The search text for the search panel
176
+ *
177
+ * @remarks
178
+ *
179
+ * Changing this can be used to manually control the search panel text
180
+ *
181
+ * @defaultValue ""
182
+ */
183
+ searchText?: string;
184
+ /**
185
+ * Whether search is shown at the top of the editor window
186
+ *
187
+ * @defaultValue false
188
+ */
189
+ searchTop?: boolean;
123
190
  /**
124
191
  * Whether the tab key is enabled
125
192
  *
@@ -177,6 +244,10 @@ export interface CypherEditorProps {
177
244
  * A listener for when the editor autocompletion state changes
178
245
  */
179
246
  onAutocompleteChanged?: AutocompleteChangedListener;
247
+ /**
248
+ * A listener for when the editor search state changes
249
+ */
250
+ onSearchChanged?: SearchChangedListener;
180
251
  /**
181
252
  * A listener for when the user clicks an editor line number
182
253
  */
@@ -186,9 +257,18 @@ export interface CypherEditorProps {
186
257
  */
187
258
  onKeyDown?: KeyDownListener;
188
259
 
189
- // TODO - add these props
190
- // preExtensions?: Extension[],
191
- // postExtensions?: Extension[]
260
+ /**
261
+ * The codemirror 6 extensions that should be added to the editor before the cypher language support extensions.
262
+ *
263
+ * @defaultValue undefined
264
+ */
265
+ preExtensions?: Extension[];
266
+ /**
267
+ * The codemirror 6 extensions that should be added to the editor after the cypher language support extensions.
268
+ *
269
+ * @defaultValue undefined
270
+ */
271
+ postExtensions?: Extension[];
192
272
  }
193
273
 
194
274
  /**