codenotch-react 1.0.66 → 1.0.68
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,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { ICodenotchEnv } from "..";
|
|
2
3
|
interface ICodeEditorProps {
|
|
4
|
+
env?: ICodenotchEnv;
|
|
3
5
|
style?: React.CSSProperties;
|
|
4
6
|
className?: string;
|
|
5
7
|
value?: string;
|
|
@@ -13,7 +15,9 @@ interface ICodeEditorProps {
|
|
|
13
15
|
export default class CodeEditor extends React.Component<ICodeEditorProps> {
|
|
14
16
|
private isIframeReady;
|
|
15
17
|
private onChangeTimeoutHandle;
|
|
18
|
+
private onMessageHandler;
|
|
16
19
|
refFrame: React.RefObject<HTMLIFrameElement>;
|
|
20
|
+
constructor(props: ICodeEditorProps);
|
|
17
21
|
setValue(value: string): void;
|
|
18
22
|
componentDidMount(): void;
|
|
19
23
|
componentWillUnmount(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../src/components/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../src/components/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAEnC,UAAU,gBAAgB;IACtB,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC;IACrE,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,qBAAqB,CAAa;IAC1C,OAAO,CAAC,gBAAgB,CAAM;IAC9B,QAAQ,qCAAwC;gBAEpC,KAAK,EAAE,gBAAgB;IAKnC,QAAQ,CAAC,KAAK,EAAE,MAAM;IAStB,iBAAiB,IAAI,IAAI;IAKzB,oBAAoB,IAAI,IAAI;IAI5B,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI;IAoBrD,OAAO,CAAC,aAAa;IAgCrB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,WAAW;IA4EnB,MAAM;CAeT"}
|
|
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const __1 = require("..");
|
|
8
7
|
/**
|
|
9
8
|
* Light version of Monaco Editor in an iframe.
|
|
10
9
|
*/
|
|
11
10
|
class CodeEditor extends react_1.default.Component {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
14
13
|
this.isIframeReady = false;
|
|
15
14
|
this.onChangeTimeoutHandle = null;
|
|
16
15
|
this.refFrame = react_1.default.createRef();
|
|
16
|
+
this.onMessageHandler = this.handleMessage.bind(this);
|
|
17
17
|
}
|
|
18
18
|
setValue(value) {
|
|
19
19
|
if (this.isIframeReady) {
|
|
@@ -24,18 +24,18 @@ class CodeEditor extends react_1.default.Component {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
componentDidMount() {
|
|
27
|
-
window.addEventListener('message', this.
|
|
27
|
+
window.addEventListener('message', this.onMessageHandler);
|
|
28
28
|
this.writeIframe();
|
|
29
29
|
}
|
|
30
30
|
componentWillUnmount() {
|
|
31
|
-
window.removeEventListener('message', this.
|
|
31
|
+
window.removeEventListener('message', this.onMessageHandler);
|
|
32
32
|
}
|
|
33
33
|
componentDidUpdate(prevProps) {
|
|
34
34
|
const changed = (prevProps.value !== this.props.value ||
|
|
35
35
|
prevProps.language !== this.props.language ||
|
|
36
36
|
prevProps.readOnly !== this.props.readOnly);
|
|
37
37
|
if (changed && this.isIframeReady) {
|
|
38
|
-
let isDark =
|
|
38
|
+
let isDark = this.props.env?.theme === 'dark';
|
|
39
39
|
this.postToIframe({
|
|
40
40
|
type: 'update',
|
|
41
41
|
value: this.props.value ?? '',
|
|
@@ -60,7 +60,7 @@ class CodeEditor extends react_1.default.Component {
|
|
|
60
60
|
value: this.props.value ?? '',
|
|
61
61
|
language: this.props.language || 'plaintext',
|
|
62
62
|
readOnly: !!this.props.readOnly,
|
|
63
|
-
theme:
|
|
63
|
+
theme: this.props.env?.theme === 'dark' ? 'vs-dark' : 'vs'
|
|
64
64
|
});
|
|
65
65
|
break;
|
|
66
66
|
}
|