@instructure/ui-source-code-editor 11.7.3-snapshot-25 → 11.7.3-snapshot-27

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.
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.SourceCodeEditor = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
8
  var _react = require("react");
10
9
  var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
11
10
  var _state = require("@codemirror/state");
@@ -34,8 +33,7 @@ var _styles = _interopRequireDefault(require("./styles"));
34
33
  var _customKeybinding = require("./customKeybinding");
35
34
  var _props = require("./props");
36
35
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
37
- const _excluded = ["label", "styles"];
38
- var _dec, _dec2, _dec3, _class, _SourceCodeEditor;
36
+ var _dec, _dec2, _dec3, _class;
39
37
  /*
40
38
  * The MIT License (MIT)
41
39
  *
@@ -65,7 +63,51 @@ var _dec, _dec2, _dec3, _class, _SourceCodeEditor;
65
63
  category: components
66
64
  ---
67
65
  **/
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 {
66
+ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec3 = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec(_class = _dec2(_class = _dec3(_class = class SourceCodeEditor extends _react.Component {
67
+ static displayName = "SourceCodeEditor";
68
+ static componentId = 'SourceCodeEditor';
69
+ static allowedProps = _props.allowedProps;
70
+ static defaultProps = {
71
+ language: 'jsx',
72
+ readOnly: false,
73
+ editable: true,
74
+ lineNumbers: false,
75
+ foldGutter: false,
76
+ highlightActiveLine: false,
77
+ highlightActiveLineGutter: false,
78
+ lineWrapping: false,
79
+ autofocus: false,
80
+ spellcheck: false,
81
+ rtlMoveVisually: true,
82
+ indentOnLoad: false,
83
+ indentWithTab: false,
84
+ defaultValue: '',
85
+ height: 'auto'
86
+ };
87
+ _id;
88
+ ref = null;
89
+ _containerRef;
90
+ _editorView;
91
+ _raf = [];
92
+ _newSelectionAfterValueChange;
93
+ handleRef = el => {
94
+ const {
95
+ elementRef
96
+ } = this.props;
97
+ this.ref = el;
98
+ if (typeof elementRef === 'function') {
99
+ elementRef(el);
100
+ }
101
+ };
102
+ handleContainerRef = el => {
103
+ const {
104
+ containerRef
105
+ } = this.props;
106
+ this._containerRef = el || undefined;
107
+ if (typeof containerRef === 'function') {
108
+ containerRef(el);
109
+ }
110
+ };
69
111
  addAnimationFrame(callback) {
70
112
  if (typeof callback === 'function') {
71
113
  this._raf.push((0, _requestAnimationFrame.requestAnimationFrame)(callback));
@@ -77,21 +119,18 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
77
119
  }
78
120
  focus() {
79
121
  this.addAnimationFrame(() => {
80
- var _this$_editorView;
81
- (_this$_editorView = this._editorView) === null || _this$_editorView === void 0 ? void 0 : _this$_editorView.focus();
122
+ this._editorView?.focus();
82
123
  });
83
124
  }
84
125
  get hasFocus() {
85
- var _this$_editorView2;
86
- return (_this$_editorView2 = this._editorView) === null || _this$_editorView2 === void 0 ? void 0 : _this$_editorView2.hasFocus;
126
+ return this._editorView?.hasFocus;
87
127
  }
88
128
  selectAll() {
89
129
  if (this._editorView) {
90
130
  this.addAnimationFrame(() => {
91
- var _this$currentDocValue;
92
131
  this.dispatchViewSelection({
93
132
  anchor: 0,
94
- head: (_this$currentDocValue = this.currentDocValue) === null || _this$currentDocValue === void 0 ? void 0 : _this$currentDocValue.length
133
+ head: this.currentDocValue?.length
95
134
  });
96
135
  });
97
136
  }
@@ -112,8 +151,7 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
112
151
  (0, _commands.indentSelection)({
113
152
  state: this._editorView.state,
114
153
  dispatch: transaction => {
115
- var _this$_editorView3;
116
- (_this$_editorView3 = this._editorView) === null || _this$_editorView3 === void 0 ? void 0 : _this$_editorView3.update([transaction]);
154
+ this._editorView?.update([transaction]);
117
155
  }
118
156
  });
119
157
  }
@@ -155,10 +193,10 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
155
193
  changes,
156
194
  ...(selection ? {
157
195
  selection
158
- } : void 0),
196
+ } : undefined),
159
197
  ...(userEvent ? {
160
198
  userEvent
161
- } : void 0)
199
+ } : undefined)
162
200
  });
163
201
  }
164
202
 
@@ -170,8 +208,7 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
170
208
  });
171
209
  }
172
210
  get currentDocValue() {
173
- var _this$_editorView4;
174
- return (_this$_editorView4 = this._editorView) === null || _this$_editorView4 === void 0 ? void 0 : _this$_editorView4.state.doc;
211
+ return this._editorView?.state.doc;
175
212
  }
176
213
 
177
214
  // when value is passed, the editor should be controlled
@@ -180,44 +217,16 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
180
217
  }
181
218
  constructor(props) {
182
219
  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
220
  this._id = props.deterministicId();
212
221
  }
213
222
  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);
223
+ const {
224
+ value,
225
+ defaultValue,
226
+ autofocus,
227
+ indentOnLoad
228
+ } = this.props;
229
+ this.props.makeStyles?.();
221
230
  const state = _state.EditorState.create({
222
231
  doc: value || defaultValue,
223
232
  extensions: this.extensions
@@ -243,13 +252,11 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
243
252
  this.assignAriaLabel();
244
253
  }
245
254
  componentWillUnmount() {
246
- var _this$_editorView5;
247
- (_this$_editorView5 = this._editorView) === null || _this$_editorView5 === void 0 ? void 0 : _this$_editorView5.destroy();
255
+ this._editorView?.destroy();
248
256
  this.cancelAnimationFrames();
249
257
  }
250
258
  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);
259
+ this.props.makeStyles?.();
253
260
  if (this._editorView) {
254
261
  if (this.props.value !== prevProps.value) {
255
262
  this.refreshEditorValue();
@@ -337,7 +344,9 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
337
344
  return keymaps;
338
345
  }
339
346
  get commandKeybinding() {
340
- const rtlMoveVisually = this.props.rtlMoveVisually;
347
+ const {
348
+ rtlMoveVisually
349
+ } = this.props;
341
350
  if (this.direction === 'rtl' && !rtlMoveVisually) {
342
351
  const overrideableKeys = _customKeybinding.rtlHorizontalArrowKeymap.map(binding => binding.key ? binding.key : binding.mac ? binding.mac : binding);
343
352
  // we have to remove the binding we want to override from the original,
@@ -348,12 +357,14 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
348
357
  return _commands.defaultKeymap;
349
358
  }
350
359
  get themeExtension() {
351
- const styles = this.props.styles;
352
- if (!(styles !== null && styles !== void 0 && styles.theme) || !styles.highlightStyle) {
353
- return void 0;
360
+ const {
361
+ styles
362
+ } = this.props;
363
+ if (!styles?.theme || !styles.highlightStyle) {
364
+ return undefined;
354
365
  }
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));
366
+ const theme = _view.EditorView.theme(styles?.theme);
367
+ const highlightStyle = (0, _language.syntaxHighlighting)(_language.HighlightStyle.define(styles?.highlightStyle));
357
368
 
358
369
  // see notes in props.ts
359
370
  // if (darkTheme) {
@@ -364,7 +375,9 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
364
375
  return [theme, highlightStyle];
365
376
  }
366
377
  get languageExtension() {
367
- const language = this.props.language;
378
+ const {
379
+ language
380
+ } = this.props;
368
381
  switch (language) {
369
382
  case 'json':
370
383
  return (0, _langJson.json)();
@@ -400,9 +413,10 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
400
413
  }
401
414
  }
402
415
  callOnChangeHandler(newValue) {
403
- const _this$props4 = this.props,
404
- onChange = _this$props4.onChange,
405
- value = _this$props4.value;
416
+ const {
417
+ onChange,
418
+ value
419
+ } = this.props;
406
420
  this.addAnimationFrame(() => {
407
421
  if (typeof onChange === 'function' && newValue !== value) {
408
422
  onChange(newValue);
@@ -435,9 +449,10 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
435
449
  });
436
450
  }
437
451
  get focusListenerExtension() {
438
- const _this$props5 = this.props,
439
- onFocus = _this$props5.onFocus,
440
- onBlur = _this$props5.onBlur;
452
+ const {
453
+ onFocus,
454
+ onBlur
455
+ } = this.props;
441
456
  return _view.EditorView.updateListener.of(update => {
442
457
  if (update.focusChanged && this._editorView) {
443
458
  if (this.hasFocus) {
@@ -471,7 +486,9 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
471
486
  }
472
487
  refreshEditorValue() {
473
488
  if (!this._editorView) return;
474
- const value = this.props.value;
489
+ const {
490
+ value
491
+ } = this.props;
475
492
  const currentValue = this._editorView.state.doc.toString();
476
493
  if (typeof value !== 'undefined' && currentValue !== value) {
477
494
  let userEvent;
@@ -501,49 +518,42 @@ let SourceCodeEditor = exports.SourceCodeEditor = (_dec = (0, _withDeterministic
501
518
  this._editorView.scrollDOM.scrollTop = scrollTop;
502
519
  }
503
520
  });
504
- this._newSelectionAfterValueChange = void 0;
521
+ this._newSelectionAfterValueChange = undefined;
505
522
  }
506
523
  if (this.props.indentOnLoad) {
507
524
  this.indentAll();
508
525
  }
509
526
  }
527
+ assignAriaLabel = () => {
528
+ if (this._containerRef) {
529
+ const editorDiv = this._containerRef.querySelector('[role="textbox"]');
530
+ if (editorDiv) {
531
+ editorDiv.setAttribute('aria-labelledby', `${this._id}`);
532
+ }
533
+ }
534
+ };
510
535
  render() {
511
- const _this$props6 = this.props,
512
- label = _this$props6.label,
513
- styles = _this$props6.styles,
514
- restProps = (0, _objectWithoutProperties2.default)(_this$props6, _excluded);
536
+ const {
537
+ label,
538
+ styles,
539
+ ...restProps
540
+ } = this.props;
515
541
  return (0, _jsxRuntime.jsx)("div", {
516
542
  "data-cid": "SourceCodeEditor",
517
543
  ref: this.handleRef,
518
- css: styles === null || styles === void 0 ? void 0 : styles.codeEditor,
544
+ css: styles?.codeEditor,
519
545
  ...(0, _passthroughProps.passthroughProps)((0, _omitProps.omitProps)(restProps, SourceCodeEditor.allowedProps)),
520
546
  children: (0, _jsxRuntime.jsxs)("label", {
521
- css: styles === null || styles === void 0 ? void 0 : styles.label,
547
+ css: styles?.label,
522
548
  id: this._id,
523
549
  children: [(0, _jsxRuntime.jsx)(_ScreenReaderContent.ScreenReaderContent, {
524
550
  children: label
525
551
  }), (0, _jsxRuntime.jsx)("div", {
526
552
  ref: this.handleContainerRef,
527
- css: styles === null || styles === void 0 ? void 0 : styles.codeEditorContainer
553
+ css: styles?.codeEditorContainer
528
554
  })]
529
555
  })
530
556
  });
531
557
  }
532
- }, _SourceCodeEditor.displayName = "SourceCodeEditor", _SourceCodeEditor.componentId = 'SourceCodeEditor', _SourceCodeEditor.allowedProps = _props.allowedProps, _SourceCodeEditor.defaultProps = {
533
- language: 'jsx',
534
- readOnly: false,
535
- editable: true,
536
- lineNumbers: false,
537
- foldGutter: false,
538
- highlightActiveLine: false,
539
- highlightActiveLineGutter: false,
540
- lineWrapping: false,
541
- autofocus: false,
542
- spellcheck: false,
543
- rtlMoveVisually: true,
544
- indentOnLoad: false,
545
- indentWithTab: false,
546
- defaultValue: '',
547
- height: 'auto'
548
- }, _SourceCodeEditor)) || _class) || _class) || _class);
558
+ }) || _class) || _class) || _class);
549
559
  var _default = exports.default = SourceCodeEditor;
@@ -39,9 +39,11 @@ var _highlight = require("@lezer/highlight");
39
39
  * @return {Object} The final style object, which will be used in the component
40
40
  */
41
41
  const generateStyle = (componentTheme, props, sharedTokens) => {
42
- const attachment = props.attachment,
43
- height = props.height,
44
- width = props.width;
42
+ const {
43
+ attachment,
44
+ height,
45
+ width
46
+ } = props;
45
47
  const attachmentBorderRadius = {
46
48
  top: {
47
49
  borderBottomLeftRadius: 0,
@@ -81,9 +83,9 @@ const generateStyle = (componentTheme, props, sharedTokens) => {
81
83
  label: 'codeEditorContainer',
82
84
  height: '100%',
83
85
  width: '100%',
84
- borderColor: componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderColor,
86
+ borderColor: componentTheme?.borderColor,
85
87
  borderStyle: 'solid',
86
- borderWidth: componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderWidth,
88
+ borderWidth: componentTheme?.borderWidth,
87
89
  borderRadius: componentTheme.borderRadius,
88
90
  marginBottom: '1rem',
89
91
  ...(attachment && {
@@ -117,7 +119,7 @@ const generateStyle = (componentTheme, props, sharedTokens) => {
117
119
  // are, for some reason, drawn behind the element content, which
118
120
  // will cause things like the active line background to cover
119
121
  // the outline (#297).
120
- outline: `${componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderWidth} solid ${sharedTokens.focusOutline.infoColor}`
122
+ outline: `${componentTheme?.borderWidth} solid ${sharedTokens.focusOutline.infoColor}`
121
123
  },
122
124
  '.cm-content': {
123
125
  padding: `${componentTheme.verticalPadding} 0`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-source-code-editor",
3
- "version": "11.7.3-snapshot-25",
3
+ "version": "11.7.3-snapshot-27",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -14,7 +14,7 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.27.6",
17
+ "@babel/runtime": "^7.29.2",
18
18
  "@codemirror/autocomplete": "^6.18.1",
19
19
  "@codemirror/commands": "^6.6.2",
20
20
  "@codemirror/lang-css": "^6.3.0",
@@ -29,24 +29,24 @@
29
29
  "@codemirror/state": "^6.4.1",
30
30
  "@codemirror/view": "^6.34.1",
31
31
  "@lezer/highlight": "1.2.1",
32
- "@instructure/emotion": "11.7.3-snapshot-25",
33
- "@instructure/ui-buttons": "11.7.3-snapshot-25",
34
- "@instructure/ui-a11y-content": "11.7.3-snapshot-25",
35
- "@instructure/ui-dom-utils": "11.7.3-snapshot-25",
36
- "@instructure/shared-types": "11.7.3-snapshot-25",
37
- "@instructure/ui-i18n": "11.7.3-snapshot-25",
38
- "@instructure/ui-react-utils": "11.7.3-snapshot-25",
39
- "@instructure/ui-icons": "11.7.3-snapshot-25",
40
- "@instructure/ui-text-input": "11.7.3-snapshot-25",
41
- "@instructure/ui-utils": "11.7.3-snapshot-25",
42
- "@instructure/ui-themes": "11.7.3-snapshot-25"
32
+ "@instructure/emotion": "11.7.3-snapshot-27",
33
+ "@instructure/shared-types": "11.7.3-snapshot-27",
34
+ "@instructure/ui-a11y-content": "11.7.3-snapshot-27",
35
+ "@instructure/ui-buttons": "11.7.3-snapshot-27",
36
+ "@instructure/ui-dom-utils": "11.7.3-snapshot-27",
37
+ "@instructure/ui-i18n": "11.7.3-snapshot-27",
38
+ "@instructure/ui-react-utils": "11.7.3-snapshot-27",
39
+ "@instructure/ui-icons": "11.7.3-snapshot-27",
40
+ "@instructure/ui-themes": "11.7.3-snapshot-27",
41
+ "@instructure/ui-text-input": "11.7.3-snapshot-27",
42
+ "@instructure/ui-utils": "11.7.3-snapshot-27"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@testing-library/jest-dom": "^6.6.3",
46
46
  "@testing-library/react": "15.0.7",
47
47
  "@testing-library/user-event": "^14.6.1",
48
48
  "vitest": "^3.2.2",
49
- "@instructure/ui-babel-preset": "11.7.3-snapshot-25"
49
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-27"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "react": ">=18 <=19",