@kubohiroya/turbowarp-plus-editor-code-views 0.6.0 → 0.7.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.
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Merging a variable or list into another one, and moving one between "this sprite only" and
3
+ * "for all sprites".
4
+ *
5
+ * Scratch refuses to rename a variable to a name that is already taken and has no way to change a
6
+ * variable's scope. Both are plans over the VM's data: every field that holds the variable's id,
7
+ * every "[name] of (sprite)" block that reads it by name, its monitor and the variable itself.
8
+ * A plan is checked before anything changes, applied as a list of reversible steps, and undone by
9
+ * running those steps backwards. Nothing here touches Blockly; the editor reloads the workspace
10
+ * from the VM afterwards.
11
+ */
12
+ export type VariableType = '' | 'list';
13
+ export interface VariableLike {
14
+ id: string;
15
+ name: string;
16
+ type: string;
17
+ value: unknown;
18
+ isCloud?: boolean;
19
+ }
20
+ export interface FieldLike {
21
+ name?: string;
22
+ id?: string | null;
23
+ value?: unknown;
24
+ variableType?: string;
25
+ }
26
+ export interface BlockLike {
27
+ id: string;
28
+ opcode: string;
29
+ fields: Record<string, FieldLike>;
30
+ inputs: Record<string, {
31
+ block?: string | null;
32
+ shadow?: string | null;
33
+ }>;
34
+ }
35
+ export interface BlocksLike {
36
+ _blocks: Record<string, BlockLike>;
37
+ getBlock?(id: string): BlockLike | undefined;
38
+ resetCache?(): void;
39
+ createBlock?(block: object): void;
40
+ deleteBlock?(id: string): void;
41
+ changeBlock?(args: object, runtime?: object): void;
42
+ }
43
+ export interface TargetLike {
44
+ id: string;
45
+ isStage: boolean;
46
+ isOriginal?: boolean;
47
+ sprite?: object;
48
+ variables: Record<string, VariableLike>;
49
+ blocks: BlocksLike;
50
+ getName(): string;
51
+ }
52
+ export interface RuntimeLike {
53
+ targets: TargetLike[];
54
+ getTargetForStage(): TargetLike;
55
+ monitorBlocks?: BlocksLike;
56
+ requestRemoveMonitor?(id: string): void;
57
+ emitProjectChanged?(): void;
58
+ }
59
+ export interface VmLike {
60
+ runtime: RuntimeLike;
61
+ editingTarget: TargetLike | null;
62
+ emitWorkspaceUpdate?(): void;
63
+ emitTargetsUpdate?(triggerProjectChange?: boolean): void;
64
+ }
65
+ /** Why a merge or a scope change cannot be made. Names are display names of targets. */
66
+ export type Refusal = {
67
+ code: 'same';
68
+ } | {
69
+ code: 'missing';
70
+ } | {
71
+ code: 'type';
72
+ } | {
73
+ code: 'cloud';
74
+ } | {
75
+ code: 'stage';
76
+ } | {
77
+ code: 'not-visible';
78
+ owner: string;
79
+ targets: string[];
80
+ } | {
81
+ code: 'used-elsewhere';
82
+ sprite: string;
83
+ targets: string[];
84
+ } | {
85
+ code: 'name-taken';
86
+ targets: string[];
87
+ };
88
+ /** Clones that kept separate values will share one, or the other way round. */
89
+ export type Warning = 'clones-share' | 'clones-split' | 'dynamic-sensing';
90
+ export interface VariableSummary {
91
+ id: string;
92
+ name: string;
93
+ type: VariableType;
94
+ value: unknown;
95
+ /** Display name of the owner, or null for a global variable. */
96
+ owner: string | null;
97
+ }
98
+ export interface Plan {
99
+ kind: 'merge' | 'global' | 'local';
100
+ source: VariableSummary;
101
+ /** The variable that remains after a merge; for a move, the moved variable itself. */
102
+ destination: VariableSummary;
103
+ /** Fields holding the source's id, counted by the target that owns them. */
104
+ references: {
105
+ target: string;
106
+ count: number;
107
+ }[];
108
+ /** "[name] of (sprite)" blocks that are rewritten. */
109
+ sensingReferences: number;
110
+ warnings: Warning[];
111
+ /** The sprite a "this sprite only" move goes to, or the sprite a local source lives in. */
112
+ sprite: string | null;
113
+ }
114
+ export type PlanResult = {
115
+ ok: true;
116
+ plan: Plan;
117
+ } | {
118
+ ok: false;
119
+ refusal: Refusal;
120
+ };
121
+ type Step = {
122
+ type: 'field';
123
+ field: FieldLike;
124
+ id: string | null | undefined;
125
+ value: unknown;
126
+ } | {
127
+ type: 'value';
128
+ field: FieldLike;
129
+ value: unknown;
130
+ } | {
131
+ type: 'remove';
132
+ owner: TargetLike;
133
+ variable: VariableLike;
134
+ } | {
135
+ type: 'add';
136
+ owner: TargetLike;
137
+ variable: VariableLike;
138
+ } | {
139
+ type: 'move';
140
+ from: TargetLike;
141
+ to: TargetLike;
142
+ variable: VariableLike;
143
+ } | {
144
+ type: 'monitor';
145
+ variable: VariableLike;
146
+ visible: boolean;
147
+ };
148
+ export interface UndoRecord {
149
+ plan: Plan;
150
+ steps: Step[];
151
+ }
152
+ /**
153
+ * The target whose variables hold an id.
154
+ * @param {VmLike} vm The VM.
155
+ * @param {string} id The variable id.
156
+ * @returns {{variable: VariableLike, owner: TargetLike} | null} The variable and its owner.
157
+ */
158
+ export declare const findVariable: (vm: VmLike, id: string) => {
159
+ variable: VariableLike;
160
+ owner: TargetLike;
161
+ };
162
+ /**
163
+ * Check merging one variable or list into another.
164
+ * @param {VmLike} vm The VM.
165
+ * @param {string} sourceId The variable that goes away.
166
+ * @param {string} destinationId The variable that remains.
167
+ * @returns {PlanResult} The plan, or why it cannot be made.
168
+ */
169
+ export declare const planMerge: (vm: VmLike, sourceId: string, destinationId: string) => PlanResult;
170
+ /**
171
+ * Check moving a variable or list to "for all sprites" or to "this sprite only".
172
+ * Moving a sprite's variable to all sprites when the stage already has one of the same name is a
173
+ * merge into that one.
174
+ * @param {VmLike} vm The VM.
175
+ * @param {string} id The variable.
176
+ * @param {'global' | 'local'} scope Where it goes.
177
+ * @param {TargetLike} sprite The sprite a "this sprite only" variable belongs to; defaults to the editing target.
178
+ * @returns {PlanResult} The plan, or why it cannot be made.
179
+ */
180
+ export declare const planScopeChange: (vm: VmLike, id: string, scope: "global" | "local", sprite?: TargetLike | null) => PlanResult;
181
+ /**
182
+ * Apply a plan made from the VM's current data.
183
+ * @param {VmLike} vm The VM.
184
+ * @param {Plan} plan A plan from planMerge or planScopeChange.
185
+ * @returns {UndoRecord} What undoes it.
186
+ */
187
+ export declare const applyPlan: (vm: VmLike, plan: Plan) => UndoRecord;
188
+ /**
189
+ * Undo an applied plan by running its steps backwards.
190
+ * @param {VmLike} vm The VM.
191
+ * @param {UndoRecord} record What applyPlan returned.
192
+ */
193
+ export declare const undoPlan: (vm: VmLike, record: UndoRecord) => void;
194
+ /**
195
+ * Show the VM's new state in the editor: the workspace, its palette and the target list.
196
+ * @param {VmLike} vm The VM.
197
+ */
198
+ export declare const refreshEditor: (vm: VmLike) => void;
199
+ export {};
@@ -0,0 +1,392 @@
1
+ /**
2
+ * Merging a variable or list into another one, and moving one between "this sprite only" and
3
+ * "for all sprites".
4
+ *
5
+ * Scratch refuses to rename a variable to a name that is already taken and has no way to change a
6
+ * variable's scope. Both are plans over the VM's data: every field that holds the variable's id,
7
+ * every "[name] of (sprite)" block that reads it by name, its monitor and the variable itself.
8
+ * A plan is checked before anything changes, applied as a list of reversible steps, and undone by
9
+ * running those steps backwards. Nothing here touches Blockly; the editor reloads the workspace
10
+ * from the VM afterwards.
11
+ */
12
+ const STAGE_KEY = '_stage_';
13
+ const originals = (vm) => vm.runtime.targets.filter(target => target.isOriginal !== false);
14
+ /**
15
+ * The target whose variables hold an id.
16
+ * @param {VmLike} vm The VM.
17
+ * @param {string} id The variable id.
18
+ * @returns {{variable: VariableLike, owner: TargetLike} | null} The variable and its owner.
19
+ */
20
+ export const findVariable = (vm, id) => {
21
+ const stage = vm.runtime.getTargetForStage();
22
+ if (stage && Object.hasOwn(stage.variables, id))
23
+ return { variable: stage.variables[id], owner: stage };
24
+ for (const target of originals(vm)) {
25
+ if (Object.hasOwn(target.variables, id))
26
+ return { variable: target.variables[id], owner: target };
27
+ }
28
+ return null;
29
+ };
30
+ const ownerKey = (owner) => owner.isStage ? STAGE_KEY : owner.getName();
31
+ const summary = (variable, owner) => ({
32
+ id: variable.id,
33
+ name: variable.name,
34
+ type: variable.type === 'list' ? 'list' : '',
35
+ value: variable.value,
36
+ owner: owner.isStage ? null : owner.getName()
37
+ });
38
+ /** Each distinct blocks container once, with the original target that owns it. */
39
+ const blockContainers = (vm) => {
40
+ const seen = new Set();
41
+ const containers = [];
42
+ for (const target of originals(vm)) {
43
+ if (!target.blocks || seen.has(target.blocks))
44
+ continue;
45
+ seen.add(target.blocks);
46
+ containers.push({ target, blocks: target.blocks });
47
+ }
48
+ return containers;
49
+ };
50
+ /** Every field, anywhere in the project's code, that holds a variable's id. */
51
+ const fieldReferences = (vm, id) => {
52
+ const found = [];
53
+ for (const { target, blocks } of blockContainers(vm)) {
54
+ for (const block of Object.values(blocks._blocks)) {
55
+ for (const field of Object.values(block.fields ?? {})) {
56
+ if (field && field.id === id)
57
+ found.push({ target, field });
58
+ }
59
+ }
60
+ }
61
+ return found;
62
+ };
63
+ /**
64
+ * "[name] of (owner)" blocks that read a scalar variable by name. A block whose sprite menu has a
65
+ * reporter dropped in is dynamic: which sprite it reads is known only while the project runs.
66
+ */
67
+ const sensingReferences = (vm, variable, owner) => {
68
+ const fixed = [];
69
+ let dynamic = 0;
70
+ if (variable.type !== '')
71
+ return { fixed, dynamic };
72
+ const key = ownerKey(owner);
73
+ for (const { target, blocks } of blockContainers(vm)) {
74
+ for (const block of Object.values(blocks._blocks)) {
75
+ if (block.opcode !== 'sensing_of' || block.fields?.PROPERTY?.value !== variable.name)
76
+ continue;
77
+ const input = block.inputs?.OBJECT;
78
+ if (!input)
79
+ continue;
80
+ if (input.block !== input.shadow) {
81
+ dynamic++;
82
+ continue;
83
+ }
84
+ const menu = input.block ? blocks._blocks[input.block] : undefined;
85
+ const object = menu?.fields?.OBJECT;
86
+ if (object && object.value === key)
87
+ fixed.push({ target, property: block.fields.PROPERTY, object });
88
+ }
89
+ }
90
+ return { fixed, dynamic };
91
+ };
92
+ const countByTarget = (references) => {
93
+ const counts = new Map();
94
+ for (const { target } of references)
95
+ counts.set(target, (counts.get(target) ?? 0) + 1);
96
+ return [...counts].map(([target, count]) => ({ target: target.getName(), count }));
97
+ };
98
+ /** Whether a sprite's values are split across clones, now or once its code runs. */
99
+ const usesClones = (vm, sprite) => {
100
+ if (vm.runtime.targets.some(target => target.isOriginal === false && target.sprite && target.sprite === sprite.sprite)) {
101
+ return true;
102
+ }
103
+ for (const { target, blocks } of blockContainers(vm)) {
104
+ for (const block of Object.values(blocks._blocks)) {
105
+ if (block.opcode !== 'control_create_clone_of_menu')
106
+ continue;
107
+ const option = block.fields?.CLONE_OPTION?.value;
108
+ if (option === sprite.getName() || (option === '_myself_' && target === sprite))
109
+ return true;
110
+ }
111
+ }
112
+ return false;
113
+ };
114
+ const unique = (names) => [...new Set(names)];
115
+ /**
116
+ * Check merging one variable or list into another.
117
+ * @param {VmLike} vm The VM.
118
+ * @param {string} sourceId The variable that goes away.
119
+ * @param {string} destinationId The variable that remains.
120
+ * @returns {PlanResult} The plan, or why it cannot be made.
121
+ */
122
+ export const planMerge = (vm, sourceId, destinationId) => {
123
+ if (sourceId === destinationId)
124
+ return { ok: false, refusal: { code: 'same' } };
125
+ const source = findVariable(vm, sourceId);
126
+ const destination = findVariable(vm, destinationId);
127
+ if (!source || !destination)
128
+ return { ok: false, refusal: { code: 'missing' } };
129
+ const sourceType = source.variable.type;
130
+ if ((sourceType !== '' && sourceType !== 'list') || sourceType !== destination.variable.type) {
131
+ return { ok: false, refusal: { code: 'type' } };
132
+ }
133
+ if (source.variable.isCloud || destination.variable.isCloud)
134
+ return { ok: false, refusal: { code: 'cloud' } };
135
+ const fields = fieldReferences(vm, sourceId);
136
+ if (!destination.owner.isStage) {
137
+ const outside = fields.filter(({ target }) => target !== destination.owner).map(({ target }) => target.getName());
138
+ if (outside.length) {
139
+ return { ok: false, refusal: { code: 'not-visible', owner: destination.owner.getName(), targets: unique(outside) } };
140
+ }
141
+ }
142
+ const sensing = sensingReferences(vm, source.variable, source.owner);
143
+ const warnings = [];
144
+ if (sensing.dynamic)
145
+ warnings.push('dynamic-sensing');
146
+ // A local value per clone becomes one shared value, or the other way round.
147
+ const localSide = !source.owner.isStage ? source.owner : !destination.owner.isStage ? destination.owner : null;
148
+ if (localSide && source.owner.isStage !== destination.owner.isStage && usesClones(vm, localSide)) {
149
+ warnings.push(destination.owner.isStage ? 'clones-share' : 'clones-split');
150
+ }
151
+ return {
152
+ ok: true,
153
+ plan: {
154
+ kind: 'merge',
155
+ source: summary(source.variable, source.owner),
156
+ destination: summary(destination.variable, destination.owner),
157
+ references: countByTarget(fields),
158
+ sensingReferences: sensing.fixed.length,
159
+ warnings,
160
+ sprite: source.owner.isStage ? null : source.owner.getName()
161
+ }
162
+ };
163
+ };
164
+ /**
165
+ * Check moving a variable or list to "for all sprites" or to "this sprite only".
166
+ * Moving a sprite's variable to all sprites when the stage already has one of the same name is a
167
+ * merge into that one.
168
+ * @param {VmLike} vm The VM.
169
+ * @param {string} id The variable.
170
+ * @param {'global' | 'local'} scope Where it goes.
171
+ * @param {TargetLike} sprite The sprite a "this sprite only" variable belongs to; defaults to the editing target.
172
+ * @returns {PlanResult} The plan, or why it cannot be made.
173
+ */
174
+ export const planScopeChange = (vm, id, scope, sprite = vm.editingTarget) => {
175
+ const found = findVariable(vm, id);
176
+ if (!found)
177
+ return { ok: false, refusal: { code: 'missing' } };
178
+ const { variable, owner } = found;
179
+ if (variable.type !== '' && variable.type !== 'list')
180
+ return { ok: false, refusal: { code: 'type' } };
181
+ if (variable.isCloud)
182
+ return { ok: false, refusal: { code: 'cloud' } };
183
+ const stage = vm.runtime.getTargetForStage();
184
+ const sameName = (target) => Object.values(target.variables)
185
+ .find(other => other.id !== id && other.name === variable.name && other.type === variable.type);
186
+ const fields = fieldReferences(vm, id);
187
+ const sensing = sensingReferences(vm, variable, owner);
188
+ const warnings = [];
189
+ if (sensing.dynamic)
190
+ warnings.push('dynamic-sensing');
191
+ if (scope === 'global') {
192
+ if (owner.isStage)
193
+ return { ok: false, refusal: { code: 'same' } };
194
+ const existing = sameName(stage);
195
+ if (existing)
196
+ return planMerge(vm, id, existing.id);
197
+ const taken = originals(vm).filter(target => !target.isStage && target !== owner && sameName(target));
198
+ if (taken.length)
199
+ return { ok: false, refusal: { code: 'name-taken', targets: taken.map(target => target.getName()) } };
200
+ if (usesClones(vm, owner))
201
+ warnings.push('clones-share');
202
+ return {
203
+ ok: true,
204
+ plan: {
205
+ kind: 'global',
206
+ source: summary(variable, owner),
207
+ destination: summary(variable, owner),
208
+ references: countByTarget(fields),
209
+ sensingReferences: sensing.fixed.length,
210
+ warnings,
211
+ sprite: owner.getName()
212
+ }
213
+ };
214
+ }
215
+ if (!sprite || sprite.isStage)
216
+ return { ok: false, refusal: { code: 'stage' } };
217
+ if (!owner.isStage)
218
+ return { ok: false, refusal: { code: 'same' } };
219
+ if (sameName(sprite))
220
+ return { ok: false, refusal: { code: 'name-taken', targets: [sprite.getName()] } };
221
+ // "[name] of (Stage)" reads it by name; a sprite's own menu cannot name the sprite itself, so
222
+ // any such block, in this sprite or elsewhere, would stop finding it.
223
+ const outside = [
224
+ ...fields.filter(({ target }) => target !== sprite),
225
+ ...sensing.fixed
226
+ ].map(({ target }) => target.getName());
227
+ if (outside.length) {
228
+ return { ok: false, refusal: { code: 'used-elsewhere', sprite: sprite.getName(), targets: unique(outside) } };
229
+ }
230
+ if (usesClones(vm, sprite))
231
+ warnings.push('clones-split');
232
+ return {
233
+ ok: true,
234
+ plan: {
235
+ kind: 'local',
236
+ source: summary(variable, owner),
237
+ destination: summary(variable, owner),
238
+ references: countByTarget(fields),
239
+ sensingReferences: 0,
240
+ warnings,
241
+ sprite: sprite.getName()
242
+ }
243
+ };
244
+ };
245
+ /** Show or hide a variable's monitor through the same path as the palette's checkbox. */
246
+ const setMonitor = (vm, variable, visible) => {
247
+ const monitors = vm.runtime.monitorBlocks;
248
+ if (!monitors)
249
+ return;
250
+ if (!visible) {
251
+ if (monitors.getBlock?.(variable.id)) {
252
+ vm.runtime.requestRemoveMonitor?.(variable.id);
253
+ monitors.deleteBlock?.(variable.id);
254
+ }
255
+ return;
256
+ }
257
+ if (!monitors.getBlock?.(variable.id)) {
258
+ const list = variable.type === 'list';
259
+ const field = list ? 'LIST' : 'VARIABLE';
260
+ monitors.createBlock?.({
261
+ id: variable.id,
262
+ opcode: list ? 'data_listcontents' : 'data_variable',
263
+ inputs: {},
264
+ fields: { [field]: { name: field, id: variable.id, value: variable.name, variableType: variable.type } },
265
+ next: null,
266
+ topLevel: true,
267
+ parent: null,
268
+ shadow: false,
269
+ x: 0,
270
+ y: 0
271
+ });
272
+ }
273
+ monitors.changeBlock?.({ id: variable.id, element: 'checkbox', value: true }, vm.runtime);
274
+ };
275
+ const monitorVisible = (vm, id) => Boolean(vm.runtime.monitorBlocks?.getBlock?.(id)?.isMonitored);
276
+ const run = (vm, step) => {
277
+ switch (step.type) {
278
+ case 'field':
279
+ case 'value':
280
+ break;
281
+ case 'remove':
282
+ delete step.owner.variables[step.variable.id];
283
+ break;
284
+ case 'add':
285
+ step.owner.variables[step.variable.id] = step.variable;
286
+ break;
287
+ case 'move':
288
+ delete step.from.variables[step.variable.id];
289
+ step.to.variables[step.variable.id] = step.variable;
290
+ break;
291
+ case 'monitor':
292
+ setMonitor(vm, step.variable, step.visible);
293
+ break;
294
+ }
295
+ };
296
+ /**
297
+ * Apply a plan made from the VM's current data.
298
+ * @param {VmLike} vm The VM.
299
+ * @param {Plan} plan A plan from planMerge or planScopeChange.
300
+ * @returns {UndoRecord} What undoes it.
301
+ */
302
+ export const applyPlan = (vm, plan) => {
303
+ const steps = [];
304
+ const source = findVariable(vm, plan.source.id);
305
+ const destination = findVariable(vm, plan.destination.id);
306
+ if (!source || !destination)
307
+ throw new Error('The variable is gone.');
308
+ const setField = (field, id, value) => {
309
+ steps.push({ type: 'field', field, id: field.id, value: field.value });
310
+ field.id = id;
311
+ field.value = value;
312
+ };
313
+ const setValue = (field, value) => {
314
+ steps.push({ type: 'value', field, value: field.value });
315
+ field.value = value;
316
+ };
317
+ const doStep = (step, inverse) => {
318
+ run(vm, step);
319
+ steps.push(inverse);
320
+ };
321
+ const sensing = sensingReferences(vm, source.variable, source.owner).fixed;
322
+ if (plan.kind === 'merge') {
323
+ const { variable, owner } = destination;
324
+ for (const { field } of fieldReferences(vm, source.variable.id))
325
+ setField(field, variable.id, variable.name);
326
+ for (const { property, object } of sensing) {
327
+ setValue(property, variable.name);
328
+ setValue(object, ownerKey(owner));
329
+ }
330
+ const showDestination = monitorVisible(vm, source.variable.id) && !monitorVisible(vm, variable.id);
331
+ if (vm.runtime.monitorBlocks?.getBlock?.(source.variable.id)) {
332
+ doStep({ type: 'monitor', variable: source.variable, visible: false }, { type: 'monitor', variable: source.variable, visible: monitorVisible(vm, source.variable.id) });
333
+ }
334
+ doStep({ type: 'remove', owner: source.owner, variable: source.variable }, { type: 'add', owner: source.owner, variable: source.variable });
335
+ if (showDestination) {
336
+ doStep({ type: 'monitor', variable, visible: true }, { type: 'monitor', variable, visible: false });
337
+ }
338
+ }
339
+ else {
340
+ const stage = vm.runtime.getTargetForStage();
341
+ const to = plan.kind === 'global' ? stage :
342
+ originals(vm).find(target => !target.isStage && target.getName() === plan.sprite);
343
+ if (!to)
344
+ throw new Error('The sprite is gone.');
345
+ for (const { object } of sensing)
346
+ setValue(object, ownerKey(to));
347
+ // A monitor remembers whether it belongs to a sprite, so it is made again for the new owner.
348
+ const visible = monitorVisible(vm, source.variable.id);
349
+ if (vm.runtime.monitorBlocks?.getBlock?.(source.variable.id)) {
350
+ doStep({ type: 'monitor', variable: source.variable, visible: false }, { type: 'monitor', variable: source.variable, visible });
351
+ }
352
+ doStep({ type: 'move', from: source.owner, to, variable: source.variable }, { type: 'move', from: to, to: source.owner, variable: source.variable });
353
+ if (visible) {
354
+ doStep({ type: 'monitor', variable: source.variable, visible: true }, { type: 'monitor', variable: source.variable, visible: false });
355
+ }
356
+ }
357
+ resetCaches(vm);
358
+ return { plan, steps };
359
+ };
360
+ /**
361
+ * Undo an applied plan by running its steps backwards.
362
+ * @param {VmLike} vm The VM.
363
+ * @param {UndoRecord} record What applyPlan returned.
364
+ */
365
+ export const undoPlan = (vm, record) => {
366
+ for (const step of [...record.steps].reverse()) {
367
+ if (step.type === 'field') {
368
+ step.field.id = step.id;
369
+ step.field.value = step.value;
370
+ }
371
+ else if (step.type === 'value') {
372
+ step.field.value = step.value;
373
+ }
374
+ else {
375
+ run(vm, step);
376
+ }
377
+ }
378
+ resetCaches(vm);
379
+ };
380
+ const resetCaches = (vm) => {
381
+ for (const { blocks } of blockContainers(vm))
382
+ blocks.resetCache?.();
383
+ vm.runtime.emitProjectChanged?.();
384
+ };
385
+ /**
386
+ * Show the VM's new state in the editor: the workspace, its palette and the target list.
387
+ * @param {VmLike} vm The VM.
388
+ */
389
+ export const refreshEditor = (vm) => {
390
+ vm.emitWorkspaceUpdate?.();
391
+ vm.emitTargetsUpdate?.(false);
392
+ };