@difizen/libro-code-editor 0.0.2-alpha.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Difizen Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,101 @@
1
+ /// <reference types="react" resolution-mode="require"/>
2
+ import { BaseView } from '@difizen/mana-app';
3
+ import { Deferred, Emitter } from '@difizen/mana-app';
4
+ import type { IEditor } from './code-editor.js';
5
+ import type { CodeEditorFactory, IEditorConfig, IEditorSelectionStyle, CompletionProvider, TooltipProvider, LSPProvider } from './code-editor.js';
6
+ import type { IModel } from './model.js';
7
+ export declare const CodeEditorRender: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>>;
8
+ /**
9
+ * A widget which hosts a code editor.
10
+ */
11
+ export declare class CodeEditorView extends BaseView {
12
+ view: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<import("react").RefAttributes<HTMLDivElement>>>;
13
+ protected classlist: string[];
14
+ protected options: CodeEditorViewOptions;
15
+ protected modalChangeEmitter: Emitter<any>;
16
+ get onModalChange(): import("@difizen/mana-app").Event<any>;
17
+ /**
18
+ * Get the editor wrapped by the widget.
19
+ */
20
+ editor: IEditor | undefined;
21
+ protected editorReadyDeferred: Deferred<void>;
22
+ get editorReady(): Promise<void>;
23
+ /**
24
+ * Construct a new code editor widget.
25
+ */
26
+ constructor(options: CodeEditorViewOptions);
27
+ onViewMount(): void;
28
+ onViewUnmount(): void;
29
+ /**
30
+ * Get the model used by the widget.
31
+ */
32
+ get model(): IModel | undefined;
33
+ /**
34
+ * Dispose of the resources held by the widget.
35
+ */
36
+ dispose(): void;
37
+ protected onViewActive: () => void;
38
+ /**
39
+ * A message handler invoked on a `'resize'` message.
40
+ */
41
+ protected onResize(): void;
42
+ addClass(classname: string): void;
43
+ removeClass(classname: string): void;
44
+ /**
45
+ * Handle a change in model selections.
46
+ */
47
+ protected _onSelectionsChanged(): void;
48
+ /**
49
+ * Handle the `'lm-dragenter'` event for the widget.
50
+ */
51
+ protected _evtDragEnter: (event: DragEvent) => void;
52
+ /**
53
+ * Handle the `'lm-dragleave'` event for the widget.
54
+ */
55
+ protected _evtDragLeave: (event: DragEvent) => void;
56
+ /**
57
+ * Handle the `'lm-dragover'` event for the widget.
58
+ */
59
+ protected _evtDragOver: (event: DragEvent) => void;
60
+ /**
61
+ * Handle the `'lm-drop'` event for the widget.
62
+ */
63
+ protected _evtDrop: (event: DragEvent) => void;
64
+ }
65
+ /**
66
+ * The namespace for the `CodeEditorWrapper` statics.
67
+ */
68
+ /**
69
+ * The options used to initialize a code editor widget.
70
+ */
71
+ export interface CodeEditorViewOptions {
72
+ /**
73
+ * A code editor factory.
74
+ *
75
+ * #### Notes
76
+ * The widget needs a factory and a model instead of a `CodeEditor.IEditor`
77
+ * object because it needs to provide its own node as the host.
78
+ */
79
+ factory: CodeEditorFactory;
80
+ /**
81
+ * The model used to initialize the code editor.
82
+ */
83
+ model: IModel;
84
+ /**
85
+ * The desired uuid for the editor.
86
+ */
87
+ uuid?: string;
88
+ /**
89
+ * The configuration options for the editor.
90
+ */
91
+ config?: Partial<IEditorConfig>;
92
+ /**
93
+ * The default selection style for the editor.
94
+ */
95
+ selectionStyle?: IEditorSelectionStyle;
96
+ tooltipProvider?: TooltipProvider;
97
+ completionProvider?: CompletionProvider;
98
+ lspProvider?: LSPProvider;
99
+ autoFocus?: boolean;
100
+ }
101
+ //# sourceMappingURL=code-editor-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-editor-view.d.ts","sourceRoot":"","sources":["../src/code-editor-view.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAoB,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EACV,iBAAiB,EAEjB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,eAAO,MAAM,gBAAgB,+HAI5B,CAAC;AAuBF;;GAEG;AACH,qBAEa,cAAe,SAAQ,QAAQ;IACjC,IAAI,gIAAoB;IAEjC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAEnC,SAAS,CAAC,OAAO,EAAE,qBAAqB,CAAC;IAEzC,SAAS,CAAC,kBAAkB,eAAiB;IAE7C,IAAI,aAAa,2CAEhB;IAED;;OAEG;IAEH,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,SAAS,CAAC,mBAAmB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IACrE,IAAI,WAAW,kBAEd;IACD;;OAEG;gBAC6B,OAAO,EAAE,qBAAqB;IAKrD,WAAW;IA6BX,aAAa;IAWtB;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED;;OAEG;IACM,OAAO,IAAI,IAAI;IAQxB,SAAS,CAAC,YAAY,QAAO,IAAI,CAE/B;IAEF;;OAEG;IACH,SAAS,CAAC,QAAQ,IAAI,IAAI;IAM1B,QAAQ,CAAC,SAAS,EAAE,MAAM;IAI1B,WAAW,CAAC,SAAS,EAAE,MAAM;IAO7B;;OAEG;IACH,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAwBtC;;OAEG;IACH,SAAS,CAAC,aAAa,UAAW,SAAS,KAAG,IAAI,CAchD;IAEF;;OAEG;IACH,SAAS,CAAC,aAAa,UAAW,SAAS,KAAG,IAAI,CAchD;IAEF;;OAEG;IACH,SAAS,CAAC,YAAY,UAAW,SAAS,KAAG,IAAI,CAgB/C;IAEF;;OAEG;IACH,SAAS,CAAC,QAAQ,UAAW,SAAS,KAAG,IAAI,CAkC3C;CACH;AAED;;GAEG;AACH;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,OAAO,EAAE,iBAAiB,CAAC;IAE3B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAEhC;;OAEG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;IAEvC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,339 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _dec2, _dec3, _class, _class2, _descriptor;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
10
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
11
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
12
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
13
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
15
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
16
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
17
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
19
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
20
+ import { getOrigin, prop } from '@difizen/mana-app';
21
+ import { BaseView, view, ViewOption } from '@difizen/mana-app';
22
+ import { inject, transient } from '@difizen/mana-app';
23
+ import { Deferred, Emitter } from '@difizen/mana-app';
24
+ import { forwardRef, memo } from 'react';
25
+ import { jsx as _jsx } from "react/jsx-runtime";
26
+ export var CodeEditorRender = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function (_props, ref) {
27
+ return /*#__PURE__*/_jsx("div", {
28
+ ref: ref
29
+ });
30
+ }));
31
+
32
+ /**
33
+ * The class name added to an editor widget that has a primary selection.
34
+ */
35
+ var HAS_SELECTION_CLASS = 'jp-mod-has-primary-selection';
36
+
37
+ /**
38
+ * The class name added to an editor widget that has a cursor/selection
39
+ * within the whitespace at the beginning of a line
40
+ */
41
+ var HAS_IN_LEADING_WHITESPACE_CLASS = 'jp-mod-in-leading-whitespace';
42
+
43
+ /**
44
+ * A class used to indicate a drop target.
45
+ */
46
+ var DROP_TARGET_CLASS = 'jp-mod-dropTarget';
47
+
48
+ /**
49
+ * RegExp to test for leading whitespace
50
+ */
51
+ var leadingWhitespaceRe = /^\s+$/;
52
+
53
+ /**
54
+ * A widget which hosts a code editor.
55
+ */
56
+ export var CodeEditorView = (_dec = transient(), _dec2 = view('code-editor-view'), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
57
+ _inherits(CodeEditorView, _BaseView);
58
+ var _super = _createSuper(CodeEditorView);
59
+ /**
60
+ * Construct a new code editor widget.
61
+ */
62
+ function CodeEditorView(options) {
63
+ var _this;
64
+ _classCallCheck(this, CodeEditorView);
65
+ _this = _super.call(this);
66
+ _this.view = CodeEditorRender;
67
+ _this.classlist = [];
68
+ _this.modalChangeEmitter = new Emitter();
69
+ /**
70
+ * Get the editor wrapped by the widget.
71
+ */
72
+ _initializerDefineProperty(_this, "editor", _descriptor, _assertThisInitialized(_this));
73
+ _this.editorReadyDeferred = new Deferred();
74
+ _this.onViewActive = function () {
75
+ var _this$editor;
76
+ (_this$editor = _this.editor) === null || _this$editor === void 0 ? void 0 : _this$editor.focus();
77
+ };
78
+ /**
79
+ * Handle the `'lm-dragenter'` event for the widget.
80
+ */
81
+ _this._evtDragEnter = function (event) {
82
+ if (!_this.editor) {
83
+ return;
84
+ }
85
+ if (_this.editor.getOption('readOnly') === true) {
86
+ return;
87
+ }
88
+ var data = findTextData(event);
89
+ if (data === undefined) {
90
+ return;
91
+ }
92
+ event.preventDefault();
93
+ event.stopPropagation();
94
+ _this.addClass('jp-mod-dropTarget');
95
+ };
96
+ /**
97
+ * Handle the `'lm-dragleave'` event for the widget.
98
+ */
99
+ _this._evtDragLeave = function (event) {
100
+ if (!_this.editor) {
101
+ return;
102
+ }
103
+ _this.removeClass(DROP_TARGET_CLASS);
104
+ if (_this.editor.getOption('readOnly') === true) {
105
+ return;
106
+ }
107
+ var data = findTextData(event);
108
+ if (data === undefined) {
109
+ return;
110
+ }
111
+ event.preventDefault();
112
+ event.stopPropagation();
113
+ };
114
+ /**
115
+ * Handle the `'lm-dragover'` event for the widget.
116
+ */
117
+ _this._evtDragOver = function (event) {
118
+ if (!_this.editor) {
119
+ return;
120
+ }
121
+ _this.removeClass(DROP_TARGET_CLASS);
122
+ if (_this.editor.getOption('readOnly') === true) {
123
+ return;
124
+ }
125
+ var data = findTextData(event);
126
+ if (data === undefined) {
127
+ return;
128
+ }
129
+ event.preventDefault();
130
+ event.stopPropagation();
131
+ event.dataTransfer.dropEffect = 'copy';
132
+ _this.addClass(DROP_TARGET_CLASS);
133
+ };
134
+ /**
135
+ * Handle the `'lm-drop'` event for the widget.
136
+ */
137
+ _this._evtDrop = function (event) {
138
+ if (!_this.editor) {
139
+ return;
140
+ }
141
+ if (_this.editor.getOption('readOnly') === true) {
142
+ return;
143
+ }
144
+ var data = findTextData(event);
145
+ if (data === undefined) {
146
+ return;
147
+ }
148
+ var coordinate = {
149
+ top: event.y,
150
+ bottom: event.y,
151
+ left: event.x,
152
+ right: event.x,
153
+ x: event.x,
154
+ y: event.y,
155
+ width: 0,
156
+ height: 0
157
+ };
158
+ var position = _this.editor.getPositionForCoordinate(coordinate);
159
+ if (position === null) {
160
+ return;
161
+ }
162
+ _this.removeClass(DROP_TARGET_CLASS);
163
+ event.preventDefault();
164
+ event.stopPropagation();
165
+ // if (event.proposedAction === 'none') {
166
+ // event.dropAction = 'none';
167
+ // return;
168
+ // }
169
+ // const offset = this.editor.getOffsetAt(position);
170
+ // this.model.value.insert(offset, data);
171
+ };
172
+ _this.options = options;
173
+ return _this;
174
+ }
175
+ CodeEditorView = inject(ViewOption)(CodeEditorView, undefined, 0) || CodeEditorView;
176
+ _createClass(CodeEditorView, [{
177
+ key: "onModalChange",
178
+ get: function get() {
179
+ return this.modalChangeEmitter.event;
180
+ }
181
+ }, {
182
+ key: "editorReady",
183
+ get: function get() {
184
+ return this.editorReadyDeferred.promise;
185
+ }
186
+ }, {
187
+ key: "onViewMount",
188
+ value: function onViewMount() {
189
+ var _this$container,
190
+ _this2 = this;
191
+ var node = (_this$container = this.container) === null || _this$container === void 0 ? void 0 : _this$container.current;
192
+ if (node) {
193
+ this.editor = this.options.factory({
194
+ host: node,
195
+ model: this.options.model,
196
+ uuid: this.options.uuid,
197
+ config: this.options.config,
198
+ selectionStyle: this.options.selectionStyle,
199
+ tooltipProvider: this.options.tooltipProvider,
200
+ completionProvider: this.options.completionProvider,
201
+ lspProvider: this.options.lspProvider
202
+ });
203
+ this.editorReadyDeferred.resolve();
204
+ this.editor.onModalChange(function (val) {
205
+ return _this2.modalChangeEmitter.fire(val);
206
+ });
207
+ // this.editor.model.selections.changed(this._onSelectionsChanged);
208
+
209
+ if (this.options.autoFocus) {
210
+ getOrigin(this.editor).focus();
211
+ }
212
+ node.addEventListener('focus', this.onViewActive);
213
+ node.addEventListener('dragenter', this._evtDragEnter);
214
+ node.addEventListener('dragleave', this._evtDragLeave);
215
+ node.addEventListener('dragover', this._evtDragOver);
216
+ node.addEventListener('drop', this._evtDrop);
217
+ }
218
+ }
219
+ }, {
220
+ key: "onViewUnmount",
221
+ value: function onViewUnmount() {
222
+ var _this$container2;
223
+ var node = (_this$container2 = this.container) === null || _this$container2 === void 0 ? void 0 : _this$container2.current;
224
+ if (node) {
225
+ node.removeEventListener('focus', this.onViewActive);
226
+ node.removeEventListener('dragenter', this._evtDragEnter);
227
+ node.removeEventListener('dragleave', this._evtDragLeave);
228
+ node.removeEventListener('dragover', this._evtDragOver);
229
+ node.removeEventListener('drop', this._evtDrop);
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Get the model used by the widget.
235
+ */
236
+ }, {
237
+ key: "model",
238
+ get: function get() {
239
+ var _this$editor2;
240
+ return (_this$editor2 = this.editor) === null || _this$editor2 === void 0 ? void 0 : _this$editor2.model;
241
+ }
242
+
243
+ /**
244
+ * Dispose of the resources held by the widget.
245
+ */
246
+ }, {
247
+ key: "dispose",
248
+ value: function dispose() {
249
+ var _this$editor3;
250
+ if (this.isDisposed) {
251
+ return;
252
+ }
253
+ _get(_getPrototypeOf(CodeEditorView.prototype), "dispose", this).call(this);
254
+ (_this$editor3 = this.editor) === null || _this$editor3 === void 0 ? void 0 : _this$editor3.dispose();
255
+ }
256
+ }, {
257
+ key: "onResize",
258
+ value:
259
+ /**
260
+ * A message handler invoked on a `'resize'` message.
261
+ */
262
+ function onResize() {
263
+ if (this.isVisible) {
264
+ var _this$editor4;
265
+ (_this$editor4 = this.editor) === null || _this$editor4 === void 0 ? void 0 : _this$editor4.resizeToFit();
266
+ }
267
+ }
268
+ }, {
269
+ key: "addClass",
270
+ value: function addClass(classname) {
271
+ this.classlist.push(classname);
272
+ }
273
+ }, {
274
+ key: "removeClass",
275
+ value: function removeClass(classname) {
276
+ var index = this.classlist.indexOf(classname);
277
+ if (index >= 0) {
278
+ this.classlist.splice(index, 1);
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Handle a change in model selections.
284
+ */
285
+ }, {
286
+ key: "_onSelectionsChanged",
287
+ value: function _onSelectionsChanged() {
288
+ if (!this.editor) {
289
+ return;
290
+ }
291
+ var _this$editor$getSelec = this.editor.getSelection(),
292
+ start = _this$editor$getSelec.start,
293
+ end = _this$editor$getSelec.end;
294
+ if (start.column !== end.column || start.line !== end.line) {
295
+ // a selection was made
296
+ this.addClass(HAS_SELECTION_CLASS);
297
+ this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
298
+ } else {
299
+ // the cursor was placed
300
+ this.removeClass(HAS_SELECTION_CLASS);
301
+ if (this.editor.getLine(end.line).slice(0, end.column).match(leadingWhitespaceRe)) {
302
+ this.addClass(HAS_IN_LEADING_WHITESPACE_CLASS);
303
+ } else {
304
+ this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
305
+ }
306
+ }
307
+ }
308
+ }]);
309
+ return CodeEditorView;
310
+ }(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "editor", [_dec3], {
311
+ configurable: true,
312
+ enumerable: true,
313
+ writable: true,
314
+ initializer: null
315
+ })), _class2)) || _class) || _class);
316
+
317
+ /**
318
+ * The namespace for the `CodeEditorWrapper` statics.
319
+ */
320
+ /**
321
+ * The options used to initialize a code editor widget.
322
+ */
323
+ /**
324
+ * Given a MimeData instance, extract the first text data, if any.
325
+ */
326
+ function findTextData(event) {
327
+ var _event$dataTransfer;
328
+ var items = (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.items;
329
+ if (!items) {
330
+ return;
331
+ }
332
+ var textTypeItem = Array.from(items).find(function (t) {
333
+ return t.type.indexOf('text') === 0;
334
+ });
335
+ if (textTypeItem === undefined) {
336
+ return undefined;
337
+ }
338
+ return event.dataTransfer.getData(textTypeItem.type);
339
+ }