@instructure/ui-source-code-editor 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -1,6 +1,4 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
- const _excluded = ["label", "styles"];
3
- var _dec, _dec2, _dec3, _class, _SourceCodeEditor;
1
+ var _dec, _dec2, _dec3, _class;
4
2
  /*
5
3
  * The MIT License (MIT)
6
4
  *
@@ -58,7 +56,51 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
58
56
  category: components
59
57
  ---
60
58
  **/
61
- let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec3 = textDirectionContextConsumer(), _dec(_class = _dec2(_class = _dec3(_class = (_SourceCodeEditor = class SourceCodeEditor extends Component {
59
+ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec3 = textDirectionContextConsumer(), _dec(_class = _dec2(_class = _dec3(_class = class SourceCodeEditor extends Component {
60
+ static displayName = "SourceCodeEditor";
61
+ static componentId = 'SourceCodeEditor';
62
+ static allowedProps = allowedProps;
63
+ static defaultProps = {
64
+ language: 'jsx',
65
+ readOnly: false,
66
+ editable: true,
67
+ lineNumbers: false,
68
+ foldGutter: false,
69
+ highlightActiveLine: false,
70
+ highlightActiveLineGutter: false,
71
+ lineWrapping: false,
72
+ autofocus: false,
73
+ spellcheck: false,
74
+ rtlMoveVisually: true,
75
+ indentOnLoad: false,
76
+ indentWithTab: false,
77
+ defaultValue: '',
78
+ height: 'auto'
79
+ };
80
+ _id;
81
+ ref = null;
82
+ _containerRef;
83
+ _editorView;
84
+ _raf = [];
85
+ _newSelectionAfterValueChange;
86
+ handleRef = el => {
87
+ const {
88
+ elementRef
89
+ } = this.props;
90
+ this.ref = el;
91
+ if (typeof elementRef === 'function') {
92
+ elementRef(el);
93
+ }
94
+ };
95
+ handleContainerRef = el => {
96
+ const {
97
+ containerRef
98
+ } = this.props;
99
+ this._containerRef = el || undefined;
100
+ if (typeof containerRef === 'function') {
101
+ containerRef(el);
102
+ }
103
+ };
62
104
  addAnimationFrame(callback) {
63
105
  if (typeof callback === 'function') {
64
106
  this._raf.push(requestAnimationFrame(callback));
@@ -70,21 +112,18 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
70
112
  }
71
113
  focus() {
72
114
  this.addAnimationFrame(() => {
73
- var _this$_editorView;
74
- (_this$_editorView = this._editorView) === null || _this$_editorView === void 0 ? void 0 : _this$_editorView.focus();
115
+ this._editorView?.focus();
75
116
  });
76
117
  }
77
118
  get hasFocus() {
78
- var _this$_editorView2;
79
- return (_this$_editorView2 = this._editorView) === null || _this$_editorView2 === void 0 ? void 0 : _this$_editorView2.hasFocus;
119
+ return this._editorView?.hasFocus;
80
120
  }
81
121
  selectAll() {
82
122
  if (this._editorView) {
83
123
  this.addAnimationFrame(() => {
84
- var _this$currentDocValue;
85
124
  this.dispatchViewSelection({
86
125
  anchor: 0,
87
- head: (_this$currentDocValue = this.currentDocValue) === null || _this$currentDocValue === void 0 ? void 0 : _this$currentDocValue.length
126
+ head: this.currentDocValue?.length
88
127
  });
89
128
  });
90
129
  }
@@ -105,8 +144,7 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
105
144
  indentSelection({
106
145
  state: this._editorView.state,
107
146
  dispatch: transaction => {
108
- var _this$_editorView3;
109
- (_this$_editorView3 = this._editorView) === null || _this$_editorView3 === void 0 ? void 0 : _this$_editorView3.update([transaction]);
147
+ this._editorView?.update([transaction]);
110
148
  }
111
149
  });
112
150
  }
@@ -148,10 +186,10 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
148
186
  changes,
149
187
  ...(selection ? {
150
188
  selection
151
- } : void 0),
189
+ } : undefined),
152
190
  ...(userEvent ? {
153
191
  userEvent
154
- } : void 0)
192
+ } : undefined)
155
193
  });
156
194
  }
157
195
 
@@ -163,8 +201,7 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
163
201
  });
164
202
  }
165
203
  get currentDocValue() {
166
- var _this$_editorView4;
167
- return (_this$_editorView4 = this._editorView) === null || _this$_editorView4 === void 0 ? void 0 : _this$_editorView4.state.doc;
204
+ return this._editorView?.state.doc;
168
205
  }
169
206
 
170
207
  // when value is passed, the editor should be controlled
@@ -173,44 +210,16 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
173
210
  }
174
211
  constructor(props) {
175
212
  super(props);
176
- this._id = void 0;
177
- this.ref = null;
178
- this._containerRef = void 0;
179
- this._editorView = void 0;
180
- this._raf = [];
181
- this._newSelectionAfterValueChange = void 0;
182
- this.handleRef = el => {
183
- const elementRef = this.props.elementRef;
184
- this.ref = el;
185
- if (typeof elementRef === 'function') {
186
- elementRef(el);
187
- }
188
- };
189
- this.handleContainerRef = el => {
190
- const containerRef = this.props.containerRef;
191
- this._containerRef = el || void 0;
192
- if (typeof containerRef === 'function') {
193
- containerRef(el);
194
- }
195
- };
196
- this.assignAriaLabel = () => {
197
- if (this._containerRef) {
198
- const editorDiv = this._containerRef.querySelector('[role="textbox"]');
199
- if (editorDiv) {
200
- editorDiv.setAttribute('aria-labelledby', `${this._id}`);
201
- }
202
- }
203
- };
204
213
  this._id = props.deterministicId();
205
214
  }
206
215
  componentDidMount() {
207
- var _this$props$makeStyle, _this$props2;
208
- const _this$props = this.props,
209
- value = _this$props.value,
210
- defaultValue = _this$props.defaultValue,
211
- autofocus = _this$props.autofocus,
212
- indentOnLoad = _this$props.indentOnLoad;
213
- (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
216
+ const {
217
+ value,
218
+ defaultValue,
219
+ autofocus,
220
+ indentOnLoad
221
+ } = this.props;
222
+ this.props.makeStyles?.();
214
223
  const state = EditorState.create({
215
224
  doc: value || defaultValue,
216
225
  extensions: this.extensions
@@ -236,13 +245,11 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
236
245
  this.assignAriaLabel();
237
246
  }
238
247
  componentWillUnmount() {
239
- var _this$_editorView5;
240
- (_this$_editorView5 = this._editorView) === null || _this$_editorView5 === void 0 ? void 0 : _this$_editorView5.destroy();
248
+ this._editorView?.destroy();
241
249
  this.cancelAnimationFrames();
242
250
  }
243
251
  componentDidUpdate(prevProps) {
244
- var _this$props$makeStyle2, _this$props3;
245
- (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
252
+ this.props.makeStyles?.();
246
253
  if (this._editorView) {
247
254
  if (this.props.value !== prevProps.value) {
248
255
  this.refreshEditorValue();
@@ -330,7 +337,9 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
330
337
  return keymaps;
331
338
  }
332
339
  get commandKeybinding() {
333
- const rtlMoveVisually = this.props.rtlMoveVisually;
340
+ const {
341
+ rtlMoveVisually
342
+ } = this.props;
334
343
  if (this.direction === 'rtl' && !rtlMoveVisually) {
335
344
  const overrideableKeys = rtlHorizontalArrowKeymap.map(binding => binding.key ? binding.key : binding.mac ? binding.mac : binding);
336
345
  // we have to remove the binding we want to override from the original,
@@ -341,12 +350,14 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
341
350
  return defaultKeymap;
342
351
  }
343
352
  get themeExtension() {
344
- const styles = this.props.styles;
345
- if (!(styles !== null && styles !== void 0 && styles.theme) || !styles.highlightStyle) {
346
- return void 0;
353
+ const {
354
+ styles
355
+ } = this.props;
356
+ if (!styles?.theme || !styles.highlightStyle) {
357
+ return undefined;
347
358
  }
348
- const theme = EditorView.theme(styles === null || styles === void 0 ? void 0 : styles.theme);
349
- const highlightStyle = syntaxHighlighting(HighlightStyle.define(styles === null || styles === void 0 ? void 0 : styles.highlightStyle));
359
+ const theme = EditorView.theme(styles?.theme);
360
+ const highlightStyle = syntaxHighlighting(HighlightStyle.define(styles?.highlightStyle));
350
361
 
351
362
  // see notes in props.ts
352
363
  // if (darkTheme) {
@@ -357,7 +368,9 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
357
368
  return [theme, highlightStyle];
358
369
  }
359
370
  get languageExtension() {
360
- const language = this.props.language;
371
+ const {
372
+ language
373
+ } = this.props;
361
374
  switch (language) {
362
375
  case 'json':
363
376
  return json();
@@ -393,9 +406,10 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
393
406
  }
394
407
  }
395
408
  callOnChangeHandler(newValue) {
396
- const _this$props4 = this.props,
397
- onChange = _this$props4.onChange,
398
- value = _this$props4.value;
409
+ const {
410
+ onChange,
411
+ value
412
+ } = this.props;
399
413
  this.addAnimationFrame(() => {
400
414
  if (typeof onChange === 'function' && newValue !== value) {
401
415
  onChange(newValue);
@@ -428,9 +442,10 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
428
442
  });
429
443
  }
430
444
  get focusListenerExtension() {
431
- const _this$props5 = this.props,
432
- onFocus = _this$props5.onFocus,
433
- onBlur = _this$props5.onBlur;
445
+ const {
446
+ onFocus,
447
+ onBlur
448
+ } = this.props;
434
449
  return EditorView.updateListener.of(update => {
435
450
  if (update.focusChanged && this._editorView) {
436
451
  if (this.hasFocus) {
@@ -464,7 +479,9 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
464
479
  }
465
480
  refreshEditorValue() {
466
481
  if (!this._editorView) return;
467
- const value = this.props.value;
482
+ const {
483
+ value
484
+ } = this.props;
468
485
  const currentValue = this._editorView.state.doc.toString();
469
486
  if (typeof value !== 'undefined' && currentValue !== value) {
470
487
  let userEvent;
@@ -494,50 +511,43 @@ let SourceCodeEditor = (_dec = withDeterministicId(), _dec2 = withStyle(generate
494
511
  this._editorView.scrollDOM.scrollTop = scrollTop;
495
512
  }
496
513
  });
497
- this._newSelectionAfterValueChange = void 0;
514
+ this._newSelectionAfterValueChange = undefined;
498
515
  }
499
516
  if (this.props.indentOnLoad) {
500
517
  this.indentAll();
501
518
  }
502
519
  }
520
+ assignAriaLabel = () => {
521
+ if (this._containerRef) {
522
+ const editorDiv = this._containerRef.querySelector('[role="textbox"]');
523
+ if (editorDiv) {
524
+ editorDiv.setAttribute('aria-labelledby', `${this._id}`);
525
+ }
526
+ }
527
+ };
503
528
  render() {
504
- const _this$props6 = this.props,
505
- label = _this$props6.label,
506
- styles = _this$props6.styles,
507
- restProps = _objectWithoutProperties(_this$props6, _excluded);
529
+ const {
530
+ label,
531
+ styles,
532
+ ...restProps
533
+ } = this.props;
508
534
  return _jsx("div", {
509
535
  "data-cid": "SourceCodeEditor",
510
536
  ref: this.handleRef,
511
- css: styles === null || styles === void 0 ? void 0 : styles.codeEditor,
537
+ css: styles?.codeEditor,
512
538
  ...passthroughProps(omitProps(restProps, SourceCodeEditor.allowedProps)),
513
539
  children: _jsxs("label", {
514
- css: styles === null || styles === void 0 ? void 0 : styles.label,
540
+ css: styles?.label,
515
541
  id: this._id,
516
542
  children: [_jsx(ScreenReaderContent, {
517
543
  children: label
518
544
  }), _jsx("div", {
519
545
  ref: this.handleContainerRef,
520
- css: styles === null || styles === void 0 ? void 0 : styles.codeEditorContainer
546
+ css: styles?.codeEditorContainer
521
547
  })]
522
548
  })
523
549
  });
524
550
  }
525
- }, _SourceCodeEditor.displayName = "SourceCodeEditor", _SourceCodeEditor.componentId = 'SourceCodeEditor', _SourceCodeEditor.allowedProps = allowedProps, _SourceCodeEditor.defaultProps = {
526
- language: 'jsx',
527
- readOnly: false,
528
- editable: true,
529
- lineNumbers: false,
530
- foldGutter: false,
531
- highlightActiveLine: false,
532
- highlightActiveLineGutter: false,
533
- lineWrapping: false,
534
- autofocus: false,
535
- spellcheck: false,
536
- rtlMoveVisually: true,
537
- indentOnLoad: false,
538
- indentWithTab: false,
539
- defaultValue: '',
540
- height: 'auto'
541
- }, _SourceCodeEditor)) || _class) || _class) || _class);
551
+ }) || _class) || _class) || _class);
542
552
  export default SourceCodeEditor;
543
553
  export { SourceCodeEditor };
@@ -33,9 +33,11 @@ import { tags } from '@lezer/highlight';
33
33
  * @return {Object} The final style object, which will be used in the component
34
34
  */
35
35
  const generateStyle = (componentTheme, props, sharedTokens) => {
36
- const attachment = props.attachment,
37
- height = props.height,
38
- width = props.width;
36
+ const {
37
+ attachment,
38
+ height,
39
+ width
40
+ } = props;
39
41
  const attachmentBorderRadius = {
40
42
  top: {
41
43
  borderBottomLeftRadius: 0,
@@ -75,9 +77,9 @@ const generateStyle = (componentTheme, props, sharedTokens) => {
75
77
  label: 'codeEditorContainer',
76
78
  height: '100%',
77
79
  width: '100%',
78
- borderColor: componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderColor,
80
+ borderColor: componentTheme?.borderColor,
79
81
  borderStyle: 'solid',
80
- borderWidth: componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderWidth,
82
+ borderWidth: componentTheme?.borderWidth,
81
83
  borderRadius: componentTheme.borderRadius,
82
84
  marginBottom: '1rem',
83
85
  ...(attachment && {
@@ -111,7 +113,7 @@ const generateStyle = (componentTheme, props, sharedTokens) => {
111
113
  // are, for some reason, drawn behind the element content, which
112
114
  // will cause things like the active line background to cover
113
115
  // the outline (#297).
114
- outline: `${componentTheme === null || componentTheme === void 0 ? void 0 : componentTheme.borderWidth} solid ${sharedTokens.focusOutline.infoColor}`
116
+ outline: `${componentTheme?.borderWidth} solid ${sharedTokens.focusOutline.infoColor}`
115
117
  },
116
118
  '.cm-content': {
117
119
  padding: `${componentTheme.verticalPadding} 0`
@@ -1,21 +1,18 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = customSearch;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
7
  var _react = require("react");
10
8
  var _search = require("@codemirror/search");
11
9
  var _v11_ = require("@instructure/ui-text-input/v11_6");
12
10
  var _v11_2 = require("@instructure/ui-buttons/v11_6");
13
11
  var _IconArrowOpenDownLine = require("@instructure/ui-icons/lib/generated/IconArrowOpenDownLine.js");
14
- var _IconArrowOpenUpLine2 = require("@instructure/ui-icons/lib/generated/IconArrowOpenUpLine.js");
15
- var _IconSearchLine2 = require("@instructure/ui-icons/lib/generated/IconSearchLine.js");
12
+ var _IconArrowOpenUpLine = require("@instructure/ui-icons/lib/generated/IconArrowOpenUpLine.js");
13
+ var _IconSearchLine = require("@instructure/ui-icons/lib/generated/IconSearchLine.js");
16
14
  var _client = require("react-dom/client");
17
15
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
18
- var _IconSearchLine, _IconArrowOpenDownLin, _IconArrowOpenUpLine;
19
16
  /*
20
17
  * The MIT License (MIT)
21
18
  *
@@ -39,14 +36,12 @@ var _IconSearchLine, _IconArrowOpenDownLin, _IconArrowOpenUpLine;
39
36
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
37
  * SOFTWARE.
41
38
  */
39
+
42
40
  function SearchPanel({
43
41
  view,
44
42
  searchConfig
45
43
  }) {
46
- const _useState = (0, _react.useState)(''),
47
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
48
- searchQueryStr = _useState2[0],
49
- setSearchQueryStr = _useState2[1];
44
+ const [searchQueryStr, setSearchQueryStr] = (0, _react.useState)('');
50
45
  const handleChange = (_e, value) => {
51
46
  setSearchQueryStr(value);
52
47
  handleHighlightSearch(value);
@@ -77,7 +72,7 @@ function SearchPanel({
77
72
  return (0, _jsxRuntime.jsx)(_v11_.TextInput, {
78
73
  renderLabel: "",
79
74
  inputRef: r => {
80
- setTimeout(() => r === null || r === void 0 ? void 0 : r.focus(), 0);
75
+ setTimeout(() => r?.focus(), 0);
81
76
  },
82
77
  size: "small",
83
78
  display: "inline-block",
@@ -86,9 +81,9 @@ function SearchPanel({
86
81
  onChange: handleChange,
87
82
  onKeyDown: handleKeyDown,
88
83
  onKeyUp: handleKeyUp,
89
- renderBeforeInput: _IconSearchLine || (_IconSearchLine = (0, _jsxRuntime.jsx)(_IconSearchLine2.IconSearchLine, {
84
+ renderBeforeInput: (0, _jsxRuntime.jsx)(_IconSearchLine.IconSearchLine, {
90
85
  size: "x-small"
91
- })),
86
+ }),
92
87
  renderAfterInput: (0, _jsxRuntime.jsxs)("span", {
93
88
  children: [(0, _jsxRuntime.jsx)(_v11_2.IconButton, {
94
89
  size: "small",
@@ -96,14 +91,14 @@ function SearchPanel({
96
91
  withBackground: false,
97
92
  onClick: handleFindNext,
98
93
  screenReaderLabel: searchConfig.nextResultLabel,
99
- children: _IconArrowOpenDownLin || (_IconArrowOpenDownLin = (0, _jsxRuntime.jsx)(_IconArrowOpenDownLine.IconArrowOpenDownLine, {}))
94
+ children: (0, _jsxRuntime.jsx)(_IconArrowOpenDownLine.IconArrowOpenDownLine, {})
100
95
  }), (0, _jsxRuntime.jsx)(_v11_2.IconButton, {
101
96
  size: "small",
102
97
  withBorder: false,
103
98
  withBackground: false,
104
99
  onClick: handleFindPrev,
105
100
  screenReaderLabel: searchConfig.prevResultLabel,
106
- children: _IconArrowOpenUpLine || (_IconArrowOpenUpLine = (0, _jsxRuntime.jsx)(_IconArrowOpenUpLine2.IconArrowOpenUpLine, {}))
101
+ children: (0, _jsxRuntime.jsx)(_IconArrowOpenUpLine.IconArrowOpenUpLine, {})
107
102
  })]
108
103
  })
109
104
  });