@huawei-ide/codearts 0.0.8 → 0.0.9
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/README.md +4 -4
- package/index.js +14 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
2. 引入 @huawei-ide/codearts
|
|
10
10
|
`const ide = require('@huawei-ide/codearts');`
|
|
11
11
|
|
|
12
|
-
3. 预加载IDE
|
|
13
|
-
|
|
14
|
-
`ide.preload(id: string).then(() => {});`
|
|
12
|
+
3. 预加载IDE, 返回Promise:
|
|
13
|
+
`await ide.preload();`
|
|
15
14
|
|
|
16
15
|
4. 展示IDE
|
|
17
|
-
|
|
16
|
+
其中id参数为挂载节点id,返回Promise:
|
|
17
|
+
`ide.show(id: string, {width:string,height: string}).then(() => {});`
|
|
18
18
|
|
|
19
19
|
5. 打开文件
|
|
20
20
|
参数content为文件内容,类型为string,path是工程内文件的唯一路径,例如'src', 'src/tool', name为带后缀的文件名:
|
package/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
var iframe = document.createElement('iframe');
|
|
2
2
|
iframe.id = 'codeartside';
|
|
3
|
-
iframe.src = 'https://res.hc-cdn.com/codearts-core-web-static/1.0.
|
|
3
|
+
iframe.src = 'https://res.hc-cdn.com/codearts-core-web-static/1.0.15/resources/server/gitcode.html';
|
|
4
4
|
iframe.width = '1px';
|
|
5
5
|
iframe.height = '1px';
|
|
6
6
|
iframe.style.opacity = 0;
|
|
7
7
|
iframe.style.zIndex = -1;
|
|
8
8
|
|
|
9
|
-
export function preload(
|
|
10
|
-
|
|
11
|
-
targetNode.appendChild(iframe);
|
|
9
|
+
export function preload() {
|
|
10
|
+
document.body.appendChild(iframe);
|
|
12
11
|
return new Promise((resolve) => {
|
|
13
12
|
window.addEventListener('message', function(event) {
|
|
14
13
|
console.log('-gitcode--receive message---', event.data);
|
|
15
14
|
if (event.data === 'ide-loaded') {
|
|
16
|
-
console.log('====Message received from iframe:', event.data);
|
|
17
15
|
resolve();
|
|
18
16
|
}
|
|
19
17
|
});
|
|
@@ -21,12 +19,22 @@ export function preload(id) {
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
// style: { width: string, height: string }
|
|
24
|
-
export function show(style) {
|
|
22
|
+
export function show(id, style) {
|
|
23
|
+
var targetNode = document.getElementById(id);
|
|
24
|
+
targetNode.appendChild(iframe);
|
|
25
25
|
const {width, height} = style;
|
|
26
26
|
iframe.width = width;
|
|
27
27
|
iframe.height = height;
|
|
28
28
|
iframe.style.opacity = 1;
|
|
29
29
|
iframe.style.zIndex = 1;
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
window.addEventListener('message', function(event) {
|
|
32
|
+
console.log('-gitcode--receive message---', event.data);
|
|
33
|
+
if (event.data === 'ide-loaded') {
|
|
34
|
+
resolve();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
// file: { content: string, path: string, name: string }
|