@kubohiroya/turbowarp-plus-editor-code-views 0.0.0-stage → 0.2.0
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/LICENSE +373 -0
- package/README.ja.md +42 -0
- package/README.md +41 -2
- package/dist/asset-edit-session.d.ts +24 -0
- package/dist/asset-edit-session.js +58 -0
- package/dist/block-argument-text.d.ts +39 -0
- package/dist/block-argument-text.js +170 -0
- package/dist/block-drag.d.ts +17 -0
- package/dist/block-drag.js +184 -0
- package/dist/code-extensions.d.ts +38 -0
- package/dist/code-extensions.js +418 -0
- package/dist/code-pane.d.ts +80 -0
- package/dist/code-pane.js +398 -0
- package/dist/custom-extension-fields.d.ts +45 -0
- package/dist/custom-extension-fields.js +144 -0
- package/dist/detached-block-palette-view.d.ts +10 -0
- package/dist/detached-block-palette-view.js +62 -0
- package/dist/detached-block-palette.d.ts +41 -0
- package/dist/detached-block-palette.js +197 -0
- package/dist/dockview-unsaved.d.ts +45 -0
- package/dist/dockview-unsaved.js +123 -0
- package/dist/history.d.ts +57 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +729 -0
- package/dist/native-extension-field.d.ts +26 -0
- package/dist/native-extension-field.js +204 -0
- package/dist/native-field-svg.d.ts +20 -0
- package/dist/native-field-svg.js +156 -0
- package/dist/palette-category-reorder.d.ts +4 -0
- package/dist/palette-category-reorder.js +167 -0
- package/dist/palette-category-search.d.ts +26 -0
- package/dist/palette-category-search.js +74 -0
- package/dist/palette-dropdown-resize.d.ts +19 -0
- package/dist/palette-dropdown-resize.js +135 -0
- package/dist/parent-field-layout.d.ts +2 -0
- package/dist/parent-field-layout.js +90 -0
- package/dist/parent-field-mirror.d.ts +3 -0
- package/dist/parent-field-mirror.js +290 -0
- package/dist/parent-field-resources.d.ts +9 -0
- package/dist/parent-field-resources.js +199 -0
- package/dist/preview-chrome.d.ts +9 -0
- package/dist/preview-chrome.js +78 -0
- package/dist/procedure-editor.d.ts +9 -0
- package/dist/procedure-editor.js +122 -0
- package/dist/procedure-edits.d.ts +16 -0
- package/dist/procedure-edits.js +47 -0
- package/dist/programmatic-extension-field.d.ts +20 -0
- package/dist/programmatic-extension-field.js +69 -0
- package/dist/protocol.d.ts +15 -0
- package/dist/protocol.js +36 -0
- package/dist/script-layout-dialog.d.ts +10 -0
- package/dist/script-layout-dialog.js +93 -0
- package/dist/script-layout-view.d.ts +68 -0
- package/dist/script-layout-view.js +164 -0
- package/dist/script-layout-workspace.d.ts +45 -0
- package/dist/script-layout-workspace.js +55 -0
- package/dist/script-layout.d.ts +17 -0
- package/dist/script-layout.js +25 -0
- package/dist/script-view-menu.d.ts +46 -0
- package/dist/script-view-menu.js +161 -0
- package/dist/sprite-code-windows.d.ts +32 -0
- package/dist/sprite-code-windows.js +180 -0
- package/dist/stage-code-prewarm.d.ts +52 -0
- package/dist/stage-code-prewarm.js +216 -0
- package/dist/target-combobox.d.ts +10 -0
- package/dist/target-combobox.js +92 -0
- package/dist/variable-references.d.ts +1 -0
- package/dist/variable-references.js +87 -0
- package/dist/workspace.d.ts +104 -0
- package/dist/workspace.js +1102 -0
- package/package.json +100 -4
- package/src/asset-edit-session.ts +72 -0
- package/src/block-argument-text.ts +172 -0
- package/src/block-drag.ts +190 -0
- package/src/code-extensions.ts +394 -0
- package/src/code-pane.ts +393 -0
- package/src/custom-extension-fields.ts +154 -0
- package/src/detached-block-palette-view.tsx +97 -0
- package/src/detached-block-palette.ts +218 -0
- package/src/dockview-unsaved.ts +134 -0
- package/src/history.ts +114 -0
- package/src/index.ts +680 -0
- package/src/native-extension-field.ts +201 -0
- package/src/native-field-svg.ts +140 -0
- package/src/palette-category-reorder.ts +155 -0
- package/src/palette-category-search.ts +82 -0
- package/src/palette-dropdown-resize.ts +132 -0
- package/src/parent-field-layout.ts +88 -0
- package/src/parent-field-mirror.ts +260 -0
- package/src/parent-field-resources.ts +179 -0
- package/src/preview-chrome.ts +82 -0
- package/src/procedure-editor.ts +123 -0
- package/src/procedure-edits.ts +46 -0
- package/src/programmatic-extension-field.ts +76 -0
- package/src/protocol.ts +47 -0
- package/src/script-layout-dialog.ts +104 -0
- package/src/script-layout-view.ts +198 -0
- package/src/script-layout-workspace.ts +95 -0
- package/src/script-layout.ts +40 -0
- package/src/script-view-menu.ts +213 -0
- package/src/sprite-code-windows.tsx +183 -0
- package/src/stage-code-prewarm.ts +242 -0
- package/src/styles.css +595 -0
- package/src/target-combobox.tsx +106 -0
- package/src/variable-references.ts +85 -0
- package/src/workspace.ts +1125 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// ScratchBlocks normally coalesces variables by name and type. The VM's
|
|
2
|
+
// projection can contain two variables or lists with the same name and different scopes.
|
|
3
|
+
export function installScopedVariableReferences(blocks, workspace, getLocale: () => string) {
|
|
4
|
+
const scopedType = type => type === '' || type === blocks.LIST_VARIABLE_TYPE;
|
|
5
|
+
const map = workspace.getVariableMap();
|
|
6
|
+
const createVariable = map.createVariable;
|
|
7
|
+
const getVariable = map.getVariable;
|
|
8
|
+
map.createVariable = function (name, type, id, isLocal, isCloud) {
|
|
9
|
+
const existing = id && scopedType(type) && typeof isLocal === 'boolean' && getVariable.call(this, name, type);
|
|
10
|
+
if (!existing) return createVariable.call(this, name, type, id, isLocal, isCloud);
|
|
11
|
+
|
|
12
|
+
const byId = this.getVariableById(id);
|
|
13
|
+
if (byId) return byId;
|
|
14
|
+
// Preserve the normal model creation and events, but match the name
|
|
15
|
+
// only within the incoming scope for this synchronous insertion.
|
|
16
|
+
const sameScope = this.getVariablesOfType(type)
|
|
17
|
+
.find(variable => variable.name === name && variable.isLocal === isLocal);
|
|
18
|
+
this.getVariable = () => sameScope;
|
|
19
|
+
try {
|
|
20
|
+
return createVariable.call(this, name, type, id, isLocal, isCloud);
|
|
21
|
+
} finally {
|
|
22
|
+
this.getVariable = getVariable;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const scopedLabel = (variable, variables) => {
|
|
27
|
+
if (!variables.some(other => other.name === variable.name && other.isLocal !== variable.isLocal)) {
|
|
28
|
+
return variable.name;
|
|
29
|
+
}
|
|
30
|
+
const ja = /^ja(?:-|$)/i.test(getLocale());
|
|
31
|
+
const scope = variable.isLocal ? (ja ? 'このスプライト' : 'Local') : (ja ? '全体' : 'Global');
|
|
32
|
+
return `${scope}: ${variable.name}`;
|
|
33
|
+
};
|
|
34
|
+
const inWorkspace = field => field.sourceBlock_?.workspace === workspace;
|
|
35
|
+
for (const field of [blocks.FieldVariable.prototype, blocks.FieldVariableGetter.prototype]) {
|
|
36
|
+
const setText = field.setText;
|
|
37
|
+
field.setText = function (text) {
|
|
38
|
+
const variable = this.getVariable();
|
|
39
|
+
const label = inWorkspace(this) && variable && scopedType(variable.type) && text === variable.name ?
|
|
40
|
+
scopedLabel(variable, workspace.getVariablesOfType(variable.type)) : text;
|
|
41
|
+
return setText.call(this, label);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getOptions = blocks.FieldVariable.prototype.getOptions;
|
|
46
|
+
blocks.FieldVariable.prototype.getOptions = function () {
|
|
47
|
+
const options = getOptions.call(this);
|
|
48
|
+
const type = this.getVariable()?.type;
|
|
49
|
+
if (!inWorkspace(this) || !scopedType(type)) return options;
|
|
50
|
+
const variables = workspace.getVariablesOfType(type);
|
|
51
|
+
const byId = new Map(variables.map(variable => [variable.getId(), variable]));
|
|
52
|
+
return options.map(option => {
|
|
53
|
+
const variable = byId.get(option[1]);
|
|
54
|
+
return variable ? [scopedLabel(variable, variables), option[1]] : option;
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
for (const [opcode, fieldName, type] of [
|
|
59
|
+
['data_variable', 'VARIABLE', ''],
|
|
60
|
+
['data_listcontents', 'LIST', blocks.LIST_VARIABLE_TYPE]
|
|
61
|
+
]) {
|
|
62
|
+
const reporter = blocks.Blocks[opcode];
|
|
63
|
+
const init = reporter.init;
|
|
64
|
+
reporter.init = function () {
|
|
65
|
+
init.call(this);
|
|
66
|
+
if (this.workspace !== workspace || this.isInFlyout) return;
|
|
67
|
+
this.customContextMenu = options => {
|
|
68
|
+
if (this.isCollapsed()) return;
|
|
69
|
+
const field = this.getField(fieldName);
|
|
70
|
+
const variables = workspace.getVariablesOfType(type);
|
|
71
|
+
for (const variable of variables.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
72
|
+
const id = variable.getId();
|
|
73
|
+
if (id !== field.getValue()) {
|
|
74
|
+
options.push({
|
|
75
|
+
text: scopedLabel(variable, variables),
|
|
76
|
+
twPlusMenuIcon: 'switch',
|
|
77
|
+
enabled: true,
|
|
78
|
+
callback: () => field.setValue(id)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|