-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
68 lines (59 loc) · 1.85 KB
/
plugin.js
File metadata and controls
68 lines (59 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Plugin {
/**
* @param {Blockly.Workspace} workspace
*/
constructor(workspace) {
this.workspace = workspace;
this.styleElement = null;
}
/**
* プラグインが有効化された時に実行される
*/
async onload() {
console.log("Plugin Loaded!");
// 1. スタイルの追加
this.applyStyles();
// 2. ブロックの登録
this.registerBlocks();
}
/**
* プラグインが無効化または削除された時に実行される
* ※必ずクリーンアップを行ってください
*/
async onunload() {
console.log("Plugin Unloaded");
// スタイルの削除
if (this.styleElement) {
this.styleElement.remove();
}
// ブロックの削除(必要に応じて)
// ※通常、Blockly.Blocksからの削除のみでOK
}
applyStyles() {
const css = `
.my-custom-block-style {
color: #555;
}
`;
this.styleElement = document.createElement('style');
this.styleElement.textContent = css;
document.head.appendChild(this.styleElement);
}
registerBlocks() {
// ブロックの定義
Blockly.Blocks['my_plugin_hello'] = {
init: function() {
this.appendDummyInput()
.appendField("こんにちは!");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(160);
}
};
// コード生成ロジック (Python)
// Blockly.Python はグローバルにアクセス可能です
Blockly.Python['my_plugin_hello'] = function(block) {
return 'print("Hello from Plugin!")\n';
};
}
}