@codecademy/codebytes 1.4.0-alpha.334191b9b7.0 → 1.4.0-alpha.463d0ee6f8.0

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,35 +1,61 @@
1
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1
7
  // DO NOT CHANGE ANYTHING HERE
2
8
  // This component is part of the Codebytes MVP and only includes basic configuration around theming
3
9
  // We are working on a monaco package in client-modules that has more configuration around themes and languages
4
10
  // Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
5
11
 
6
12
  import ReactMonacoEditor from '@monaco-editor/react';
7
- import React, { useCallback, useRef } from 'react';
8
- import ResizeObserver from 'react-resize-observer';
13
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
9
14
  import { dark } from './theme';
10
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
15
+ import { jsx as _jsx } from "react/jsx-runtime";
11
16
  export const SimpleMonacoEditor = _ref => {
12
17
  let value = _ref.value,
13
18
  language = _ref.language,
14
19
  onChange = _ref.onChange;
20
+ const _useState = useState(0),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ width = _useState2[0],
23
+ setWidth = _useState2[1];
24
+ const _useState3 = useState(0),
25
+ _useState4 = _slicedToArray(_useState3, 2),
26
+ height = _useState4[0],
27
+ setHeight = _useState4[1];
28
+ const containerRef = useRef(null);
15
29
  const editorRef = useRef(null);
16
30
  const editorWillMount = useCallback((editor, monaco) => {
17
31
  editorRef.current = editor;
18
32
  monaco.editor.defineTheme('dark', dark);
19
33
  monaco.editor.setTheme('dark');
20
34
  }, []);
21
- return /*#__PURE__*/_jsxs(_Fragment, {
22
- children: [/*#__PURE__*/_jsx(ResizeObserver, {
23
- onResize: _ref2 => {
24
- var _editorRef$current;
25
- let height = _ref2.height,
26
- width = _ref2.width;
27
- (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.layout({
28
- height,
29
- width
30
- });
35
+ useEffect(() => {
36
+ const element = containerRef.current;
37
+ if (!element) return;
38
+ const resizeObserver = new ResizeObserver(entries => {
39
+ for (const entry of entries) {
40
+ const _entry$contentRect = entry.contentRect,
41
+ newWidth = _entry$contentRect.width,
42
+ newHeight = _entry$contentRect.height;
43
+ setWidth(newWidth);
44
+ setHeight(newHeight);
31
45
  }
32
- }), /*#__PURE__*/_jsx(ReactMonacoEditor, {
46
+ });
47
+ resizeObserver.observe(element);
48
+ return () => {
49
+ resizeObserver.disconnect();
50
+ };
51
+ }, []);
52
+ return /*#__PURE__*/_jsx("div", {
53
+ ref: containerRef,
54
+ style: {
55
+ width: '100%',
56
+ height: '100%'
57
+ },
58
+ children: /*#__PURE__*/_jsx(ReactMonacoEditor, {
33
59
  onMount: editorWillMount,
34
60
  onChange: onChange,
35
61
  options: {
@@ -39,11 +65,13 @@ export const SimpleMonacoEditor = _ref => {
39
65
  },
40
66
  theme: "vs-dark",
41
67
  value: value,
68
+ height: height,
69
+ width: width,
42
70
  language: language
43
- // beforeMount is a required prop for the Monaco editor. If it is not provided, the editor will not be initialized correctly.
71
+ // beforeMount is used internally by Monaco. If it is not provided, the editor will not be initialized correctly.
44
72
  // eslint-disable-next-line @typescript-eslint/no-empty-function
45
73
  ,
46
74
  beforeMount: () => {}
47
- })]
75
+ })
48
76
  });
49
77
  };
package/package.json CHANGED
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "@codecademy/codebytes",
3
+ "version": "1.4.0-alpha.463d0ee6f8.0",
3
4
  "description": "Codebytes Editor",
4
- "version": "1.4.0-alpha.334191b9b7.0",
5
+ "license": "MIT",
6
+ "repository": "git@github.com:codecademy-engineering/mono.git",
5
7
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
- "dependencies": {
7
- "@monaco-editor/react": "^4.4.5",
8
- "react-resize-observer": "^1.1.1"
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "scripts": {
11
+ "build:watch": "yarn build:clean && yarn build:compile && yarn build:types && onchange ./src -- yarn build:compile && yarn build:types"
9
12
  },
10
13
  "files": [
11
14
  "dist/**"
12
15
  ],
13
- "license": "MIT",
14
- "main": "./dist/index.js",
15
- "module": "./dist/index.js",
16
+ "dependencies": {
17
+ "@monaco-editor/react": "^4.4.5"
18
+ },
16
19
  "peerDependencies": {
17
20
  "@codecademy/gamut": "*",
18
21
  "@codecademy/gamut-icons": "*",
19
22
  "@codecademy/gamut-styles": "*",
20
- "@codecademy/tracking": "1.4.0-alpha.334191b9b7.0",
23
+ "@codecademy/tracking": "1.4.0-alpha.463d0ee6f8.0",
21
24
  "@codecademy/variance": "*",
22
25
  "@emotion/styled": "^11.3.0",
23
26
  "monaco-editor": "*",
@@ -26,10 +29,6 @@
26
29
  "publishConfig": {
27
30
  "access": "public"
28
31
  },
29
- "repository": "git@github.com:codecademy-engineering/mono.git",
30
- "scripts": {
31
- "build:watch": "yarn build:clean && yarn build:compile && yarn build:types && onchange ./src -- yarn build:compile && yarn build:types"
32
- },
33
32
  "sideEffects": [
34
33
  "**/*.css",
35
34
  "**/*.scss",