@neo4j-cypher/react-codemirror 1.0.1 → 1.0.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.
@@ -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
@@ -74,6 +81,7 @@ class CypherEditor extends Component {
74
81
  };
75
82
  this.lastValue = null;
76
83
  this.lastPosition = null;
84
+ this.lastSelection = null;
77
85
  }
78
86
  componentDidMount() {
79
87
  const {
@@ -102,6 +110,7 @@ class CypherEditor extends Component {
102
110
  searchOpen,
103
111
  searchText,
104
112
  searchTop,
113
+ selection,
105
114
  tabKey,
106
115
  theme,
107
116
  tooltipAbsolute,
@@ -140,6 +149,7 @@ class CypherEditor extends Component {
140
149
  searchOpen,
141
150
  searchText,
142
151
  searchTop,
152
+ selection,
143
153
  tabKey,
144
154
  theme,
145
155
  tooltipAbsolute,
@@ -153,6 +163,7 @@ class CypherEditor extends Component {
153
163
  this.cypherEditor.onFocusChanged(this.focusChanged);
154
164
  this.cypherEditor.onScrollChanged(this.scrollChanged);
155
165
  this.cypherEditor.onPositionChanged(this.positionChanged);
166
+ this.cypherEditor.onSelectionChanged(this.selectionChanged);
156
167
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
157
168
  this.cypherEditor.onSearchChanged(this.searchChanged);
158
169
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
@@ -166,6 +177,7 @@ class CypherEditor extends Component {
166
177
  this.cypherEditor.offFocusChanged(this.focusChanged);
167
178
  this.cypherEditor.offScrollChanged(this.scrollChanged);
168
179
  this.cypherEditor.offPositionChanged(this.positionChanged);
180
+ this.cypherEditor.offSelectionChanged(this.selectionChanged);
169
181
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
170
182
  this.cypherEditor.offSearchChanged(this.searchChanged);
171
183
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
@@ -210,6 +222,13 @@ class CypherEditor extends Component {
210
222
  this.lastPosition = position;
211
223
  }
212
224
  }
225
+ if (key === "selection") {
226
+ if (prop[key] === this.lastSelection) {
227
+ return;
228
+ } else {
229
+ this.lastSelection = prop[key];
230
+ }
231
+ }
213
232
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
214
233
  if (this.cypherEditor[methodName]) {
215
234
  this.cypherEditor[methodName](prop[key]);
@@ -226,7 +245,8 @@ class CypherEditor extends Component {
226
245
  render() {
227
246
  const {
228
247
  className,
229
- focusedClassName
248
+ focusedClassName,
249
+ style
230
250
  } = this.props;
231
251
  const {
232
252
  focused
@@ -234,6 +254,7 @@ class CypherEditor extends Component {
234
254
  const editorClassName = (className ? className + " " : "") + (focused && focusedClassName ? focusedClassName : "");
235
255
  return /*#__PURE__*/_jsx("div", {
236
256
  className: editorClassName,
257
+ style: style,
237
258
  ref: this.setEditorRef
238
259
  });
239
260
  }
@@ -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
@@ -83,6 +90,7 @@ class CypherEditor extends _react.Component {
83
90
  };
84
91
  this.lastValue = null;
85
92
  this.lastPosition = null;
93
+ this.lastSelection = null;
86
94
  }
87
95
  componentDidMount() {
88
96
  const {
@@ -111,6 +119,7 @@ class CypherEditor extends _react.Component {
111
119
  searchOpen,
112
120
  searchText,
113
121
  searchTop,
122
+ selection,
114
123
  tabKey,
115
124
  theme,
116
125
  tooltipAbsolute,
@@ -149,6 +158,7 @@ class CypherEditor extends _react.Component {
149
158
  searchOpen,
150
159
  searchText,
151
160
  searchTop,
161
+ selection,
152
162
  tabKey,
153
163
  theme,
154
164
  tooltipAbsolute,
@@ -162,6 +172,7 @@ class CypherEditor extends _react.Component {
162
172
  this.cypherEditor.onFocusChanged(this.focusChanged);
163
173
  this.cypherEditor.onScrollChanged(this.scrollChanged);
164
174
  this.cypherEditor.onPositionChanged(this.positionChanged);
175
+ this.cypherEditor.onSelectionChanged(this.selectionChanged);
165
176
  this.cypherEditor.onAutocompleteChanged(this.autocompleteChanged);
166
177
  this.cypherEditor.onSearchChanged(this.searchChanged);
167
178
  this.cypherEditor.onLineNumberClick(this.lineNumberClick);
@@ -175,6 +186,7 @@ class CypherEditor extends _react.Component {
175
186
  this.cypherEditor.offFocusChanged(this.focusChanged);
176
187
  this.cypherEditor.offScrollChanged(this.scrollChanged);
177
188
  this.cypherEditor.offPositionChanged(this.positionChanged);
189
+ this.cypherEditor.offSelectionChanged(this.selectionChanged);
178
190
  this.cypherEditor.offAutocompleteChanged(this.autocompleteChanged);
179
191
  this.cypherEditor.offSearchChanged(this.searchChanged);
180
192
  this.cypherEditor.offLineNumberClick(this.lineNumberClick);
@@ -219,6 +231,13 @@ class CypherEditor extends _react.Component {
219
231
  this.lastPosition = position;
220
232
  }
221
233
  }
234
+ if (key === "selection") {
235
+ if (prop[key] === this.lastSelection) {
236
+ return;
237
+ } else {
238
+ this.lastSelection = prop[key];
239
+ }
240
+ }
222
241
  const methodName = "set" + key[0].toUpperCase() + key.slice(1);
223
242
  if (this.cypherEditor[methodName]) {
224
243
  this.cypherEditor[methodName](prop[key]);
@@ -235,7 +254,8 @@ class CypherEditor extends _react.Component {
235
254
  render() {
236
255
  const {
237
256
  className,
238
- focusedClassName
257
+ focusedClassName,
258
+ style
239
259
  } = this.props;
240
260
  const {
241
261
  focused
@@ -243,6 +263,7 @@ class CypherEditor extends _react.Component {
243
263
  const editorClassName = (className ? className + " " : "") + (focused && focusedClassName ? focusedClassName : "");
244
264
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
245
265
  className: editorClassName,
266
+ style: style,
246
267
  ref: this.setEditorRef
247
268
  });
248
269
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "codemirror",
8
8
  "codemirror 6"
9
9
  ],
10
- "version": "1.0.1",
10
+ "version": "1.0.3",
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.1"
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,
@@ -14,7 +14,8 @@ import type {
14
14
  ValueChangedListener,
15
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
  *
@@ -231,7 +238,10 @@ export interface CypherEditorProps {
231
238
  * A css class name to be added to the root editor dom element when it is focused
232
239
  */
233
240
  focusedClassName?: string;
234
-
241
+ /**
242
+ * a style prop to be applied to the root editor dom element
243
+ */
244
+ style?: React.CSSProperties;
235
245
  /**
236
246
  * A listener for when the editor api gets created
237
247
  */
@@ -260,6 +270,10 @@ export interface CypherEditorProps {
260
270
  * A listener for when the editor search state changes
261
271
  */
262
272
  onSearchChanged?: SearchChangedListener;
273
+ /**
274
+ * A listener for when the editor text selection changes
275
+ */
276
+ onSelectionChanged?: SelectionChangedListener;
263
277
  /**
264
278
  * A listener for when the user clicks an editor line number
265
279
  */