Skip to content

Commit

Permalink
Merge pull request #64 from wu-component/feat/new
Browse files Browse the repository at this point in the history
feat:deploy playground
  • Loading branch information
canyuegongzi authored Oct 30, 2022
2 parents a8fcc41 + ddfab46 commit e8d77b8
Show file tree
Hide file tree
Showing 79 changed files with 207 additions and 671 deletions.
2 changes: 0 additions & 2 deletions component/packages/wu-code-monaco-editor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ export class WuCodeMonacoEditor extends WuComponent implements OnConnected {
const file = new File([ u8arr ], `initialSrcTs.tsx`, {
type: "text/plain"
});
console.log(file);
const reader = new FileReader();
reader.onload = ()=> {
// 语句是为了显示内容换行
// @ts-ignore
/*const str = reader.result?.replace(/\n/g,"<br/>");
console.log(str);*/
console.log(reader.result);
resolve(reader.result as string);
};
reader.readAsText(file,'utf-8');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>wu-component-playground</title>
<style>
html {
width: 100vw;height:100vh;
}
</style>
<!--<script src="https://unpkg.com/@wu-component/web-core-plus"></script>-->
<script src="https://cdn.canyuegongzi.xyz/wu-code-playground/static/core/index.umd.js"></script>
<script src="https://cdn.canyuegongzi.xyz/wu-code-playground/static/code_editor/index.umd.js"></script>
<script src="https://cdn.canyuegongzi.xyz/wu-code-playground/static/sandbox/index.umd.js"></script>
</head>
<body style="width: 100%;height: 100%;margin: 0;">
<wu-code-playground style="width: 100%;height: 100%"></wu-code-playground>
</body>
<script src="https://cdn.canyuegongzi.xyz/wu-code-playground/static/playground/index.umd.js"></script>
</html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
width: 100vw;height:100vh;
}
</style>
<script src="https://unpkg.com/@wu-component/web-core-plus"></script>
<script src="./public/code_editor/index.umd.js"></script>
<script src="./public/sandbox/index.umd.js"></script>
</head>
<body style="width: 100%;height: 100%;margin: 0;">
<wu-code-playground style="width: 100%;height: 100%"></wu-code-playground>
</body>
<script src="./public/co/index.umd.js"></script>
<script src="./public/si/index.umd.js"></script>
<script src="./dist/index.umd.js"></script>
</body>
</html>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
width: 100vw;height:100vh;
}
</style>
<script src="./co/index.umd.js"></script>
<script src="./si/index.umd.js"></script>
<script src="https://unpkg.com/@wu-component/web-core-plus@0.3.3/dist/index.umd.js"></script>
<script src="./code_editor/index.umd.js"></script>
<script src="./sandbox/index.umd.js"></script>
</head>
<body style="width: 100%;height: 100%;margin: 0;">
<wu-code-playground style="width: 100%;height: 100%"></wu-code-playground>
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions component/packages/wu-code-playground/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './options';
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Component, h, OnConnected, Prop, WuComponent } from '@wu-component/web-core-plus';
import css from './index.scss';
import { compileTS } from "./core/typescript";
import type { WuMonacoEditor } from "./editor";
import type { WuMonacoEditorPreview } from "./preview";
import srcdoc from './srcdoc.txt';
// import "../../wu-code-monaco-editor/src/index";
// import "../../wu-code-sandbox/src/index";
import type { WuCodeMonacoEditor } from "../../wu-code-monaco-editor/types";
import type { WuMonacoEditorPreview } from "../../wu-code-sandbox/types";
import srcdoc from './srcdoc.html';
import initialSrcTs from './initialSrcTs.txt';

@Component({
Expand All @@ -18,7 +20,7 @@ export class WuCodePlayground extends WuComponent implements OnConnected {
@Prop({ default: '', type: String })
public name: string;

public editorContainer: WuMonacoEditor = null;
public editorContainer: WuCodeMonacoEditor = null;
public previewContainer: WuMonacoEditorPreview = null;

public initialEvalSuccess = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './options';
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OnConnected, WuComponent } from '@wu-component/web-core-plus';
import type { WuMonacoEditor } from "./editor";
import type { WuMonacoEditorPreview } from "./preview";
import type { WuCodeMonacoEditor } from "../../wu-code-monaco-editor/types";
import type { WuMonacoEditorPreview } from "../../wu-code-sandbox/types";
export declare class WuCodePlayground extends WuComponent implements OnConnected {
constructor();
name: string;
editorContainer: WuMonacoEditor;
editorContainer: WuCodeMonacoEditor;
previewContainer: WuMonacoEditorPreview;
initialEvalSuccess: boolean;
connected(shadowRoot: ShadowRoot): void;
Expand Down
1 change: 1 addition & 0 deletions component/packages/wu-code-sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
margin: 0;
}
</style>
<script src="https://unpkg.com/@wu-component/web-core-plus@0.3.6/dist/index.umd.js"></script>
</head>
<body style="width: 100%;height: 100%;margin: 0;">
<wu-code-sandbox style="width: 100%;height: 100%"></wu-code-sandbox>
Expand Down
28 changes: 25 additions & 3 deletions component/packages/wu-code-sandbox/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, h, OnConnected, Prop, WuComponent } from "@wu-component/web-core-plus";
import { Component, Emit, h, OnConnected, Prop, WuComponent } from "@wu-component/web-core-plus";
import css from './index.scss';
import { PreviewProxy, LoadDependencies } from "./sandbox";
import { Store } from "./Store";
import srcdoc from './srcdoc.txt';
import srcdoc from './srcdoc.html';

@Component({
name: 'wu-code-sandbox',
Expand Down Expand Up @@ -77,25 +77,35 @@ export class WuMonacoEditorPreview extends WuComponent implements OnConnected {
// 示例话沙箱代理
this.proxy = new PreviewProxy(this.container, {
on_fetch_progress: (progress: any) => {
// this.emitEvent(progress);
// pending_imports = progress;
},
on_error: (event: any) => {
// this.emitEvent(event);
console.log("on_error", event);
},
on_unhandled_rejection: (event: any) => {
// this.emitEvent(event);
console.log("on_unhandled_rejection", event);
},
on_console: (log: any) => {
// this.emitEvent(log);
console.log("log", log);
},
on_console_group: (action: any) => {
// this.emitEvent(action);
// group_logs(action.label, false);
},
on_console_group_end: () => {
on_console_group_end: (event: any) => {
// this.emitEvent(event);
// ungroup_logs();
},
on_console_group_collapsed: (action: any) => {
// this.emitEvent(event);
// group_logs(action.label, true);
},
on_default_event: (event: any) => {
this.emitEvent(event);
}
});
// 沙箱实例完成
Expand Down Expand Up @@ -131,10 +141,22 @@ export class WuMonacoEditorPreview extends WuComponent implements OnConnected {

}

/**
* 沙箱加载依赖
* @param options
*/
public loadDependencies(options: LoadDependencies) {
return this.proxy.load_depend(options);
}

@Emit("message")
public emitEvent(data: any) {
return {
data: data || {}
};

}

public override render(_renderProps = {}, _store = {}) {
const sandbox = () => [ 'allow-forms', 'allow-modals', 'allow-pointer-lock', 'allow-popups', 'allow-same-origin', 'allow-scripts', 'allow-top-navigation-by-user-activation' ].join(' ');
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class PreviewProxy {
if (event.source !== this.iframe.contentWindow) return;

const { action, args } = event.data;

this.handlers.on_default_event(event);
switch (action) {
case 'cmd_error':
case 'cmd_ok':
Expand Down
7 changes: 7 additions & 0 deletions component/packages/wu-code-sandbox/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export declare class WuMonacoEditorPreview extends WuComponent implements OnConn
* @param code
*/
runCode(type: string, code: string): void;
/**
* 沙箱加载依赖
* @param options
*/
loadDependencies(options: LoadDependencies): Promise<unknown>;
emitEvent(data: any): {
data: any;
};
render(_renderProps?: {}, _store?: {}): any;
}
16 changes: 0 additions & 16 deletions component/packages/wu-monaco-editor/public/co/index.umd.js

This file was deleted.

16 changes: 0 additions & 16 deletions component/packages/wu-monaco-editor/public/si/index.umd.js

This file was deleted.

34 changes: 0 additions & 34 deletions component/packages/wu-monaco-editor/src/core/createEditor.ts

This file was deleted.

3 changes: 0 additions & 3 deletions component/packages/wu-monaco-editor/src/core/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions component/packages/wu-monaco-editor/src/core/monaco.ts

This file was deleted.

9 changes: 0 additions & 9 deletions component/packages/wu-monaco-editor/src/editor/index.scss

This file was deleted.

68 changes: 0 additions & 68 deletions component/packages/wu-monaco-editor/src/editor/index.tsx

This file was deleted.

58 changes: 0 additions & 58 deletions component/packages/wu-monaco-editor/src/preview/Store.ts

This file was deleted.

Loading

0 comments on commit e8d77b8

Please sign in to comment.