@codecademy/codebytes 1.4.0-alpha.b72c2541d4.0 → 1.4.0-alpha.ec36a35d00.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.
- package/dist/MonacoEditor/index.js +50 -35
- package/package.json +11 -12
|
@@ -10,53 +10,68 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
|
10
10
|
// Monaco as a shared package RFC https://www.notion.so/codecademy/Monaco-editor-as-a-shared-package-1f4484db165b4abc8394c3556451ef6a
|
|
11
11
|
|
|
12
12
|
import ReactMonacoEditor from '@monaco-editor/react';
|
|
13
|
-
import React, { useCallback, useRef } from 'react';
|
|
14
|
-
import { useMeasure } from 'react-use';
|
|
13
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
15
14
|
import { dark } from './theme';
|
|
16
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
16
|
export const SimpleMonacoEditor = _ref => {
|
|
18
17
|
let value = _ref.value,
|
|
19
18
|
language = _ref.language,
|
|
20
19
|
onChange = _ref.onChange;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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);
|
|
27
29
|
const editorRef = useRef(null);
|
|
28
30
|
const editorWillMount = useCallback((editor, monaco) => {
|
|
29
31
|
editorRef.current = editor;
|
|
30
32
|
monaco.editor.defineTheme('dark', dark);
|
|
31
33
|
monaco.editor.setTheme('dark');
|
|
32
34
|
}, []);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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);
|
|
45
|
+
}
|
|
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, {
|
|
59
|
+
onMount: editorWillMount,
|
|
60
|
+
onChange: onChange,
|
|
61
|
+
options: {
|
|
62
|
+
minimap: {
|
|
63
|
+
enabled: false
|
|
64
|
+
}
|
|
41
65
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
value: value,
|
|
52
|
-
height: height,
|
|
53
|
-
width: width,
|
|
54
|
-
language: language
|
|
55
|
-
// beforeMount is a required prop for the Monaco editor. If it is not provided, the editor will not be initialized correctly.
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
57
|
-
,
|
|
58
|
-
beforeMount: () => {}
|
|
59
|
-
})
|
|
66
|
+
theme: "vs-dark",
|
|
67
|
+
value: value,
|
|
68
|
+
height: height,
|
|
69
|
+
width: width,
|
|
70
|
+
language: language
|
|
71
|
+
// beforeMount is used internally by Monaco. If it is not provided, the editor will not be initialized correctly.
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
73
|
+
,
|
|
74
|
+
beforeMount: () => {}
|
|
60
75
|
})
|
|
61
|
-
);
|
|
76
|
+
});
|
|
62
77
|
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/codebytes",
|
|
3
|
+
"version": "1.4.0-alpha.ec36a35d00.0",
|
|
3
4
|
"description": "Codebytes Editor",
|
|
4
|
-
"
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "git@github.com:codecademy-engineering/mono.git",
|
|
5
7
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
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.
|
|
23
|
+
"@codecademy/tracking": "1.4.0-alpha.ec36a35d00.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",
|