@instructure/ui-source-code-editor 11.6.0 → 11.6.1-snapshot-129

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