@instructure/ui-source-code-editor 8.33.1 → 8.33.2-snapshot-5
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/CHANGELOG.md +8 -0
- package/es/SourceCodeEditor/SourceCodeEditorLocator.js +5 -10
- package/es/SourceCodeEditor/customKeybinding.js +7 -3
- package/es/SourceCodeEditor/index.js +42 -122
- package/es/SourceCodeEditor/props.js +3 -1
- package/es/SourceCodeEditor/styles.js +11 -7
- package/es/SourceCodeEditor/theme.js +5 -5
- package/lib/SourceCodeEditor/SourceCodeEditorLocator.js +3 -13
- package/lib/SourceCodeEditor/customKeybinding.js +7 -5
- package/lib/SourceCodeEditor/index.js +37 -153
- package/lib/SourceCodeEditor/props.js +3 -5
- package/lib/SourceCodeEditor/styles.js +10 -8
- package/lib/SourceCodeEditor/theme.js +5 -6
- package/lib/index.js +0 -1
- package/package.json +15 -15
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,74 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.SourceCodeEditor = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
-
|
|
12
9
|
var _react = require("react");
|
|
13
|
-
|
|
14
10
|
var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
|
|
15
|
-
|
|
16
11
|
var _state = require("@codemirror/state");
|
|
17
|
-
|
|
18
12
|
var _view = require("@codemirror/view");
|
|
19
|
-
|
|
20
13
|
var _autocomplete = require("@codemirror/autocomplete");
|
|
21
|
-
|
|
22
14
|
var _search = require("@codemirror/search");
|
|
23
|
-
|
|
24
15
|
var _commands = require("@codemirror/commands");
|
|
25
|
-
|
|
26
16
|
var _lint = require("@codemirror/lint");
|
|
27
|
-
|
|
28
17
|
var _language = require("@codemirror/language");
|
|
29
|
-
|
|
30
18
|
var _langJavascript = require("@codemirror/lang-javascript");
|
|
31
|
-
|
|
32
19
|
var _langHtml = require("@codemirror/lang-html");
|
|
33
|
-
|
|
34
20
|
var _langCss = require("@codemirror/lang-css");
|
|
35
|
-
|
|
36
21
|
var _langMarkdown = require("@codemirror/lang-markdown");
|
|
37
|
-
|
|
38
22
|
var _langJson = require("@codemirror/lang-json");
|
|
39
|
-
|
|
40
23
|
var _shell = require("@codemirror/legacy-modes/mode/shell");
|
|
41
|
-
|
|
42
24
|
var _yaml = require("@codemirror/legacy-modes/mode/yaml");
|
|
43
|
-
|
|
44
25
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
45
|
-
|
|
46
26
|
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
47
|
-
|
|
48
27
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
49
|
-
|
|
50
28
|
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
51
|
-
|
|
52
29
|
var _requestAnimationFrame = require("@instructure/ui-dom-utils/lib/requestAnimationFrame.js");
|
|
53
|
-
|
|
54
30
|
var _ScreenReaderContent = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
|
|
55
|
-
|
|
56
31
|
var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
|
|
57
|
-
|
|
58
32
|
var _emotion = require("@instructure/emotion");
|
|
59
|
-
|
|
60
33
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
61
|
-
|
|
62
34
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
63
|
-
|
|
64
35
|
var _customKeybinding = require("./customKeybinding");
|
|
65
|
-
|
|
66
36
|
var _props = require("./props");
|
|
67
|
-
|
|
68
37
|
const _excluded = ["label", "styles"];
|
|
69
|
-
|
|
70
38
|
var _dec, _dec2, _dec3, _dec4, _class, _class2;
|
|
71
|
-
|
|
72
39
|
/**
|
|
73
40
|
---
|
|
74
41
|
category: components
|
|
@@ -81,32 +48,24 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
81
48
|
this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(callback));
|
|
82
49
|
}
|
|
83
50
|
}
|
|
84
|
-
|
|
85
51
|
cancelAnimationFrames() {
|
|
86
52
|
this._raf.forEach(request => request.cancel());
|
|
87
|
-
|
|
88
53
|
this._raf = [];
|
|
89
54
|
}
|
|
90
|
-
|
|
91
55
|
focus() {
|
|
92
56
|
this.addAnimationFrame(() => {
|
|
93
57
|
var _this$_editorView;
|
|
94
|
-
|
|
95
58
|
(_this$_editorView = this._editorView) === null || _this$_editorView === void 0 ? void 0 : _this$_editorView.focus();
|
|
96
59
|
});
|
|
97
60
|
}
|
|
98
|
-
|
|
99
61
|
get hasFocus() {
|
|
100
62
|
var _this$_editorView2;
|
|
101
|
-
|
|
102
63
|
return (_this$_editorView2 = this._editorView) === null || _this$_editorView2 === void 0 ? void 0 : _this$_editorView2.hasFocus;
|
|
103
64
|
}
|
|
104
|
-
|
|
105
65
|
selectAll() {
|
|
106
66
|
if (this._editorView) {
|
|
107
67
|
this.addAnimationFrame(() => {
|
|
108
68
|
var _this$currentDocValue;
|
|
109
|
-
|
|
110
69
|
this.dispatchViewSelection({
|
|
111
70
|
anchor: 0,
|
|
112
71
|
head: (_this$currentDocValue = this.currentDocValue) === null || _this$currentDocValue === void 0 ? void 0 : _this$currentDocValue.length
|
|
@@ -114,7 +73,6 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
114
73
|
});
|
|
115
74
|
}
|
|
116
75
|
}
|
|
117
|
-
|
|
118
76
|
deselectAll() {
|
|
119
77
|
if (this._editorView) {
|
|
120
78
|
this.addAnimationFrame(() => {
|
|
@@ -125,7 +83,6 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
125
83
|
});
|
|
126
84
|
}
|
|
127
85
|
}
|
|
128
|
-
|
|
129
86
|
indentCurrentSelection() {
|
|
130
87
|
this.addAnimationFrame(() => {
|
|
131
88
|
if (this._editorView) {
|
|
@@ -133,14 +90,12 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
133
90
|
state: this._editorView.state,
|
|
134
91
|
dispatch: transaction => {
|
|
135
92
|
var _this$_editorView3;
|
|
136
|
-
|
|
137
93
|
(_this$_editorView3 = this._editorView) === null || _this$_editorView3 === void 0 ? void 0 : _this$_editorView3.update([transaction]);
|
|
138
94
|
}
|
|
139
95
|
});
|
|
140
96
|
}
|
|
141
97
|
});
|
|
142
98
|
}
|
|
143
|
-
|
|
144
99
|
indentAll() {
|
|
145
100
|
this.addAnimationFrame(() => {
|
|
146
101
|
if (this._editorView && this.currentDocValue) {
|
|
@@ -148,7 +103,6 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
148
103
|
}
|
|
149
104
|
});
|
|
150
105
|
}
|
|
151
|
-
|
|
152
106
|
indentCodeRange(from, to) {
|
|
153
107
|
this.addAnimationFrame(() => {
|
|
154
108
|
if (this._editorView && this.currentDocValue) {
|
|
@@ -157,24 +111,22 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
157
111
|
});
|
|
158
112
|
}
|
|
159
113
|
});
|
|
160
|
-
}
|
|
161
|
-
|
|
114
|
+
}
|
|
162
115
|
|
|
116
|
+
// Attach state effects
|
|
163
117
|
dispatchViewEffects(effects) {
|
|
164
118
|
if (!this._editorView || !effects) return;
|
|
165
|
-
|
|
166
119
|
this._editorView.dispatch({
|
|
167
120
|
effects
|
|
168
121
|
});
|
|
169
|
-
}
|
|
170
|
-
|
|
122
|
+
}
|
|
171
123
|
|
|
124
|
+
// Dispatch changes to the document
|
|
172
125
|
dispatchViewChanges(_ref) {
|
|
173
126
|
let changes = _ref.changes,
|
|
174
|
-
|
|
175
|
-
|
|
127
|
+
selection = _ref.selection,
|
|
128
|
+
userEvent = _ref.userEvent;
|
|
176
129
|
if (!this._editorView || !changes) return;
|
|
177
|
-
|
|
178
130
|
this._editorView.dispatch({
|
|
179
131
|
changes,
|
|
180
132
|
...(selection ? {
|
|
@@ -184,28 +136,24 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
184
136
|
userEvent
|
|
185
137
|
} : void 0)
|
|
186
138
|
});
|
|
187
|
-
}
|
|
188
|
-
|
|
139
|
+
}
|
|
189
140
|
|
|
141
|
+
// Select a portion of the document
|
|
190
142
|
dispatchViewSelection(selection) {
|
|
191
143
|
if (!this._editorView || !selection) return;
|
|
192
|
-
|
|
193
144
|
this._editorView.dispatch({
|
|
194
145
|
selection
|
|
195
146
|
});
|
|
196
147
|
}
|
|
197
|
-
|
|
198
148
|
get currentDocValue() {
|
|
199
149
|
var _this$_editorView4;
|
|
200
|
-
|
|
201
150
|
return (_this$_editorView4 = this._editorView) === null || _this$_editorView4 === void 0 ? void 0 : _this$_editorView4.state.doc;
|
|
202
|
-
}
|
|
203
|
-
|
|
151
|
+
}
|
|
204
152
|
|
|
153
|
+
// when value is passed, the editor should be controlled
|
|
205
154
|
get isControlled() {
|
|
206
155
|
return typeof this.props.value === 'string';
|
|
207
156
|
}
|
|
208
|
-
|
|
209
157
|
constructor(props) {
|
|
210
158
|
super(props);
|
|
211
159
|
this._id = void 0;
|
|
@@ -214,156 +162,124 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
214
162
|
this._editorView = void 0;
|
|
215
163
|
this._raf = [];
|
|
216
164
|
this._newSelectionAfterValueChange = void 0;
|
|
217
|
-
|
|
218
165
|
this.handleRef = el => {
|
|
219
166
|
const elementRef = this.props.elementRef;
|
|
220
167
|
this.ref = el;
|
|
221
|
-
|
|
222
168
|
if (typeof elementRef === 'function') {
|
|
223
169
|
elementRef(el);
|
|
224
170
|
}
|
|
225
171
|
};
|
|
226
|
-
|
|
227
172
|
this.handleContainerRef = el => {
|
|
228
173
|
const containerRef = this.props.containerRef;
|
|
229
174
|
this._containerRef = el || void 0;
|
|
230
|
-
|
|
231
175
|
if (typeof containerRef === 'function') {
|
|
232
176
|
containerRef(el);
|
|
233
177
|
}
|
|
234
178
|
};
|
|
235
|
-
|
|
236
179
|
this._id = props.deterministicId();
|
|
237
180
|
}
|
|
238
|
-
|
|
239
181
|
componentDidMount() {
|
|
240
182
|
var _this$props$makeStyle, _this$props2;
|
|
241
|
-
|
|
242
183
|
const _this$props = this.props,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
184
|
+
value = _this$props.value,
|
|
185
|
+
defaultValue = _this$props.defaultValue,
|
|
186
|
+
autofocus = _this$props.autofocus,
|
|
187
|
+
indentOnLoad = _this$props.indentOnLoad;
|
|
247
188
|
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
248
|
-
|
|
249
189
|
const state = _state.EditorState.create({
|
|
250
190
|
doc: value || defaultValue,
|
|
251
191
|
extensions: this.extensions
|
|
252
192
|
});
|
|
253
|
-
|
|
254
193
|
this._editorView = new _view.EditorView({
|
|
255
194
|
state,
|
|
256
195
|
parent: this._containerRef
|
|
257
196
|
});
|
|
258
|
-
|
|
259
197
|
if (autofocus) {
|
|
260
198
|
this.focus();
|
|
261
199
|
}
|
|
262
|
-
|
|
263
200
|
if (indentOnLoad) {
|
|
264
201
|
this.indentAll();
|
|
265
202
|
}
|
|
266
203
|
}
|
|
267
|
-
|
|
268
204
|
componentWillUnmount() {
|
|
269
205
|
var _this$_editorView5;
|
|
270
|
-
|
|
271
206
|
(_this$_editorView5 = this._editorView) === null || _this$_editorView5 === void 0 ? void 0 : _this$_editorView5.destroy();
|
|
272
207
|
this.cancelAnimationFrames();
|
|
273
208
|
}
|
|
274
|
-
|
|
275
209
|
componentDidUpdate(prevProps) {
|
|
276
210
|
var _this$props$makeStyle2, _this$props3;
|
|
277
|
-
|
|
278
211
|
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
279
|
-
|
|
280
212
|
if (this._editorView) {
|
|
281
213
|
if (this.props.value !== prevProps.value) {
|
|
282
214
|
this.refreshEditorValue();
|
|
283
215
|
}
|
|
284
|
-
|
|
285
216
|
if (this.shouldUpdateExtensions(prevProps)) {
|
|
286
217
|
this.refreshExtensions();
|
|
287
218
|
}
|
|
288
219
|
}
|
|
289
220
|
}
|
|
290
|
-
|
|
291
221
|
shouldUpdateExtensions(prevProps) {
|
|
292
|
-
const propsToObserve = ['styles',
|
|
222
|
+
const propsToObserve = ['styles',
|
|
223
|
+
// needed for theme update
|
|
293
224
|
'themeOverride', 'language', 'readOnly', 'editable', 'lineNumbers', 'highlightActiveLineGutter', 'foldGutter', 'lineWrapping', 'autofocus', 'spellcheck', 'direction', 'dir', 'rtlMoveVisually', 'indentOnLoad', 'indentWithTab', 'indentUnit', 'highlightActiveLine', 'attachment'];
|
|
294
|
-
|
|
295
225
|
for (const prop of propsToObserve) {
|
|
296
226
|
if (!(0, _deepEqual.deepEqual)(this.props[prop], prevProps[prop])) {
|
|
297
227
|
return true;
|
|
298
228
|
}
|
|
299
229
|
}
|
|
300
|
-
|
|
301
230
|
return false;
|
|
302
231
|
}
|
|
303
|
-
|
|
304
232
|
get direction() {
|
|
305
233
|
// comes from the `direction` prop and
|
|
306
234
|
// falls back to the `dir` prop coming from the bidirectional decorator
|
|
307
235
|
return this.props.direction || this.props.dir;
|
|
308
236
|
}
|
|
309
|
-
|
|
310
237
|
get extensions() {
|
|
311
|
-
const extensions = [...this.baseExtensions,
|
|
238
|
+
const extensions = [...this.baseExtensions,
|
|
239
|
+
// our custom extensions
|
|
312
240
|
this.languageExtension, this.onChangeExtension, this.focusListenerExtension, this.announceLineNumberExtension];
|
|
313
|
-
|
|
314
241
|
if (this.themeExtension) {
|
|
315
242
|
extensions.push(this.themeExtension);
|
|
316
243
|
}
|
|
317
|
-
|
|
318
244
|
if (this.props.lineNumbers) {
|
|
319
245
|
extensions.push((0, _view.lineNumbers)());
|
|
320
246
|
}
|
|
321
|
-
|
|
322
247
|
if (this.props.highlightActiveLine) {
|
|
323
248
|
extensions.push((0, _view.highlightActiveLine)());
|
|
324
249
|
}
|
|
325
|
-
|
|
326
250
|
if (this.props.highlightActiveLineGutter) {
|
|
327
251
|
extensions.push((0, _view.highlightActiveLineGutter)());
|
|
328
252
|
}
|
|
329
|
-
|
|
330
253
|
if (this.props.foldGutter) {
|
|
331
254
|
extensions.push((0, _language.foldGutter)());
|
|
332
255
|
}
|
|
333
|
-
|
|
334
256
|
if (this.props.lineWrapping) {
|
|
335
257
|
extensions.push(_view.EditorView.lineWrapping);
|
|
336
258
|
}
|
|
337
|
-
|
|
338
259
|
if (this.props.editable === false) {
|
|
339
260
|
extensions.push(_view.EditorView.editable.of(false));
|
|
340
261
|
}
|
|
341
|
-
|
|
342
262
|
if (this.props.readOnly) {
|
|
343
263
|
extensions.push(_state.EditorState.readOnly.of(true));
|
|
344
264
|
}
|
|
345
|
-
|
|
346
265
|
if (this.props.spellcheck) {
|
|
347
266
|
extensions.push(_view.EditorView.contentAttributes.of({
|
|
348
267
|
spellcheck: 'true'
|
|
349
268
|
}));
|
|
350
269
|
}
|
|
351
|
-
|
|
352
270
|
if (this.direction) {
|
|
353
271
|
extensions.push(_view.EditorView.contentAttributes.of({
|
|
354
272
|
dir: this.direction
|
|
355
273
|
}));
|
|
356
274
|
}
|
|
357
|
-
|
|
358
275
|
if (this.props.indentUnit) {
|
|
359
276
|
extensions.push(_language.indentUnit.of(this.props.indentUnit));
|
|
360
277
|
}
|
|
361
|
-
|
|
362
278
|
return extensions;
|
|
363
279
|
}
|
|
364
|
-
|
|
365
280
|
get baseExtensions() {
|
|
366
|
-
return [
|
|
281
|
+
return [
|
|
282
|
+
// The extensions are based on codemirrors basic setup from 'codemirror'.
|
|
367
283
|
// It is recommended by CodeMirror, that if we want to configure
|
|
368
284
|
// our editor more precisely, we have to copy the source
|
|
369
285
|
// and adjust it as desired.
|
|
@@ -371,10 +287,11 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
371
287
|
fallback: true
|
|
372
288
|
}), (0, _language.bracketMatching)(), (0, _autocomplete.closeBrackets)(), (0, _autocomplete.autocompletion)(), (0, _view.rectangularSelection)(), (0, _view.crosshairCursor)(), (0, _search.highlightSelectionMatches)(), (0, _language.indentOnInput)(), _view.keymap.of(this.keymaps)];
|
|
373
289
|
}
|
|
374
|
-
|
|
375
290
|
get keymaps() {
|
|
376
291
|
// TODO: if more keymaps are added, list them in the docs as well (#Command keybinding)
|
|
377
|
-
const keymaps = [..._autocomplete.closeBracketsKeymap, ...this.commandKeybinding, ..._commands.historyKeymap, ..._language.foldKeymap, ..._autocomplete.completionKeymap, ..._lint.lintKeymap
|
|
292
|
+
const keymaps = [..._autocomplete.closeBracketsKeymap, ...this.commandKeybinding, ..._commands.historyKeymap, ..._language.foldKeymap, ..._autocomplete.completionKeymap, ..._lint.lintKeymap
|
|
293
|
+
|
|
294
|
+
// TODO: style and include search & replace toolbar feature
|
|
378
295
|
// Note: the search & replace toolbar is not styled.
|
|
379
296
|
// If this feature is needed in the future, we need a decision about the styling.
|
|
380
297
|
// For now we turned the feature off, since RCE doesn't need it.
|
|
@@ -384,36 +301,28 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
384
301
|
if (this.props.indentWithTab) {
|
|
385
302
|
keymaps.push(_commands.indentWithTab);
|
|
386
303
|
}
|
|
387
|
-
|
|
388
304
|
return keymaps;
|
|
389
305
|
}
|
|
390
|
-
|
|
391
306
|
get commandKeybinding() {
|
|
392
307
|
const rtlMoveVisually = this.props.rtlMoveVisually;
|
|
393
|
-
|
|
394
308
|
if (this.direction === 'rtl' && !rtlMoveVisually) {
|
|
395
|
-
const overrideableKeys = _customKeybinding.rtlHorizontalArrowKeymap.map(binding => binding.key ? binding.key : binding.mac ? binding.mac : binding);
|
|
309
|
+
const overrideableKeys = _customKeybinding.rtlHorizontalArrowKeymap.map(binding => binding.key ? binding.key : binding.mac ? binding.mac : binding);
|
|
310
|
+
// we have to remove the binding we want to override from the original,
|
|
396
311
|
// otherwise all will be merged and the defaults will still apply
|
|
397
|
-
|
|
398
|
-
|
|
399
312
|
const filteredOriginal = _commands.defaultKeymap.filter(binding => binding.key ? overrideableKeys.indexOf(binding.key) < 0 : binding.mac ? overrideableKeys.indexOf(binding.mac) < 0 : false);
|
|
400
|
-
|
|
401
313
|
return [...filteredOriginal, ..._customKeybinding.rtlHorizontalArrowKeymap];
|
|
402
314
|
}
|
|
403
|
-
|
|
404
315
|
return _commands.defaultKeymap;
|
|
405
316
|
}
|
|
406
|
-
|
|
407
317
|
get themeExtension() {
|
|
408
318
|
const styles = this.props.styles;
|
|
409
|
-
|
|
410
319
|
if (!(styles !== null && styles !== void 0 && styles.theme) || !styles.highlightStyle) {
|
|
411
320
|
return;
|
|
412
321
|
}
|
|
413
|
-
|
|
414
322
|
const theme = _view.EditorView.theme(styles === null || styles === void 0 ? void 0 : styles.theme);
|
|
323
|
+
const highlightStyle = (0, _language.syntaxHighlighting)(_language.HighlightStyle.define(styles === null || styles === void 0 ? void 0 : styles.highlightStyle));
|
|
415
324
|
|
|
416
|
-
|
|
325
|
+
// see notes in props.ts
|
|
417
326
|
// if (darkTheme) {
|
|
418
327
|
// theme = oneDarkTheme
|
|
419
328
|
// highlightStyle = syntaxHighlighting(oneDarkHighlightStyle)
|
|
@@ -421,14 +330,11 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
421
330
|
|
|
422
331
|
return [theme, highlightStyle];
|
|
423
332
|
}
|
|
424
|
-
|
|
425
333
|
get languageExtension() {
|
|
426
334
|
const language = this.props.language;
|
|
427
|
-
|
|
428
335
|
switch (language) {
|
|
429
336
|
case 'json':
|
|
430
337
|
return (0, _langJson.json)();
|
|
431
|
-
|
|
432
338
|
case 'js':
|
|
433
339
|
case 'jsx':
|
|
434
340
|
case 'javascript':
|
|
@@ -436,29 +342,23 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
436
342
|
jsx: true,
|
|
437
343
|
typescript: true
|
|
438
344
|
});
|
|
439
|
-
|
|
440
345
|
case 'html':
|
|
441
346
|
return (0, _langHtml.html)({
|
|
442
347
|
matchClosingTags: true,
|
|
443
348
|
autoCloseTags: true
|
|
444
349
|
});
|
|
445
|
-
|
|
446
350
|
case 'css':
|
|
447
351
|
return (0, _langCss.css)();
|
|
448
|
-
|
|
449
352
|
case 'markdown':
|
|
450
353
|
return (0, _langMarkdown.markdown)();
|
|
451
|
-
|
|
452
354
|
case 'sh':
|
|
453
355
|
case 'shell':
|
|
454
356
|
case 'bash':
|
|
455
357
|
// ????
|
|
456
358
|
return _language.StreamLanguage.define(_shell.shell);
|
|
457
|
-
|
|
458
359
|
case 'yml':
|
|
459
360
|
case 'yaml':
|
|
460
361
|
return _language.StreamLanguage.define(_yaml.yaml);
|
|
461
|
-
|
|
462
362
|
default:
|
|
463
363
|
return (0, _langJavascript.javascript)({
|
|
464
364
|
jsx: true,
|
|
@@ -466,27 +366,23 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
466
366
|
});
|
|
467
367
|
}
|
|
468
368
|
}
|
|
469
|
-
|
|
470
369
|
callOnChangeHandler(newValue) {
|
|
471
370
|
const _this$props4 = this.props,
|
|
472
|
-
|
|
473
|
-
|
|
371
|
+
onChange = _this$props4.onChange,
|
|
372
|
+
value = _this$props4.value;
|
|
474
373
|
this.addAnimationFrame(() => {
|
|
475
374
|
if (typeof onChange === 'function' && newValue !== value) {
|
|
476
375
|
onChange(newValue);
|
|
477
376
|
}
|
|
478
377
|
});
|
|
479
378
|
}
|
|
480
|
-
|
|
481
379
|
get onChangeExtension() {
|
|
482
380
|
return _state.EditorState.changeFilter.of(transaction => {
|
|
483
381
|
if (!this._editorView) {
|
|
484
382
|
return false;
|
|
485
383
|
}
|
|
486
|
-
|
|
487
384
|
if (transaction.docChanged) {
|
|
488
385
|
const newDoc = transaction.newDoc.toString();
|
|
489
|
-
|
|
490
386
|
if (this.isControlled) {
|
|
491
387
|
// the value will be changed by the onChange handler,
|
|
492
388
|
// refreshEditorValue has to run first
|
|
@@ -502,15 +398,13 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
502
398
|
this.callOnChangeHandler(newDoc);
|
|
503
399
|
}
|
|
504
400
|
}
|
|
505
|
-
|
|
506
401
|
return true;
|
|
507
402
|
});
|
|
508
403
|
}
|
|
509
|
-
|
|
510
404
|
get focusListenerExtension() {
|
|
511
405
|
const _this$props5 = this.props,
|
|
512
|
-
|
|
513
|
-
|
|
406
|
+
onFocus = _this$props5.onFocus,
|
|
407
|
+
onBlur = _this$props5.onBlur;
|
|
514
408
|
return _view.EditorView.updateListener.of(update => {
|
|
515
409
|
if (update.focusChanged && this._editorView) {
|
|
516
410
|
if (this.hasFocus) {
|
|
@@ -525,12 +419,10 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
525
419
|
}
|
|
526
420
|
});
|
|
527
421
|
}
|
|
528
|
-
|
|
529
422
|
get announceLineNumberExtension() {
|
|
530
423
|
return _state.EditorState.transactionExtender.of(tr => {
|
|
531
424
|
const selection = tr.selection;
|
|
532
425
|
const oldSelection = tr.startState.selection.main;
|
|
533
|
-
|
|
534
426
|
if (selection && selection.main.empty && oldSelection.empty) {
|
|
535
427
|
const oldLine = tr.startState.doc.lineAt(oldSelection.head);
|
|
536
428
|
const newLine = tr.newDoc.lineAt(selection.main.head);
|
|
@@ -538,32 +430,27 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
538
430
|
effects: _view.EditorView.announce.of(tr.startState.phrase('line ') + newLine.number + '.')
|
|
539
431
|
};
|
|
540
432
|
}
|
|
541
|
-
|
|
542
433
|
return null;
|
|
543
434
|
});
|
|
544
435
|
}
|
|
545
|
-
|
|
546
436
|
refreshExtensions() {
|
|
547
437
|
this.dispatchViewEffects(_state.StateEffect.reconfigure.of(this.extensions));
|
|
548
438
|
}
|
|
549
|
-
|
|
550
439
|
refreshEditorValue() {
|
|
551
440
|
if (!this._editorView) return;
|
|
552
441
|
const value = this.props.value;
|
|
553
|
-
|
|
554
442
|
const currentValue = this._editorView.state.doc.toString();
|
|
555
|
-
|
|
556
443
|
if (value && currentValue !== value) {
|
|
557
444
|
let userEvent;
|
|
558
|
-
const lengthDiff = value.length - currentValue.length;
|
|
559
|
-
// (only these 2 events, autocomplete doesn't work on paste, etc.)
|
|
445
|
+
const lengthDiff = value.length - currentValue.length;
|
|
560
446
|
|
|
447
|
+
// setting user events are needed for the autocomplete to work
|
|
448
|
+
// (only these 2 events, autocomplete doesn't work on paste, etc.)
|
|
561
449
|
if (lengthDiff === 1) {
|
|
562
450
|
userEvent = 'input.type';
|
|
563
451
|
} else if (lengthDiff === -1) {
|
|
564
452
|
userEvent = 'delete.backward';
|
|
565
453
|
}
|
|
566
|
-
|
|
567
454
|
this.dispatchViewChanges({
|
|
568
455
|
changes: {
|
|
569
456
|
from: 0,
|
|
@@ -575,17 +462,15 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
575
462
|
});
|
|
576
463
|
this._newSelectionAfterValueChange = void 0;
|
|
577
464
|
}
|
|
578
|
-
|
|
579
465
|
if (this.props.indentOnLoad) {
|
|
580
466
|
this.indentAll();
|
|
581
467
|
}
|
|
582
468
|
}
|
|
583
|
-
|
|
584
469
|
render() {
|
|
585
470
|
const _this$props6 = this.props,
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
471
|
+
label = _this$props6.label,
|
|
472
|
+
styles = _this$props6.styles,
|
|
473
|
+
restProps = (0, _objectWithoutProperties2.default)(_this$props6, _excluded);
|
|
589
474
|
return (0, _emotion.jsx)("div", Object.assign({
|
|
590
475
|
ref: this.handleRef,
|
|
591
476
|
css: styles === null || styles === void 0 ? void 0 : styles.codeEditor
|
|
@@ -596,7 +481,6 @@ let SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(),
|
|
|
596
481
|
css: styles === null || styles === void 0 ? void 0 : styles.codeEditorContainer
|
|
597
482
|
})));
|
|
598
483
|
}
|
|
599
|
-
|
|
600
484
|
}, _class2.displayName = "SourceCodeEditor", _class2.componentId = 'SourceCodeEditor', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
|
|
601
485
|
language: 'jsx',
|
|
602
486
|
readOnly: false,
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.propTypes = exports.allowedProps = void 0;
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
|
|
13
|
-
|
|
14
10
|
/*
|
|
15
11
|
* The MIT License (MIT)
|
|
16
12
|
*
|
|
@@ -34,6 +30,7 @@ var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
|
|
|
34
30
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
31
|
* SOFTWARE.
|
|
36
32
|
*/
|
|
33
|
+
|
|
37
34
|
const propTypes = {
|
|
38
35
|
label: _propTypes.default.string.isRequired,
|
|
39
36
|
language: _propTypes.default.oneOf(['sh', 'js', 'json', 'javascript', 'jsx', 'shell', 'css', 'html', 'markdown', 'yaml', 'yml', 'bash']),
|
|
@@ -62,6 +59,7 @@ const propTypes = {
|
|
|
62
59
|
containerRef: _propTypes.default.func
|
|
63
60
|
};
|
|
64
61
|
exports.propTypes = propTypes;
|
|
65
|
-
const allowedProps = ['label', 'language', 'readOnly', 'editable', 'lineNumbers', 'foldGutter', 'highlightActiveLineGutter', 'highlightActiveLine', 'lineWrapping', 'autofocus', 'spellcheck', 'direction', 'rtlMoveVisually', 'indentOnLoad', 'indentWithTab', 'indentUnit', 'defaultValue', 'value', 'onChange', 'onFocus', 'onBlur', 'attachment',
|
|
62
|
+
const allowedProps = ['label', 'language', 'readOnly', 'editable', 'lineNumbers', 'foldGutter', 'highlightActiveLineGutter', 'highlightActiveLine', 'lineWrapping', 'autofocus', 'spellcheck', 'direction', 'rtlMoveVisually', 'indentOnLoad', 'indentWithTab', 'indentUnit', 'defaultValue', 'value', 'onChange', 'onFocus', 'onBlur', 'attachment',
|
|
63
|
+
// 'darkTheme',
|
|
66
64
|
'elementRef', 'containerRef'];
|
|
67
65
|
exports.allowedProps = allowedProps;
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _highlight = require("@lezer/highlight");
|
|
9
|
-
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -75,7 +73,8 @@ const generateStyle = (componentTheme, props) => {
|
|
|
75
73
|
borderWidth: componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderWidth,
|
|
76
74
|
borderRadius: componentTheme.borderRadius,
|
|
77
75
|
marginBottom: '1rem',
|
|
78
|
-
...(attachment && {
|
|
76
|
+
...(attachment && {
|
|
77
|
+
...attachmentVariants[attachment],
|
|
79
78
|
...attachmentBorderRadius[attachment]
|
|
80
79
|
})
|
|
81
80
|
},
|
|
@@ -91,7 +90,8 @@ const generateStyle = (componentTheme, props) => {
|
|
|
91
90
|
lineHeight: 1.4375,
|
|
92
91
|
minHeight: '1.4375rem',
|
|
93
92
|
borderRadius: componentTheme.borderRadius,
|
|
94
|
-
...(attachment && {
|
|
93
|
+
...(attachment && {
|
|
94
|
+
...attachmentBorderRadius[attachment]
|
|
95
95
|
})
|
|
96
96
|
},
|
|
97
97
|
'&.cm-editor.cm-focused': {
|
|
@@ -163,7 +163,8 @@ const generateStyle = (componentTheme, props) => {
|
|
|
163
163
|
}, {
|
|
164
164
|
tag: [_highlight.tags.string, _highlight.tags.deleted],
|
|
165
165
|
color: '#a11'
|
|
166
|
-
},
|
|
166
|
+
},
|
|
167
|
+
// {
|
|
167
168
|
// tag: [tags.regexp, tags.escape, tags.special(tags.string)],
|
|
168
169
|
// color: '#e40'
|
|
169
170
|
// },
|
|
@@ -173,7 +174,8 @@ const generateStyle = (componentTheme, props) => {
|
|
|
173
174
|
}, {
|
|
174
175
|
tag: _highlight.tags.local(_highlight.tags.variableName),
|
|
175
176
|
color: '#30a'
|
|
176
|
-
},
|
|
177
|
+
},
|
|
178
|
+
// { tag: [tags.typeName, tags.namespace], color: '#085' },
|
|
177
179
|
{
|
|
178
180
|
tag: _highlight.tags.className,
|
|
179
181
|
color: '#167'
|
|
@@ -186,7 +188,8 @@ const generateStyle = (componentTheme, props) => {
|
|
|
186
188
|
}, {
|
|
187
189
|
tag: _highlight.tags.comment,
|
|
188
190
|
color: '#940'
|
|
189
|
-
},
|
|
191
|
+
},
|
|
192
|
+
// { tag: tags.invalid, color: '#f00' },
|
|
190
193
|
|
|
191
194
|
/**
|
|
192
195
|
* Custom highlighting overrides
|
|
@@ -208,6 +211,5 @@ const generateStyle = (componentTheme, props) => {
|
|
|
208
211
|
}]
|
|
209
212
|
};
|
|
210
213
|
};
|
|
211
|
-
|
|
212
214
|
var _default = generateStyle;
|
|
213
215
|
exports.default = _default;
|