Skip to content

Commit

Permalink
nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
fs-context committed Dec 15, 2024
1 parent 49b49cc commit 8334726
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/loader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExtensionLoadError } from "@framework/exceptions";
type LoaderConfig = import("@framework/internal").LoaderConfig;
const config: LoaderConfig = {
target: import("@src/extension"),
target: import("@samples/py/extension"),
errorCatches: [Error, ExtensionLoadError],
platform: ["TurboWarp"]
};
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"license": "MIT",
"devDependencies": {
"@eslint/js": "^9.16.0",
"@types/md5": "^2.3.5",
"css-loader": "^7.1.2",
"eslint": "^9.16.0",
"eslint-plugin-vue": "^9.32.0",
Expand All @@ -35,7 +34,6 @@
},
"dependencies": {
"highlight.js": "^11.10.0",
"md5": "^2.3.0",
"vue": "^3.5.12"
}
}
47 changes: 47 additions & 0 deletions src/fs-context/samples/py/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Scratch } from "@framework/internal";
import { Collaborator, Extension, Translator, Version, BlockType } from "@framework/structs";
import { GlobalContext, Unnecessary } from "@framework/tools";
import "./style.css";
const translator = Translator.create("zh-cn", {
name: "内嵌Python",
description: "使用pyscript嵌入Python",
run: "设置[console:string]中的代码[code:string=print('hello world')]",
create: "创建控制台[name:string]",
startRendering: "开始渲染[console:string]"
});
export default class FSIFrame extends Extension {
id = "pyinner";
displayName = translator.load("name");
version = new Version(1, 0, 0);
description = translator.load("description");
collaborators = [
new Collaborator("FallingShrimp", "https://rundll86.github.io")
];
init(runtime: Scratch) {
runtime.renderer.canvas.parentElement?.appendChild(
dataStore.read("rootBase").result
);
document.head.appendChild(
Unnecessary.elementTree("script")
.attribute("src", "https://pyscript.net/releases/2024.11.1/core.js")
.attribute("type", "module")
.result
);
};
@BlockType.Command(translator.load("create"))
create(arg: Record<string, any>) {
dataStore.read("consoles")[arg.name] = Unnecessary.elementTree("mpy-script" as any);
};
@BlockType.Command(translator.load("run"))
run(arg: Record<string, any>) {
dataStore.read("consoles")[arg.console].attribute("innerHTML", arg.code);
};
@BlockType.Command(translator.load("startRendering"))
startRendering(arg: Record<string, any>) {
dataStore.read("rootBase").child(dataStore.read("consoles")[arg.console]);
};
};
const dataStore = GlobalContext.createDataStore(FSIFrame, {
consoles: {} as Record<string, any>,
rootBase: Unnecessary.elementTree("div").class("fsi-base")
});
11 changes: 11 additions & 0 deletions src/fs-context/samples/py/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.fsi-base {
position: absolute;
left: 0;
top: 0;
}

.fsi-iframe {
position: absolute;
border:none;
outline:none;
}
39 changes: 39 additions & 0 deletions src/fs-context/samples/run-js/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { BlockType, Extension, Translator } from "@framework/structs";
import { GlobalContext } from "@framework/tools";
const translator = Translator.create("zh-cn", {
name: "Run JS",
description: "运行JS代码",
run: "运行[js:string]",
runAndGetResult: "运行[js:string]并返回结果",
getStack: "上次JS运行异常的错误栈信息"
});
export default class FallingAnchors extends Extension {
id: string = "runjs";
displayName: string = translator.load("name");
description: string = translator.load("description");
allowSandboxed: boolean = false;
@BlockType.Command(translator.load("run"))
runJs(arg: Record<string, any>) {
try {
eval(arg.js);
} catch (e: any) {
dataStore.write("stack", e.stack);
}
}
@BlockType.Reporter(translator.load("runAndGetResult"))
runAndGetResult(arg: Record<string, any>) {
try {
return eval(arg.js);
} catch (e: any) {
dataStore.write("stack", e.stack);
return undefined;
}
}
@BlockType.Reporter(translator.load("getStack"))
getStack(arg: Record<string, any>) {
return dataStore.read("stack");
}
};
const dataStore = GlobalContext.createDataStore(FallingAnchors, {
stack: ""
});
1 change: 0 additions & 1 deletion src/fs-context/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
BlockConfigA,
MenuDefine
} from "./internal";
import md5 from "md5";
import { MenuParser, TextParser, Unnecessary } from "./tools";
import { MissingError, OnlyInstanceWarn } from "./exceptions";
export class Extension {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"module": "ESNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"outDir": "generated",
"experimentalDecorators": true,
"resolveJsonModule": true,
"moduleResolution": "bundler",
"paths": {
"@framework/*": [
"./src/fs-context/*"
Expand Down
7 changes: 5 additions & 2 deletions webpack.config.ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ module.exports = {
...commonConfig.staticShow,
entry: "@framework/entry.ts",
output: {
filename: `${serverConfig.extension.output}.dist.js`,
// filename: `${serverConfig.extension.output}.dist.js`,
filename:"[name].dist.js",
path: path.resolve(__dirname, `dist/${serverConfig.extension.output}`),
clean: true
clean: true,
library: serverConfig.extension.output,
libraryTarget: "window"
},
module: {
rules: [
Expand Down

0 comments on commit 8334726

Please sign in to comment.