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