@neo4j-cypher/react-codemirror 1.0.0 → 1.0.2

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.
@@ -39,6 +39,13 @@ class CypherEditor extends Component {
39
39
  } = this.props;
40
40
  onPositionChanged && onPositionChanged(positionObject);
41
41
  });
42
+ _defineProperty(this, "selectionChanged", selection => {
43
+ this.lastSelection = selection;
44
+ const {
45
+ onSelectionChanged
46
+ } = this.props;
47
+ onSelectionChanged && onSelectionChanged(selection);
48
+ });
42
49
  _defineProperty(this, "autocompleteChanged", (autocompleteOpen, options, option) => {
43
50
  const {
44
51
  onAutocompleteChanged
@@ -63,11 +70,18 @@ class CypherEditor extends Component {
63
70
  } = this.props;
64
71
  onKeyDown && onKeyDown(event);
65
72
  });
73
+ _defineProperty(this, "keyUp", event => {
74
+ const {
75
+ onKeyUp
76
+ } = this.props;
77
+ onKeyUp && onKeyUp(event);
78
+ });
66
79
  this.state = {
67
80
  focused: false
68
81
  };
69
82
  this.lastValue = null;
70
83
  this.lastPosition = null;
84
+ this.lastSelection = null;
71
85
  }
72
86
  componentDidMount() {
73
87
  const {
@@ -96,6 +110,7 @@ class CypherEditor extends Component {
96
110
  searchOpen,
97
111
  searchText,
98
112
  searchTop,
113
+ selection,
99
114
  tabKey,
100
115
  theme,
101
116
  tooltipAbsolute,
@@ -134,6 +149,7 @@ class CypherEditor extends Component {
134
149
  searchOpen,
135
150
  searchText,
136
151
  searchTop,
152
+ selection,
137
153
  tabKey,
138
154
  theme,
139
155
  tooltipAbsolute,
@@ -147,10 +163,12 @@ class CypherEditor extends Component {
147
163
  this.cypherEditor.onFocusChanged(this.focusChanged);
148
164
  this.cypherEditor.onScrollChanged(this.scrollChanged);
149
165
  this.cypherEditor.onPositionChanged(this.positionChanged);
166
+ this.cypherEditor.onSelectionChanged(this.selectionChanged);
150
167
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
151
168
  this.cypherEditor.onSearchChanged(this.searchChanged);
152
169
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
153
170
  this.cypherEditor.onKeyDown(this.keyDown);
171
+ this.cypherEditor.onKeyUp(this.keyUp);
154
172
  onEditorCreated && onEditorCreated(this.cypherEditor);
155
173
  }
156
174
  componentWillUnmount() {
@@ -159,10 +177,12 @@ class CypherEditor extends Component {
159
177
  this.cypherEditor.offFocusChanged(this.focusChanged);
160
178
  this.cypherEditor.offScrollChanged(this.scrollChanged);
161
179
  this.cypherEditor.offPositionChanged(this.positionChanged);
180
+ this.cypherEditor.offSelectionChanged(this.selectionChanged);
162
181
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
163
182
  this.cypherEditor.offSearchChanged(this.searchChanged);
164
183
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
165
184
  this.cypherEditor.offKeyDown(this.keyDown);
185
+ this.cypherEditor.offKeyUp(this.keyUp);
166
186
  this.cypherEditor.destroy();
167
187
  }
168
188
  }
@@ -202,6 +222,13 @@ class CypherEditor extends Component {
202
222
  this.lastPosition = position;
203
223
  }
204
224
  }
225
+ if (key === "selection") {
226
+ if (prop[key] === this.lastSelection) {
227
+ return;
228
+ } else {
229
+ this.lastSelection = prop[key];
230
+ }
231
+ }
205
232
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
206
233
  if (this.cypherEditor[methodName]) {
207
234
  this.cypherEditor[methodName](prop[key]);
@@ -48,6 +48,13 @@ class CypherEditor extends _react.Component {
48
48
  } = this.props;
49
49
  onPositionChanged && onPositionChanged(positionObject);
50
50
  });
51
+ (0, _defineProperty2.default)(this, "selectionChanged", selection => {
52
+ this.lastSelection = selection;
53
+ const {
54
+ onSelectionChanged
55
+ } = this.props;
56
+ onSelectionChanged && onSelectionChanged(selection);
57
+ });
51
58
  (0, _defineProperty2.default)(this, "autocompleteChanged", (autocompleteOpen, options, option) => {
52
59
  const {
53
60
  onAutocompleteChanged
@@ -72,11 +79,18 @@ class CypherEditor extends _react.Component {
72
79
  } = this.props;
73
80
  onKeyDown && onKeyDown(event);
74
81
  });
82
+ (0, _defineProperty2.default)(this, "keyUp", event => {
83
+ const {
84
+ onKeyUp
85
+ } = this.props;
86
+ onKeyUp && onKeyUp(event);
87
+ });
75
88
  this.state = {
76
89
  focused: false
77
90
  };
78
91
  this.lastValue = null;
79
92
  this.lastPosition = null;
93
+ this.lastSelection = null;
80
94
  }
81
95
  componentDidMount() {
82
96
  const {
@@ -105,6 +119,7 @@ class CypherEditor extends _react.Component {
105
119
  searchOpen,
106
120
  searchText,
107
121
  searchTop,
122
+ selection,
108
123
  tabKey,
109
124
  theme,
110
125
  tooltipAbsolute,
@@ -143,6 +158,7 @@ class CypherEditor extends _react.Component {
143
158
  searchOpen,
144
159
  searchText,
145
160
  searchTop,
161
+ selection,
146
162
  tabKey,
147
163
  theme,
148
164
  tooltipAbsolute,
@@ -156,10 +172,12 @@ class CypherEditor extends _react.Component {
156
172
  this.cypherEditor.onFocusChanged(this.focusChanged);
157
173
  this.cypherEditor.onScrollChanged(this.scrollChanged);
158
174
  this.cypherEditor.onPositionChanged(this.positionChanged);
175
+ this.cypherEditor.onSelectionChanged(this.selectionChanged);
159
176
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
160
177
  this.cypherEditor.onSearchChanged(this.searchChanged);
161
178
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
162
179
  this.cypherEditor.onKeyDown(this.keyDown);
180
+ this.cypherEditor.onKeyUp(this.keyUp);
163
181
  onEditorCreated && onEditorCreated(this.cypherEditor);
164
182
  }
165
183
  componentWillUnmount() {
@@ -168,10 +186,12 @@ class CypherEditor extends _react.Component {
168
186
  this.cypherEditor.offFocusChanged(this.focusChanged);
169
187
  this.cypherEditor.offScrollChanged(this.scrollChanged);
170
188
  this.cypherEditor.offPositionChanged(this.positionChanged);
189
+ this.cypherEditor.offSelectionChanged(this.selectionChanged);
171
190
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
172
191
  this.cypherEditor.offSearchChanged(this.searchChanged);
173
192
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
174
193
  this.cypherEditor.offKeyDown(this.keyDown);
194
+ this.cypherEditor.offKeyUp(this.keyUp);
175
195
  this.cypherEditor.destroy();
176
196
  }
177
197
  }
@@ -211,6 +231,13 @@ class CypherEditor extends _react.Component {
211
231
  this.lastPosition = position;
212
232
  }
213
233
  }
234
+ if (key === "selection") {
235
+ if (prop[key] === this.lastSelection) {
236
+ return;
237
+ } else {
238
+ this.lastSelection = prop[key];
239
+ }
240
+ }
214
241
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
215
242
  if (this.cypherEditor[methodName]) {
216
243
  this.cypherEditor[methodName](prop[key]);
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "codemirror",
8
8
  "codemirror 6"
9
9
  ],
10
- "version": "1.0.0",
10
+ "version": "1.0.2",
11
11
  "author": "Neo4j Inc.",
12
12
  "license": "Apache-2.0",
13
13
  "main": "./lib/react-codemirror.js",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@babel/runtime": "^7.20.13",
53
- "@neo4j-cypher/codemirror": "1.0.0"
53
+ "@neo4j-cypher/codemirror": "1.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": ">=16"
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import type { Extension } from "@codemirror/state";
2
+ import type { Extension, EditorSelection } from "@codemirror/state";
3
3
  import type { EditorSupportSchema } from "@neo4j-cypher/editor-support";
4
4
  import type {
5
5
  PositionAny,
@@ -12,9 +12,10 @@ import type {
12
12
  ScrollChangedListener,
13
13
  SearchChangedListener,
14
14
  ValueChangedListener,
15
- KeyDownListener,
15
+ KeyListener,
16
16
  LineNumberClickListener,
17
- LineNumberFormatter
17
+ LineNumberFormatter,
18
+ SelectionChangedListener
18
19
  } from "@neo4j-cypher/codemirror";
19
20
 
20
21
  /**
@@ -199,6 +200,12 @@ export interface CypherEditorProps {
199
200
  * @defaultValue false
200
201
  */
201
202
  searchTop?: boolean;
203
+ /**
204
+ * The editor text selection
205
+ *
206
+ * @defaultValue undefined
207
+ */
208
+ selection?: EditorSelection;
202
209
  /**
203
210
  * Whether the tab key is enabled
204
211
  *
@@ -260,14 +267,22 @@ export interface CypherEditorProps {
260
267
  * A listener for when the editor search state changes
261
268
  */
262
269
  onSearchChanged?: SearchChangedListener;
270
+ /**
271
+ * A listener for when the editor text selection changes
272
+ */
273
+ onSelectionChanged?: SelectionChangedListener;
263
274
  /**
264
275
  * A listener for when the user clicks an editor line number
265
276
  */
266
277
  onLineNumberClick?: LineNumberClickListener;
267
278
  /**
268
- * A listener for when the user presses a key down in the editor
279
+ * A listener for when the user performs a key down in the editor
280
+ */
281
+ onKeyDown?: KeyListener;
282
+ /**
283
+ * A listener for when the user performs a key up in the editor
269
284
  */
270
- onKeyDown?: KeyDownListener;
285
+ onKeyUp?: KeyListener;
271
286
 
272
287
  /**
273
288
  * The codemirror 6 extensions that should be added to the editor before the cypher language support extensions.