@instructure/ui-source-code-editor 8.25.1-snapshot-19

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +48 -0
  3. package/es/SourceCodeEditor/SourceCodeEditorLocator.js +81 -0
  4. package/es/SourceCodeEditor/customKeybinding.js +96 -0
  5. package/es/SourceCodeEditor/index.js +587 -0
  6. package/es/SourceCodeEditor/props.js +55 -0
  7. package/es/SourceCodeEditor/styles.js +204 -0
  8. package/es/SourceCodeEditor/theme.js +52 -0
  9. package/es/index.js +24 -0
  10. package/lib/SourceCodeEditor/SourceCodeEditorLocator.js +92 -0
  11. package/lib/SourceCodeEditor/customKeybinding.js +104 -0
  12. package/lib/SourceCodeEditor/index.js +601 -0
  13. package/lib/SourceCodeEditor/props.js +67 -0
  14. package/lib/SourceCodeEditor/styles.js +213 -0
  15. package/lib/SourceCodeEditor/theme.js +60 -0
  16. package/lib/index.js +13 -0
  17. package/lib/package.json +1 -0
  18. package/package.json +68 -0
  19. package/src/SourceCodeEditor/README.md +794 -0
  20. package/src/SourceCodeEditor/SourceCodeEditorLocator.ts +56 -0
  21. package/src/SourceCodeEditor/customKeybinding.ts +121 -0
  22. package/src/SourceCodeEditor/index.tsx +659 -0
  23. package/src/SourceCodeEditor/props.ts +291 -0
  24. package/src/SourceCodeEditor/styles.ts +200 -0
  25. package/src/SourceCodeEditor/theme.ts +55 -0
  26. package/src/index.ts +25 -0
  27. package/tsconfig.build.json +25 -0
  28. package/tsconfig.build.tsbuildinfo +1 -0
  29. package/tsconfig.json +4 -0
  30. package/types/SourceCodeEditor/SourceCodeEditorLocator.d.ts +607 -0
  31. package/types/SourceCodeEditor/SourceCodeEditorLocator.d.ts.map +1 -0
  32. package/types/SourceCodeEditor/customKeybinding.d.ts +4 -0
  33. package/types/SourceCodeEditor/customKeybinding.d.ts.map +1 -0
  34. package/types/SourceCodeEditor/index.d.ts +126 -0
  35. package/types/SourceCodeEditor/index.d.ts.map +1 -0
  36. package/types/SourceCodeEditor/props.d.ts +130 -0
  37. package/types/SourceCodeEditor/props.d.ts.map +1 -0
  38. package/types/SourceCodeEditor/styles.d.ts +14 -0
  39. package/types/SourceCodeEditor/styles.d.ts.map +1 -0
  40. package/types/SourceCodeEditor/theme.d.ts +10 -0
  41. package/types/SourceCodeEditor/theme.d.ts.map +1 -0
  42. package/types/index.d.ts +3 -0
  43. package/types/index.d.ts.map +1 -0
@@ -0,0 +1,587 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["label", "styles"];
3
+
4
+ var _dec, _dec2, _dec3, _dec4, _class, _class2;
5
+
6
+ /*
7
+ * The MIT License (MIT)
8
+ *
9
+ * Copyright (c) 2015 - present Instructure, Inc.
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights
14
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ * copies of the Software, and to permit persons to whom the Software is
16
+ * furnished to do so, subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ * SOFTWARE.
28
+ */
29
+
30
+ /** @jsx jsx */
31
+ import { Component } from 'react';
32
+ import { merge, cloneDeep, isEqual } from 'lodash';
33
+ import { EditorState, StateEffect } from '@codemirror/state';
34
+ import { EditorView, highlightSpecialChars, highlightActiveLine, drawSelection, dropCursor, rectangularSelection, crosshairCursor, lineNumbers, highlightActiveLineGutter, keymap } from '@codemirror/view';
35
+ import { autocompletion, completionKeymap, closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
36
+ import { highlightSelectionMatches // Search feature is turned off for now, see note at keymaps
37
+ // searchKeymap
38
+ } from '@codemirror/search';
39
+ import { indentSelection, defaultKeymap, indentWithTab, history, historyKeymap } from '@codemirror/commands';
40
+ import { lintKeymap } from '@codemirror/lint';
41
+ import { indentOnInput, indentUnit, StreamLanguage, bracketMatching, foldGutter, foldKeymap, defaultHighlightStyle, syntaxHighlighting, HighlightStyle } from '@codemirror/language';
42
+ import { javascript } from '@codemirror/lang-javascript';
43
+ import { html } from '@codemirror/lang-html';
44
+ import { css } from '@codemirror/lang-css';
45
+ import { markdown } from '@codemirror/lang-markdown';
46
+ import { json } from '@codemirror/lang-json';
47
+ import { shell } from '@codemirror/legacy-modes/mode/shell';
48
+ import { yaml } from '@codemirror/legacy-modes/mode/yaml'; // import { oneDarkTheme, oneDarkHighlightStyle } from '@codemirror/theme-one-dark'
49
+
50
+ import { testable } from '@instructure/ui-testable';
51
+ import { omitProps, passthroughProps, withDeterministicId } from '@instructure/ui-react-utils';
52
+ import { requestAnimationFrame } from '@instructure/ui-dom-utils';
53
+ import { ScreenReaderContent } from '@instructure/ui-a11y-content';
54
+ import { textDirectionContextConsumer } from '@instructure/ui-i18n';
55
+ import { withStyle, jsx } from '@instructure/emotion';
56
+ import generateStyle from './styles';
57
+ import generateComponentTheme from './theme';
58
+ import { rtlHorizontalArrowKeymap } from './customKeybinding';
59
+ import { propTypes, allowedProps } from './props';
60
+
61
+ /**
62
+ ---
63
+ category: components
64
+ ---
65
+ @tsProps
66
+ **/
67
+ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = textDirectionContextConsumer(), _dec4 = testable(), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = (_class2 = class SourceCodeEditor extends Component {
68
+ addAnimationFrame(callback) {
69
+ if (typeof callback === 'function') {
70
+ this._raf.push(requestAnimationFrame(callback));
71
+ }
72
+ }
73
+
74
+ cancelAnimationFrames() {
75
+ this._raf.forEach(request => request.cancel());
76
+
77
+ this._raf = [];
78
+ }
79
+
80
+ focus() {
81
+ this.addAnimationFrame(() => {
82
+ var _this$_editorView;
83
+
84
+ (_this$_editorView = this._editorView) === null || _this$_editorView === void 0 ? void 0 : _this$_editorView.focus();
85
+ });
86
+ }
87
+
88
+ get hasFocus() {
89
+ var _this$_editorView2;
90
+
91
+ return (_this$_editorView2 = this._editorView) === null || _this$_editorView2 === void 0 ? void 0 : _this$_editorView2.hasFocus;
92
+ }
93
+
94
+ selectAll() {
95
+ if (this._editorView) {
96
+ this.addAnimationFrame(() => {
97
+ var _this$currentDocValue;
98
+
99
+ this.dispatchViewSelection({
100
+ anchor: 0,
101
+ head: (_this$currentDocValue = this.currentDocValue) === null || _this$currentDocValue === void 0 ? void 0 : _this$currentDocValue.length
102
+ });
103
+ });
104
+ }
105
+ }
106
+
107
+ deselectAll() {
108
+ if (this._editorView) {
109
+ this.addAnimationFrame(() => {
110
+ this.dispatchViewSelection({
111
+ anchor: 0,
112
+ head: 0
113
+ });
114
+ });
115
+ }
116
+ }
117
+
118
+ indentCurrentSelection() {
119
+ this.addAnimationFrame(() => {
120
+ if (this._editorView) {
121
+ indentSelection({
122
+ state: this._editorView.state,
123
+ dispatch: transaction => {
124
+ var _this$_editorView3;
125
+
126
+ (_this$_editorView3 = this._editorView) === null || _this$_editorView3 === void 0 ? void 0 : _this$_editorView3.update([transaction]);
127
+ }
128
+ });
129
+ }
130
+ });
131
+ }
132
+
133
+ indentAll() {
134
+ this.addAnimationFrame(() => {
135
+ this.selectAll();
136
+ this.indentCurrentSelection();
137
+ this.deselectAll();
138
+ });
139
+ } // Attach state effects
140
+
141
+
142
+ dispatchViewEffects(effects) {
143
+ if (!this._editorView || !effects) return;
144
+
145
+ this._editorView.dispatch({
146
+ effects
147
+ });
148
+ } // Dispatch changes to the document
149
+
150
+
151
+ dispatchViewChanges(_ref) {
152
+ let changes = _ref.changes,
153
+ selection = _ref.selection,
154
+ userEvent = _ref.userEvent;
155
+ if (!this._editorView || !changes) return;
156
+
157
+ this._editorView.dispatch({
158
+ changes,
159
+ ...(selection ? {
160
+ selection
161
+ } : void 0),
162
+ ...(userEvent ? {
163
+ userEvent
164
+ } : void 0)
165
+ });
166
+ } // Select a portion of the document
167
+
168
+
169
+ dispatchViewSelection(selection) {
170
+ if (!this._editorView || !selection) return;
171
+
172
+ this._editorView.dispatch({
173
+ selection
174
+ });
175
+ }
176
+
177
+ get currentDocValue() {
178
+ var _this$_editorView4;
179
+
180
+ return (_this$_editorView4 = this._editorView) === null || _this$_editorView4 === void 0 ? void 0 : _this$_editorView4.state.doc;
181
+ } // when value is passed, the editor should be controlled
182
+
183
+
184
+ get isControlled() {
185
+ return typeof this.props.value === 'string';
186
+ }
187
+
188
+ constructor(props) {
189
+ super(props);
190
+ this._id = void 0;
191
+ this.ref = null;
192
+ this._containerRef = void 0;
193
+ this._editorView = void 0;
194
+ this._raf = [];
195
+ this._newSelectionAfterValueChange = void 0;
196
+
197
+ this.handleRef = el => {
198
+ const elementRef = this.props.elementRef;
199
+ this.ref = el;
200
+
201
+ if (typeof elementRef === 'function') {
202
+ elementRef(el);
203
+ }
204
+ };
205
+
206
+ this.handleContainerRef = el => {
207
+ const containerRef = this.props.containerRef;
208
+ this._containerRef = el || void 0;
209
+
210
+ if (typeof containerRef === 'function') {
211
+ containerRef(el);
212
+ }
213
+ };
214
+
215
+ this._id = props.deterministicId();
216
+ }
217
+
218
+ componentDidMount() {
219
+ var _this$props$makeStyle, _this$props2;
220
+
221
+ const _this$props = this.props,
222
+ value = _this$props.value,
223
+ defaultValue = _this$props.defaultValue,
224
+ autofocus = _this$props.autofocus,
225
+ indentOnLoad = _this$props.indentOnLoad;
226
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
227
+ const state = EditorState.create({
228
+ doc: value || defaultValue,
229
+ extensions: this.extensions
230
+ });
231
+ this._editorView = new EditorView({
232
+ state,
233
+ parent: this._containerRef
234
+ });
235
+
236
+ if (autofocus) {
237
+ this.focus();
238
+ }
239
+
240
+ if (indentOnLoad) {
241
+ this.indentAll();
242
+ }
243
+ }
244
+
245
+ componentWillUnmount() {
246
+ this._editorView = void 0;
247
+ this.cancelAnimationFrames();
248
+ }
249
+
250
+ componentDidUpdate(prevProps) {
251
+ var _this$props$makeStyle2, _this$props3;
252
+
253
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
254
+
255
+ if (this._editorView) {
256
+ if (this.props.value !== prevProps.value) {
257
+ this.refreshEditorValue();
258
+ }
259
+
260
+ if (this.shouldUpdateExtensions(prevProps)) {
261
+ this.refreshExtensions();
262
+ }
263
+ }
264
+ }
265
+
266
+ shouldUpdateExtensions(prevProps) {
267
+ const propsToObserve = ['styles', // needed for theme update
268
+ 'themeOverride', 'language', 'readOnly', 'editable', 'lineNumbers', 'highlightActiveLineGutter', 'foldGutter', 'lineWrapping', 'autofocus', 'spellcheck', 'direction', 'dir', 'rtlMoveVisually', 'indentOnLoad', 'indentWithTab', 'indentUnit', 'highlightActiveLine', 'attachment'];
269
+
270
+ for (const prop of propsToObserve) {
271
+ if (!isEqual(this.props[prop], prevProps[prop])) {
272
+ return true;
273
+ }
274
+ }
275
+
276
+ return false;
277
+ }
278
+
279
+ get direction() {
280
+ // comes from the `direction` prop and
281
+ // falls back to the `dir` prop coming from the bidirectional decorator
282
+ return this.props.direction || this.props.dir;
283
+ }
284
+
285
+ get extensions() {
286
+ const extensions = [...this.baseExtensions, // our custom extensions
287
+ this.languageExtension, this.onChangeExtension, this.focusListenerExtension, this.announceLineNumberExtension];
288
+
289
+ if (this.themeExtension) {
290
+ extensions.push(this.themeExtension);
291
+ }
292
+
293
+ if (this.props.lineNumbers) {
294
+ extensions.push(lineNumbers());
295
+ }
296
+
297
+ if (this.props.highlightActiveLine) {
298
+ extensions.push(highlightActiveLine());
299
+ }
300
+
301
+ if (this.props.highlightActiveLineGutter) {
302
+ extensions.push(highlightActiveLineGutter());
303
+ }
304
+
305
+ if (this.props.foldGutter) {
306
+ extensions.push(foldGutter());
307
+ }
308
+
309
+ if (this.props.lineWrapping) {
310
+ extensions.push(EditorView.lineWrapping);
311
+ }
312
+
313
+ if (this.props.editable === false) {
314
+ extensions.push(EditorView.editable.of(false));
315
+ }
316
+
317
+ if (this.props.readOnly) {
318
+ extensions.push(EditorState.readOnly.of(true));
319
+ }
320
+
321
+ if (this.props.spellcheck) {
322
+ extensions.push(EditorView.contentAttributes.of({
323
+ spellcheck: 'true'
324
+ }));
325
+ }
326
+
327
+ if (this.direction) {
328
+ extensions.push(EditorView.contentAttributes.of({
329
+ dir: this.direction
330
+ }));
331
+ }
332
+
333
+ if (this.props.indentUnit) {
334
+ extensions.push(indentUnit.of(this.props.indentUnit));
335
+ }
336
+
337
+ return extensions;
338
+ }
339
+
340
+ get baseExtensions() {
341
+ return [// The extensions are based on codemirrors basic setup from 'codemirror'.
342
+ // It is recommended by CodeMirror, that if we want to configure
343
+ // our editor more precisely, we have to copy the source
344
+ // and adjust it as desired.
345
+ highlightSpecialChars(), history(), drawSelection(), dropCursor(), EditorState.allowMultipleSelections.of(true), syntaxHighlighting(defaultHighlightStyle, {
346
+ fallback: true
347
+ }), bracketMatching(), closeBrackets(), autocompletion(), rectangularSelection(), crosshairCursor(), highlightSelectionMatches(), indentOnInput(), keymap.of(this.keymaps)];
348
+ }
349
+
350
+ get keymaps() {
351
+ // TODO: if more keymaps are added, list them in the docs as well (#Command keybinding)
352
+ const keymaps = [...closeBracketsKeymap, ...this.commandKeybinding, ...historyKeymap, ...foldKeymap, ...completionKeymap, ...lintKeymap // TODO: style and include search & replace toolbar feature
353
+ // Note: the search & replace toolbar is not styled.
354
+ // If this feature is needed in the future, we need a decision about the styling.
355
+ // For now we turned the feature off, since RCE doesn't need it.
356
+ // ...searchKeymap
357
+ ];
358
+
359
+ if (this.props.indentWithTab) {
360
+ keymaps.push(indentWithTab);
361
+ }
362
+
363
+ return keymaps;
364
+ }
365
+
366
+ get commandKeybinding() {
367
+ const rtlMoveVisually = this.props.rtlMoveVisually;
368
+
369
+ if (this.direction === 'rtl' && !rtlMoveVisually) {
370
+ // we need to clone the original so that it doesn't get overridden
371
+ return merge(cloneDeep(defaultKeymap), rtlHorizontalArrowKeymap);
372
+ }
373
+
374
+ return defaultKeymap;
375
+ }
376
+
377
+ get themeExtension() {
378
+ const styles = this.props.styles;
379
+
380
+ if (!(styles !== null && styles !== void 0 && styles.theme) || !styles.highlightStyle) {
381
+ return;
382
+ }
383
+
384
+ const theme = EditorView.theme(styles === null || styles === void 0 ? void 0 : styles.theme);
385
+ const highlightStyle = syntaxHighlighting(HighlightStyle.define(styles === null || styles === void 0 ? void 0 : styles.highlightStyle)); // see notes in props.ts
386
+ // if (darkTheme) {
387
+ // theme = oneDarkTheme
388
+ // highlightStyle = syntaxHighlighting(oneDarkHighlightStyle)
389
+ // }
390
+
391
+ return [theme, highlightStyle];
392
+ }
393
+
394
+ get languageExtension() {
395
+ const language = this.props.language;
396
+
397
+ switch (language) {
398
+ case 'json':
399
+ return json();
400
+
401
+ case 'js':
402
+ case 'jsx':
403
+ case 'javascript':
404
+ return javascript({
405
+ jsx: true,
406
+ typescript: true
407
+ });
408
+
409
+ case 'html':
410
+ return html({
411
+ matchClosingTags: true,
412
+ autoCloseTags: true
413
+ });
414
+
415
+ case 'css':
416
+ return css();
417
+
418
+ case 'markdown':
419
+ return markdown();
420
+
421
+ case 'sh':
422
+ case 'shell':
423
+ case 'bash':
424
+ // ????
425
+ return StreamLanguage.define(shell);
426
+
427
+ case 'yml':
428
+ case 'yaml':
429
+ return StreamLanguage.define(yaml);
430
+
431
+ default:
432
+ return javascript({
433
+ jsx: true,
434
+ typescript: true
435
+ });
436
+ }
437
+ }
438
+
439
+ callOnChangeHandler(newValue) {
440
+ const _this$props4 = this.props,
441
+ onChange = _this$props4.onChange,
442
+ value = _this$props4.value;
443
+ this.addAnimationFrame(() => {
444
+ if (typeof onChange === 'function' && newValue !== value) {
445
+ onChange(newValue);
446
+ }
447
+ });
448
+ }
449
+
450
+ get onChangeExtension() {
451
+ return EditorState.changeFilter.of(transaction => {
452
+ if (!this._editorView) {
453
+ return false;
454
+ }
455
+
456
+ if (transaction.docChanged) {
457
+ const newDoc = transaction.newDoc.toString();
458
+
459
+ if (this.isControlled) {
460
+ // the value will be changed by the onChange handler,
461
+ // refreshEditorValue has to run first
462
+ if (newDoc !== this.props.value) {
463
+ this._newSelectionAfterValueChange = transaction.selection;
464
+ this.cancelAnimationFrames();
465
+ this.callOnChangeHandler(newDoc);
466
+ return false;
467
+ } else {
468
+ return true;
469
+ }
470
+ } else {
471
+ this.callOnChangeHandler(newDoc);
472
+ }
473
+ }
474
+
475
+ return true;
476
+ });
477
+ }
478
+
479
+ get focusListenerExtension() {
480
+ const _this$props5 = this.props,
481
+ onFocus = _this$props5.onFocus,
482
+ onBlur = _this$props5.onBlur;
483
+ return EditorView.updateListener.of(update => {
484
+ if (update.focusChanged && this._editorView) {
485
+ if (this.hasFocus) {
486
+ if (typeof onFocus === 'function') {
487
+ onFocus();
488
+ }
489
+ } else {
490
+ if (typeof onBlur === 'function') {
491
+ onBlur();
492
+ }
493
+ }
494
+ }
495
+ });
496
+ }
497
+
498
+ get announceLineNumberExtension() {
499
+ return EditorState.transactionExtender.of(tr => {
500
+ const selection = tr.selection;
501
+ const oldSelection = tr.startState.selection.main;
502
+
503
+ if (selection && selection.main.empty && oldSelection.empty) {
504
+ const oldLine = tr.startState.doc.lineAt(oldSelection.head);
505
+ const newLine = tr.newDoc.lineAt(selection.main.head);
506
+ if (oldLine.number != newLine.number) return {
507
+ effects: EditorView.announce.of(tr.startState.phrase('line ') + newLine.number + '.')
508
+ };
509
+ }
510
+
511
+ return null;
512
+ });
513
+ }
514
+
515
+ refreshExtensions() {
516
+ this.dispatchViewEffects(StateEffect.reconfigure.of(this.extensions));
517
+ }
518
+
519
+ refreshEditorValue() {
520
+ if (!this._editorView) return;
521
+ const value = this.props.value;
522
+
523
+ const currentValue = this._editorView.state.doc.toString();
524
+
525
+ if (value && currentValue !== value) {
526
+ let userEvent;
527
+ const lengthDiff = value.length - currentValue.length; // setting user events are needed for the autocomplete to work
528
+ // (only these 2 events, autocomplete doesn't work on paste, etc.)
529
+
530
+ if (lengthDiff === 1) {
531
+ userEvent = 'input.type';
532
+ } else if (lengthDiff === -1) {
533
+ userEvent = 'delete.backward';
534
+ }
535
+
536
+ this.dispatchViewChanges({
537
+ changes: {
538
+ from: 0,
539
+ to: currentValue.length,
540
+ insert: value || ''
541
+ },
542
+ selection: this._newSelectionAfterValueChange,
543
+ userEvent: userEvent
544
+ });
545
+ this._newSelectionAfterValueChange = void 0;
546
+ }
547
+
548
+ if (this.props.indentOnLoad) {
549
+ this.indentAll();
550
+ }
551
+ }
552
+
553
+ render() {
554
+ const _this$props6 = this.props,
555
+ label = _this$props6.label,
556
+ styles = _this$props6.styles,
557
+ restProps = _objectWithoutProperties(_this$props6, _excluded);
558
+
559
+ return jsx("div", Object.assign({
560
+ ref: this.handleRef,
561
+ css: styles === null || styles === void 0 ? void 0 : styles.codeEditor
562
+ }, passthroughProps(omitProps(restProps, SourceCodeEditor.allowedProps))), jsx("label", {
563
+ htmlFor: this._id
564
+ }, jsx(ScreenReaderContent, null, label), jsx("div", {
565
+ ref: this.handleContainerRef,
566
+ css: styles === null || styles === void 0 ? void 0 : styles.codeEditorContainer
567
+ })));
568
+ }
569
+
570
+ }, _class2.displayName = "SourceCodeEditor", _class2.componentId = 'SourceCodeEditor', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
571
+ language: 'jsx',
572
+ readOnly: false,
573
+ editable: true,
574
+ lineNumbers: false,
575
+ foldGutter: false,
576
+ highlightActiveLine: false,
577
+ highlightActiveLineGutter: false,
578
+ lineWrapping: false,
579
+ autofocus: false,
580
+ spellcheck: false,
581
+ rtlMoveVisually: true,
582
+ indentOnLoad: false,
583
+ indentWithTab: false,
584
+ defaultValue: ''
585
+ }, _class2)) || _class) || _class) || _class) || _class);
586
+ export default SourceCodeEditor;
587
+ export { SourceCodeEditor };
@@ -0,0 +1,55 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import PropTypes from 'prop-types';
25
+ import { controllable } from '@instructure/ui-prop-types';
26
+ const propTypes = {
27
+ label: PropTypes.string.isRequired,
28
+ language: PropTypes.oneOf(['sh', 'js', 'json', 'javascript', 'jsx', 'shell', 'css', 'html', 'markdown', 'yaml', 'yml', 'bash']),
29
+ readOnly: PropTypes.bool,
30
+ editable: PropTypes.bool,
31
+ lineNumbers: PropTypes.bool,
32
+ foldGutter: PropTypes.bool,
33
+ highlightActiveLineGutter: PropTypes.bool,
34
+ highlightActiveLine: PropTypes.bool,
35
+ lineWrapping: PropTypes.bool,
36
+ autofocus: PropTypes.bool,
37
+ spellcheck: PropTypes.bool,
38
+ direction: PropTypes.oneOf(['ltr', 'rtl']),
39
+ rtlMoveVisually: PropTypes.bool,
40
+ indentOnLoad: PropTypes.bool,
41
+ indentWithTab: PropTypes.bool,
42
+ indentUnit: PropTypes.string,
43
+ defaultValue: PropTypes.string,
44
+ value: controllable(PropTypes.string, 'onChange', 'defaultValue'),
45
+ onChange: PropTypes.func,
46
+ onFocus: PropTypes.func,
47
+ onBlur: PropTypes.func,
48
+ attachment: PropTypes.oneOf(['bottom', 'top']),
49
+ // darkTheme: PropTypes.bool,
50
+ elementRef: PropTypes.func,
51
+ containerRef: PropTypes.func
52
+ };
53
+ const allowedProps = ['label', 'language', 'readOnly', 'editable', 'lineNumbers', 'foldGutter', 'highlightActiveLineGutter', 'highlightActiveLine', 'lineWrapping', 'autofocus', 'spellcheck', 'direction', 'rtlMoveVisually', 'indentOnLoad', 'indentWithTab', 'indentUnit', 'defaultValue', 'value', 'onChange', 'onFocus', 'onBlur', 'attachment', // 'darkTheme',
54
+ 'elementRef', 'containerRef'];
55
+ export { propTypes, allowedProps };